Java (not to be confused with JavaScript) is a class-based, object-oriented, strongly typed, reflective language and run-time environment (JRE). Java programs are compiled to byte-code and run in a virtual machine (JVM) enabling a "write once, run anywhere" (WORA) methodology.

learn more… | top users | synonyms (2)

0
votes
0answers
9 views

Naming of methods that perform some actions under some condition [migrated]

I often write such methods to avoid duplication in code and I give them name such as doSomethingIfSomeCondition(). For example: ...
0
votes
1answer
17 views

Follow-up: Find number of times that difference of array values are equals to a number

This question is follow-up to this question. Sample Calculation ...
0
votes
1answer
15 views

Follow-up: Find sum of number of times that each character of source occurs in the target

This question is a follow-up of this question. The aim of the questions is to find sum of number of times that each character of source occurs in the target. In the new code, I've renamed the char ...
3
votes
2answers
71 views

Building a simple tree structure

I'm trying to build this simple tree: ...
6
votes
1answer
30 views

Shady Characters

As part of my familiarization with the features of Java 8, and inspired by this question, I thought I would take the 'Shady Character' problem to 'the next level'. Find sum of number of times that ...
3
votes
2answers
72 views

Find sum of number of times that each character of source occurs in the target

I wrote the following code in response to this question "find sum of number of times that each character of source occurs in the target", is there any better solution for it? Analysis ...
3
votes
4answers
125 views

Find the number of times that the difference of array values are equal to the number

I wrote the following code to answer this, but I am wondering if there is any better approach. For example If the following array is given: {10,21,34,45,56} ...
1
vote
1answer
30 views

HeapSort Efficiency

For heap (array based) sort, we need to start at index 1, ignoring the 0th index. If I want to make a static function like ...
5
votes
3answers
267 views

Time to Next Departure

I am trying to find out how many minutes that are remaining until the next train will departure, based on the current system time in Java. I am so far not familiar with the many aspects of Java, but ...
3
votes
1answer
24 views

Unit testing a servlet in a meaningful way

I have to write a unit test for the method processRequest in the servlet below and I'm wondering if: It just shouldn't be done. The class should be rewritten / ...
16
votes
2answers
1k views

Android Flashlight app

This is my first project, a Flashlight application for Android-based devices: ...
0
votes
0answers
4 views

Future proofing fluent-method-chained-DSL test code [migrated]

The current design is a pair of thin fluent-method-chained-DSLs that mix the "traditional" and "enhanced" builder patterns. That's just a fancy way to say some chained methods are optional and not ...
2
votes
2answers
109 views

Is SList class an ADT?

I call the SList class an Abstract Data Type because it satisfies following 6 invariants: Multiple users of SList class should ...
3
votes
0answers
85 views

To subclass or to wrap for “default” implementation? [migrated]

I'm creating a toolset in Java consisting of many Natural Language Processing (NLP) tools, such as Tokenizer, POS tagger, Lemmatizer, Sentence parsing, etc. I want to put all good and publicly ...
5
votes
2answers
255 views

Parallel “wget” in Java

Purpose: write Java program that downloads a list of URLs specified on commandline in parallel (simultaneously), reporting download completion every second. My solution follows below, please point ...
2
votes
7answers
106 views

Optimization of a String maneuvering oriented program

I've got an interview coming up for which the following is a prospective question: Given 2 strings, for instance: John Lennon Paul ON delete every character from string 1 which ...
0
votes
0answers
25 views

How to get values to output as a currency? [on hold]

I am working on calculating change, and investment rates with java. My code gives me the correct values, but does not display them how I'd like. For the first part, when I calculate the dollar amount ...
9
votes
5answers
287 views

Modeling a Triangle, with a utility method to classify it

Inspired by this question, I played a bit with the idea of modeling a Triangle, and a utility method to classify it: ...
0
votes
0answers
27 views

Values are null [on hold]

I am working on a contact list. I've just about got it working, except for two problems. The output value for the user input prints as null and the Email Address output line contains the null values ...
3
votes
2answers
107 views

Calculating sum of manhattan distances in a sliding puzzle

I would like some feed back on a method which calculates the sum of Manhattan distances for each tile in a sliding puzzle to its goal position in the goal puzzle. Here is the code: ...
5
votes
3answers
335 views

Triangle Type Program

Is there any way to simplify it further? ...
-1
votes
0answers
55 views

JavaSE client: is this how to get a new JPA EntityManager each time? (DAO) [on hold]

This class functions, in that the program can be left open for hours and it will still reconnect to the database when the user prompts for a CRUD operation. I've read about DAO, and some other ...
1
vote
1answer
34 views

Group by two lists in one map using lambda

I've got two collections: collection of rules, and collection of keys that can handle specific rules. Key have method ...
3
votes
3answers
130 views

Merge Sort - Efficiency

I've written this Java code to implement Merge Sort. ...
4
votes
2answers
53 views

Efficiency and design of Dijkstra's algorithm modified for connected nodes

I've written an AI (well... it's not really that intelligent) that plays the board game Ticket to Ride. In that game, cities are essentially nodes of a graph, linked together by train tracks (the ...
-4
votes
0answers
35 views

Where is the possible memory leak? [on hold]

Where is the possible memory leak in my code? There is also supposed to be a programming error too in one the methods as well, that might cause problems if I create a subclass of this class. ...
0
votes
1answer
34 views

Speeding up Mersenne prime generator

I am writing a program to calculate Mersenne primes. This code works, but it is so slow: ...
3
votes
2answers
46 views

Calculating the ideal body weight

The following question was taken from Absolute Java 5th ed. by Walter Savitch: A simple rule to estimate your ideal body weight is to allow 110 pounds for the first 5 feet of height and 5 pounds ...
8
votes
3answers
130 views

Compare values of elements in Stream

I'm having fun with Java's Stream library and lambdas. The following code looks for persons within a list that have the same ID (which might indicate that something's wrong with the data) and prints ...
4
votes
1answer
244 views

Queue Implementation using a Linked List

For understanding the concepts, I've implemented the Queue data structures using a linked list. Is there anything to improve? LinkList.java ...
-1
votes
0answers
27 views

Class to manage the states of the game [on hold]

I'm developing a simple java game and i have written a class to manage the states of this game. Every level is a state, same for game over and the main menu. I get a strange behavior in this ...
2
votes
1answer
45 views

Refactoring the Iffy Tractor task

There is a test of OO knowledge called Iffy Tractor. The task is to refactor the code and make it as much flexible as possible for the future modifications. I have placed the code here. It was taken ...
3
votes
2answers
96 views

Converting seconds to hours, minutes and seconds

The following question was taken from Absolute Java 5th ed. by Walter Savitch: Write a program that outputs the number of hours, minutes, and seconds that corresponds to 50,391 total seconds. The ...
6
votes
3answers
638 views

Stack implementation using a linked list

To understand the concept, I implemented the stack operations using a linked list. Please review the code and tell me your suggestions. Node.java ...
6
votes
3answers
116 views

Memory text based game

Would anyone be so kind as to review my code for Memory? ...
2
votes
1answer
56 views

Encoding and decoding exercise

I was issued the following coding challenge from a company to write an encoding and decoding function: Encoding: This function needs to accept a signed integer in the 14-bit range [-8192..+8191] ...
1
vote
0answers
21 views

Validate XML using XSD, a Catalog Resolver, and JAXP DOM for XSLT

Background As this related question describes, there does not appear to be a canonical way to validate XML files against an XSD then subsequently transform them using an XSL template with file paths ...
6
votes
1answer
96 views

Pokemon Type Evaluator part 2

I started anew and completely refactored the way I implemented Pokemon Type Evaluator. Also, first use of a lambda expression (Case of using it, but still don't fully grasp how it's working). I'm ...
4
votes
2answers
143 views

Performance of hashmap-based session object

Unfortunately, I can't use the Tomcat session for storing the key/value pairs for each user (restricted because it's an IVR domain-based project). But I need the same functionality like a ...
-1
votes
0answers
31 views

Singly linked list implementation and related questions [closed]

I started brushing up Data Structures and Algorithms several days ago in preparation for upcoming interviews in a few months. I began with linked lists and discovered I'm a bit rusty. With clause ...
3
votes
1answer
50 views

Calculating the speed of a bicycle given the gear size and cadence

The following question was taken from Absolute Java 5th ed. by Walter Savitch: Bicyclists can calculate their speed if the gear size and cadence is known. Gear size refers to the effective ...
3
votes
1answer
27 views

Input on where and how I can make improvements on my randomizer

As my title states I'm just looking for a little input on how I can improve one of my side projects when I'm not doing my CS assignments. All my program is, is a primitive randomizer for Battlefield 4 ...
0
votes
0answers
38 views

Best practice to avoid if else statement in complex conditions [closed]

I'm looking into refactoring part of some legacy code. ...
4
votes
1answer
34 views

Optimization of Barnes-Hut Multithread Insertion algorithm

I'm currently working on optimizing a Barnes-Hut implementation (connected to a previous post I did) and I need help to optimize it further. After some testing, the main problem appears to be in the ...
1
vote
3answers
210 views

Find the Max Width Of Tree

1 / \ 2 3 / \ \ 4 5 8 / \ 6 7 Width of a tree is maximum of widths of all levels. For the above tree, width ...
2
votes
1answer
29 views

Time complexity of 0/1 Knapsack challenge

The code gives correct output. How do I calculate time complexity for code like this? The program finds all the combinations of items and sees if the combination gives the max profit. If the last ...
5
votes
1answer
82 views

Improving an IRC bot

I've recently started working on a java project, and the main purpose of it is to get better at Java. I've decided to make an IRC bot for twitch. But after some hours of progress I already see my Bot ...
2
votes
1answer
40 views

Changing the first occurrence of a text in a sentence

The following question was taken from Absolute Java 5th ed. by Walter Savitch: Write a program that starts with a line of text and then outputs that line of text with the first occurrence of ...
11
votes
4answers
543 views

Split camel cased/snake cased String

I want to implement a method which, given some camelcased or underscored String, will return a list of separate words that make up this ...