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

Whats the best approach to report exceptions to the caller? [on hold]

I have the following code that return integer values to report type of the raised exception to the caller of the method and eventually user of the application. I suppose it is not the best way to do ...
2
votes
0answers
10 views

Rotating Text in Circular Pattern Using JavaFX

Just wanted to see what you all thought about my program, I basically have two different classes that I designed to allow for automated wrapping of text in a circular pattern. This is my first bit of ...
1
vote
0answers
14 views

Deepest left leaf node in a binary tree

Given a Binary Tree, find the deepest leaf node that is left child of its parent. This question is attributed to GeeksForGeeks. Looking for code-review, optimizations and best practices. ...
3
votes
0answers
26 views

Flatten a multilevel linked list

Given such a structure the output should be ...
7
votes
1answer
49 views

Perfect game loop

I've been working on development for an Android game, and this is the game loop I have so far: ...
3
votes
3answers
41 views

Use a Java Array like a List

I'm saving string values in an array one at a time so I cannot initialize the array with the values all at once. After I'm done with the array I need to pass it to another class that is expected a ...
2
votes
2answers
24 views

Calculating the number of prime numbers to solve the puzzle

How can the following program execution time improved? I have used dynamic programming in both "recursive" as well as "prime" function, but I'm not getting the efficient execution time. There is ...
4
votes
0answers
29 views

Making a lightweight app in BlackBerry Browserfield

This is an app made by me to display a web page on blackberry and to add some more features like checking network connectivity while opening app, loading some URL in browser rather than app, making a ...
2
votes
0answers
22 views

Reverse values of alternate nodes of the tree

Given a Perfect Binary Tree, reverse the alternate level nodes of the binary tree. Given tree: ...
9
votes
5answers
1k views

Dynamic programming with Fibonacci

I have written the following code using a dynamic programming technique. Can I use ArrayList here? Please let me know if I can improve this code. ...
5
votes
0answers
41 views

Why does the new ADT create a static inner class Fragment by default?

Honestly, I can't help but feel that this is done merely to confuse newcomers. Most of the errors on Stack Overflow by complete Android newbies mostly stem from that they have a static inner class ...
5
votes
2answers
48 views

Queue that connects multiple producers and multiple consumers

The scenario is about processing 'Message' objects. Producer creates them and Consumer does the consumption. ...
3
votes
2answers
152 views

Simple Java web app code

I wanted to work on HttpSessions and JSP. This is the view I have: ...
9
votes
5answers
589 views

Using sounds in Java

I'm trying to apply sound today, and the goal in mind was a simple violin tuner. The actionListener seems repetitive/ How might I optimize it (what I tried just ...
7
votes
1answer
70 views

Program to insert, search for and delete an element from an array

I'd like this code to be improved. ...
4
votes
1answer
47 views

Making this site navigation less verbose

I have this one controller that serves up all the webpages and any dynamic content. Is this the most efficient way of doing this? Can it be improved? ...
6
votes
1answer
46 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, ...
4
votes
2answers
52 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 ...
1
vote
1answer
87 views

Base generic DAO to work with different POJO classes

Right now, I have base abstract GenericDAO class to execute CRUD operations with different kind of objects. I have Customer and Employee POJO classes which are used ...
0
votes
0answers
23 views

Find POJO by one field in List [on hold]

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

understand operator precedence [migrated]

Was fixing bug in our code and found this weird function that was misbehaving: ...
1
vote
1answer
60 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
35 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 ...
6
votes
1answer
78 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
38 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
22 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
25 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
46 views

Simple Calculator - revised

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

Inefficient Stopwatch - revised

This is my revised code of Stopwatch: ...
2
votes
1answer
35 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
26 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
714 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
66 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
102 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
102 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): ...
12
votes
3answers
461 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
175 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
57 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
64 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
737 views

Class for catching error and logging

I often write something like this in my code: ...
11
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
119 views

Eliminating duplicated code blocks

I have an abstract PersonDao class, extended by several other DAO classes, for example EmployeeDao, ...
2
votes
2answers
146 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. ...
-2
votes
0answers
26 views

Need help to create a method in DAO [closed]

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 ...
3
votes
1answer
27 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
26 views

Encryption in Java and Decryption using in C# using AES [closed]

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 ...
12
votes
4answers
143 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
558 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? ...