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 (1)

4
votes
1answer
20 views

How to efficiently parse HTML table using jsoup?

I am trying to parse HTML using jsoup. This is my first time working with jsoup and I read some tutorial on it as well. Below is my HTML table, which I am trying to parse. If you see my table, it has ...
3
votes
1answer
24 views

Accessing a String value from multiple threads without synchronization

I'm looking for some input here. I have a class that contains a value which is updated every few seconds by a method within that class. Right now, access to this value across multiple threads is ...
0
votes
0answers
9 views

Base “DAL” for different POJO classes

I have Employee "DAO" class which have basic methods to manipulate Employee objects based on Employee POJO class: get, getAll, remove, update, search. I want to do a base "DAO" class with the same ...
0
votes
0answers
17 views

Find POJO by one field in List [on hold]

I often find myself having to write helper functions like these ...
-2
votes
0answers
28 views

understand operator precedence [migrated]

Was fixing bug in our code and found this weird function that was misbehaving: ...
0
votes
1answer
38 views

Null checking in nested getter calls [on hold]

I have the following piece of code and I would like to see what different approaches would be to solve that in a more elegant way. The thing is that I don't know whether is better to have the null ...
1
vote
1answer
30 views

Extend or Encapsulate [on hold]

I couldn't find proper tips anywhere, since searching for these general terms isn't very efficient. I deal with this almost everyday, creating Java SWT widgets in particular. Each time I create a ...
5
votes
0answers
38 views

Separating Logic from GUI

I am new to Java's Swing and built a test client that connects to a server. I was wondering if my use of a Controller class as a link between the classes ...
3
votes
0answers
34 views

Is this a valid implementation of the MVP pattern?

Since fxml controllers compromises pure MVP, I tried to implement the pattern in this way: Main presenter class: ...
0
votes
0answers
18 views

Return the next right node

Given a binary tree, return the next right node. This question is attributed to GeeksForGeeks. For example, consider the following Binary Tree. Output for 2 is 6, output for 4 is 5. Output for 10, 6 ...
0
votes
0answers
17 views

Add two numbers represented by linkedlist

Given two numbers represented by two linked lists, write a function that returns sum list. The sum list is linked list representation of addition of two input numbers. It is not allowed to modify the ...
4
votes
0answers
40 views

Simple Calculator - revised

This is my revised code of the Calculator: ...
2
votes
0answers
27 views

Inefficient Stopwatch - revised

This is my revised code of Stopwatch: ...
1
vote
1answer
31 views

Improving performance in generating an Excel file

I am using this code to write more than 170,000 rows to an Excel document. All in all, the file generation process takes about 3 minutes total. (I've already shaved off about ten minutes by shaving ...
4
votes
1answer
21 views

Synchronized LinkedHashed map

I've written the following code ages ago (10+ years) which is part of a simple chat server. I'm going to refactor it a bit in java and then for fun I'm going to convert it to Scala and use Akka actors ...
6
votes
3answers
705 views

Rock, Paper, Scissors Game in Java

I made a Rock, Paper, Scissors game and would like the code to be reviewed. Main class: ...
1
vote
1answer
63 views

Get the levels of a binary tree

Given a binary tree, return a list of each level. I'm looking for a general review and a mention on best-practices, optimization, and verification of my complexities. Time complexity: \$O(n)\$ ...
7
votes
2answers
96 views

Finding the longest Collatz sequence cycle

I wrote a program to calculate Collatz sequences for initial numbers between 1 and a given integer i, then find the one with the largest cycle length. My code is ...
4
votes
1answer
99 views

Inefficient Stopwatch

I have just finished a simple GUI stopwatch, but some of its code looks like it needs replacing. This is the code: Clock class (extends Thread): ...
11
votes
3answers
443 views

Calculating the circumference and area of a circle

This simple program uses Scanner to obtain a radius from the user, then calculates and outputs the circumference and area. Questions: Is it customary in Java to ...
3
votes
2answers
168 views

Locate user of an Android device

I am new to oriented object paradigm and I work on Android using Java project for an internship. I must be able to locate the user and some around buildings I read stuff about how to setup ...
4
votes
1answer
56 views

Generic predicate in Java 8

Use Case Creating a generic and reusable predicate with closures that supports Float, Double, Integer, float, double, and integer. Problem Extending "Number" doesn't allow for the modulo operator. ...
0
votes
0answers
30 views

Nested maps vs. combined keys [migrated]

in the project I am currently working on we had three different types of prices depending on the age of the user (adult, child, etc...). So we had on the DB a table looking like this: ...
3
votes
1answer
62 views

Method to close a lot of closeable objects

I wrote a method that closes 3 closeable types: java.sql.Connection java.sql.PreparedStatement ...
5
votes
3answers
726 views

Class for catching error and logging

I often write something like this in my code: ...
10
votes
4answers
2k views

DRY attack and defense

I have these two methods on a class that differ only in one method call. Obviously, this is very un-DRY, especially as both use the same formula. Could anyone give me advice on how to tidy this up? ...
3
votes
2answers
116 views

Eliminating duplicated code blocks

I have an abstract PersonDao class, extended by several other DAO classes, for example EmployeeDao, ...
2
votes
2answers
139 views

Calculating multiple car prices from a file - follow-up

My application needs to read a file, which includes a list of cars from different factories, and calculate the prices (by this I mean mean add up their prices). I suppose my solution is efficient. ...
0
votes
0answers
21 views

Need help to create a method in DAO [on hold]

I need a help to create a method that takes the AAL Customer ID and returns a big decimal which is customer tlrd ref sys id.returning something real put some system.out.println to make sure you are ...
2
votes
1answer
24 views

Calculating multiple car prices from a file

My application needs to read a file, which includes a list of cars from different factories, and calculate the prices (by this I mean mean add up their prices). I suppose my solution is efficient. ...
-2
votes
0answers
23 views

Encryption in Java and Decryption using in C# using AES [on hold]

I have got two different systems to integrate where the Encrypted strings would be created on using Java platform. However, the encrypted strings need to be decrypted using C#. I have the Java ...
11
votes
4answers
111 views

Tic Tac Toe game in Java OOP

I have written a simple GUI Tic Tac Toe Application and since this is my first shot, I think it can be improved a lot. Please tell me what you think about it and what you see I made wrong so I can ...
8
votes
2answers
551 views

Simple calculator that seems inefficient

I have a simple calculator program that needs some reviewing. Is this as efficient as it can get, or is there a better way? ...
1
vote
0answers
16 views

Calculator Program [duplicate]

I have a simple calculator program that needs some reviewing. Is this as efficient as it can get, or is there a better way? ...
7
votes
2answers
71 views

EditController and ModelConverter - Does this make my ass look fat?

Description I am using a combination of the following two classes to achieve a quite simple task. I have Users in my application. These Users can be assigned Roles. And these Roles need to be ...
8
votes
3answers
627 views

More elegant way to increment Integers in Map?

I have a HashMap<Token, Integer>, which counts occurrences of Token. Each time Token ...
0
votes
0answers
22 views

AES-128 CBC decryption [on hold]

I have written this code in java in order to decrypt a ciphertext. I have the key. Everything seems correct to me but I have the problem that I'm gonna explain. Here is my code: ...
2
votes
0answers
36 views

Safely network reconnection (netty based)

NettyConnectionManager.scala: ...
3
votes
0answers
21 views

Robust organization data class (partial followup)

This question is a partial followup from my previous question, however the requirements have changed: I now need to be able to store multiple data entries for some fields. I also have added two hooks ...
4
votes
0answers
24 views

Dashboard for running programs in JavaFX 8

I have decided to create a dashboard view of a number of running processes/programs/applications, because it became tedious to monitor a bunch of applications, which I had to boot up manually. Please ...
6
votes
1answer
93 views

Finding common strings among 2 arrays of strings of length 1, sorted alphabetically in O(n) time complexity

The problem: Start with two arrays of strings, a and b, each in alphabetical order, possibly with duplicates. Return the count of the number of strings which appear in both arrays. ...
3
votes
2answers
94 views

Parsing arithmetic expressions like (x + y * a + b *z)

I have this code which I wrote to parse arithmetic expressions. However, many people say there are problems with it but don't tell me what the problem is. Please let me know if you see any. Note ...
2
votes
2answers
50 views

List of search results using Selenium

I have written the following code for looping through WebElements in Selenium. Can someone please provide me with feedback on how to improve my code? ...
-1
votes
0answers
12 views

Split the File which contain single line [on hold]

I have a single line file.I want to read file line by line based on delimiter *;Is it possible through Buffered Reader.I try through scanner like below.... ...
-1
votes
0answers
29 views

I am getting approximately 6 errors in this BinaryTree implementation and I'd like help fixing them [on hold]

I am getting approximately 6 errors in this BinaryTree implementation and I'd like help fixing them. Also I'd like any other advise for implementing Binary Trees. Also, while I have this code up, ...
0
votes
0answers
33 views

How to avoid StackOverflowError caused by the number of recursion calls in Java? [on hold]

I want to solve this problem: https://www.hackerrank.com/challenges/find-median ,i.e. find the median element in unsorted array. To do this I perform quickselect algorithm. My program works correctly ...
3
votes
1answer
62 views

Confusing control flow

Currently, the following code runs and produces the expected and desired output. However, I'm sure that there's much wrong with it. This project queries the (flat) database, instantiates each row as ...
1
vote
1answer
58 views

Simple Operations Calculator

I'm practicing Swing effects. Everything works but for some reason I get a ton of error messages in the command prompt when the fields are empty, despite my attempt to add some exception handling ...
6
votes
2answers
35 views

Program to find the element in an array

I'd like this code to be improved. ...
10
votes
1answer
69 views

Circular Wrapping Text, minor adjustments

I am actually pretty damn proud of this code, it's my first complex algorithm I have made. Basically it sets a shapes default size and radius based on how many characters are in a string that is ...