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)

0
votes
0answers
11 views

How to 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 below table, ...
0
votes
0answers
21 views

Get the levels of binary tree

Given a binary tree, return a list of each level. I'm looking for code-review, best-practices, and optimizations. Also verifying complexity. Time complexity: \$O(n)\$ Space complexity: ...
3
votes
0answers
21 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
77 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): ...
6
votes
2answers
189 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
163 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
52 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
0answers
51 views

Method to close a lot of closeable objects

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

How should I name this helper class?

I often write something like this in my code: ...
8
votes
3answers
969 views

How to tidy these two similar methods using the DRY principle?

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
109 views

Eliminating duplicated code blocks

I have an abstract PersonDao class, extended by several other DAO classes, for example EmployeeDao, ...
2
votes
2answers
135 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
20 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
19 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 ...
9
votes
3answers
72 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
528 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
15 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? ...
5
votes
1answer
53 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
621 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
21 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
26 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
21 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
91 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. ...
2
votes
2answers
75 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
44 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
28 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
32 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
60 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
56 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 ...
1
vote
0answers
22 views
10
votes
1answer
68 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 ...
10
votes
2answers
130 views

100 gunmen in circle kill next person

The question is here. 100 people are standing in a circle with gun in their hands. 1 kills 2, 3 kills 4, 5 kills 6 and so on till we are left with only one person. Who will be the last person ...
5
votes
1answer
112 views

Memoized Fibonacci

I went ahead and I implemented a method to calculate Fibonacci numbers using memoization. ...
2
votes
0answers
24 views

Secure password-hashing in Java

Here is an article on password hashing, along with an implementation. Is this code secure with number of iterations 10000, key length 256 and salt bytes 32? Is there a rule-of-thumb for key ...
0
votes
0answers
27 views

How to re-factor this code portion? [on hold]

I have to write a method which return a String based on density and width. First of all I have to check if the width in between 600 to 720 or above 720. And then if ...
1
vote
0answers
21 views

Following-up “given a two dimensional linked list, create a flattened sorted list”

A node has a next and down pointer. Merge the linked-list such that end result is sorted. Here we have a top level linked-list, followed by a down-list. If { 10 : {20, 30} , 35 { 40, 50 } ...
11
votes
2answers
110 views

Dog owner simulator

I've just started programming and read a book called Head First Java. I thought it would be fun to make a training project that I can put all the stuff I learn into. Is the code I've written here ...
-1
votes
0answers
31 views

Followup to BigInteger Cube Root Optimization

Followup to Followup: How do I optimize this Java cube root function for BigInteger? Here's my current code for this cube root approximation for BigInteger, which returns the integer part of the cube ...
1
vote
0answers
28 views

Finding if there is a subset that sums to a target value from an array of integers

I came across this problem. Problem Statement: Given an array of ints, is it possible to choose a group of some of the ...
2
votes
1answer
26 views

Logging a message and the stack trace of caught exceptions

Using Spring's JdbcTemplate to load a specific object by ID if exists, I have this code: ...
21
votes
8answers
2k views

The FizzBuzz challenge in Java 8 written in a short, readable and interesting way

I decided to take on the FizzBuzz challenge with as twist that I would use Java 8 concepts to make it a bit modular, yet still let it be a short, readable and understandable program. This in contrary ...
3
votes
1answer
32 views

How to generate valid number of combinations of datacenter and its host id?

I have a list of datacenters, which are dc1, dc2 and dc3. And each datacenter has six ids as ...
3
votes
1answer
43 views

Refactoring this producer consumer class to minimize what is exposed

I don't like the service class below, specifically, the way it exposes the internals of the producer. While it would be possible to combine all three classes into one producer-consumer, I would ...
3
votes
3answers
213 views

Can this insertion sort be optimized?

Could you provide feedback for this code? For arrays of length 2, is it more efficient not to use a sorting algorithm? ...
5
votes
1answer
30 views

Using SQL to reorder items in a list view - is this efficient?

I'm writing an application for work that requires me to process a list of transactions. The list is small (5 records at the most) and I'm required to display that data in an android ...