Questions tagged [java]

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 bytecode and run in a virtual machine (JVM) enabling a "write once, run anywhere" (WORA) methodology.

Filter by
Sorted by
Tagged with
4
votes
0answers
71 views

RGB to YCbCr conversion in Java

I found a Go language code to do RGB to YCbCr conversion from here! I ported it to Java: ...
1
vote
1answer
39 views

Splitting a String into words and add to an array, Only using StringBuffer and String Array

I've been doing a Java for beginners course for a few weeks (2 hours a week), we had an exam question. Take a sentence as an input from a user for twitter. Using only String Arrays and String ...
4
votes
3answers
55 views

Simulation of forest growth and pruning

I was wondering how I could streamline the following code. This was the project assigned to us: The Canadian Forest Service wants to do a simple simulation of the growth and pruning of forests. ...
1
vote
0answers
39 views

Map of Map iteration in java 8

I want to iterate a map of map in a java 8 way and get the entry which contains 40 in the value in the inner map. I have tried the following code in order to do that. But I still don't understand ...
1
vote
2answers
160 views

Leeetcode - Best time to buy and sell stock to get maximum profit

Question Say you have an array for which the ith element is the price of a given stock on day i. If you were only permitted to complete at most one transaction (i.e., buy one and sell one ...
5
votes
3answers
98 views

Field class as a basis for a role playing game

My programs that I have written so far included only a few lines of source code. When I tried to write larger programs, it usually failed because I'm not a master of software engineering. This time, I ...
-2
votes
1answer
53 views

Which is best choise performance wise Double or BigDecimal to calculate percentage of tax? [closed]

I've to calculate 50% of tax . So I approach it using two ways. 1) public static void main(String[] args) { new Double(500) / 100 * 50); } 2) ...
-2
votes
1answer
35 views
2
votes
2answers
53 views

Find all k points which are closest to origin

We have a list of points on the plane. Find the K closest points to the origin (0, 0). (Here, the distance between two points on a plane is the Euclidean distance.) You may return the ...
3
votes
1answer
48 views

Find number of islands Leetcode

Here is the question: Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally ...
1
vote
2answers
68 views

Making toString function more readable In Java

I'm trying to make my code more readable. I created a function toString - It returns a string in the following format: ...
5
votes
1answer
65 views

Goldbach conjecture solution finder

The Goldbach conjecture says: any even number greater than two can be represented by the sum of two prime numbers. G(n) = { (p1, p2) | p1 + p2 = n, p1 and p2 are prime numbers with p1 < p2 } ...
1
vote
1answer
49 views

Caret color and movement animation in Swing

I'm developing a new Look and Feel that is based on animation , so I've decided to make animated text caret too ! The caret works as expected every thing is fine except that am worried about how I ...
1
vote
2answers
82 views

Input class in Java

I'm a newcomer to Java (I primarily do C# ) and I have to say that they have made I/O handling much more difficult than it should have been. I am accustomed to the scenario where when I need keyboard ...
1
vote
1answer
26 views

Summing buying and selling rate fetched from the web txt

I've got a class that is like a facade, like an engine for my application which is responsible for fetching data from url and summing it. I have got problem with proper names for my methods. ...
0
votes
1answer
64 views

Grouping objects that have the same attributes

A list of objects needs to be grouped. The list is iterated and checked with other objects in the same list except itself. The method People.isAttributeEqual() checks if two objects can be grouped. ...
1
vote
1answer
38 views

Depth-first traversal implementation in Java (by recursion)

I implemented a recursive depth-first traversal, with all three traversal modes in this function. Is this the most succinct way to write the code? ...
11
votes
2answers
2k views

Employing 3DES algorithm in Java

I am making a project just for fun that employs the 3DES algorithm in Java. I was wondering if my algorithm looks secure. Is there any advice or feedback you could give me? Do I need to include an IV? ...
2
votes
0answers
54 views

Efficient counting sort for large byte arrays in Java

I have this counting sort for byte values running in linear time with respect to array length: Arrays.java ...
2
votes
0answers
29 views

Having single DAO parent class in an EJB application

I have the following DAOParent class that I use to put connect/disconnect code in one place. Each DAO class in the application ...
4
votes
1answer
200 views

Lazy Loading a Bioinformatic SAM record

I'm currently writing an API to work with Bioinformatic SAM records. Here's an example of one: ...
4
votes
2answers
803 views

Compiling and throwing simple dynamic exceptions at runtime for JVM

I've been using my Dynamic Exception with C# for quite some time already and it saved me a lot of time. This means, I don't have to create a new exception ...
3
votes
2answers
92 views

Design a sustainable home tracker and calibrater for power, water, gas to minimize the expense

Problem Statement Following are the various scenarios to be considered Track energy - Track consumption of water, gas and electricity. We should be able extend to capture other type of ...
0
votes
0answers
24 views

Select a value other then currently selected drop down value

Scenario:Select a any other value other then currently selected from a drop down. Please help/review the code and tell me whether this is a efficient solution? ...
1
vote
2answers
103 views

Typed properties in Java

I tried to build a "typed" property system in Java and this is what I came up with: first the class Properties that any class can use as an attribute (demo code in the end). ...
5
votes
1answer
82 views

JavaFX Connect Four AI

I made a Connect Four AI with minimax algorithm. It's my first bigger JavaFX project. Any help for improvements would be really appreciated. Board: ...
2
votes
4answers
172 views

Find the thousandth integer without the digits 3, 4, and 7

I have to find the thousandth number (excluding numbers 3, 4, 7) but it's taking a long time, about 9 seconds. I'd like to find out how to improve performance. ...
2
votes
1answer
179 views

Implement Queue using fixed size array

I came across below interview question and I am working on it: Build a queue class with the enqueue and dequeue methods. The queue can store an UNLIMITED number of elements but you are limited to ...
0
votes
1answer
27 views

PreparedStatement for closable recordset and connection

Following approach uses more Functional approach (non OOP), each method is passed DataSource as dependency. I've written this piece and I'm wondering if there's something that can be improved. I wish ...
2
votes
1answer
62 views

Implement search for JPA and Spring

I'm trying to implement properly search functionality for database table. I tried this approach: Controller: ...
-2
votes
1answer
37 views

Search customer by ID not printing [closed]

I dont know why my code is not working at all. In my Eclipse there's no errors shown at all. I want to use the id to print the name of my customers, and that's my goal ...
3
votes
0answers
84 views

Java game: select numbered tiles to form a goal sum

This is a homework project (Soft. Eng.) which I have completed. My teacher gave me a 91, but I am unhappy with this grade because my code is quite messy. (Please excuse incomplete Javadoc, the code is ...
0
votes
2answers
77 views

Making Anagram Problem Implementation

Problem Statement Alice is taking a cryptography class and finding anagrams to be very useful. We consider two strings to be anagrams of each other if the first string's letters can be rearranged ...
2
votes
1answer
63 views

MinMax Problem Implementation

Problem Statement: You will be given a list of integers, arr, and a single integer k. You must create an array of length k from elements of arr such that its unfairness is minimized. Call ...
1
vote
0answers
34 views

Java local service with sockets

My goal was to create a Java service on Windows that runs locally and communicates with local programs using JSON. The service should be reliable and robust. The service runs a ServerSocket and ...
0
votes
0answers
21 views

Authentication and auto renewal of an API Token

Following is an https call to retrieve the token, once it's retrieved, it's cached. Callers call the addTokenObserver method that sets a timer based on the token ...
2
votes
0answers
49 views

Code Chef's Cleaning Tables: find the minimum number of tables to clean

Description: Haku has been newly hired by Chef to clean tables at his restaurant. So whenever a customer wants a table, Haku must clean it. But Haku happens to be a lazy boy. So in the ...
0
votes
1answer
69 views

Combinational string search using Java

I wrote a program that receives 2 strings (Input and Search) in the Search string. The sign '+' indicates that if the substring before the '+' exists in the Input string. (The search string cannot ...
3
votes
1answer
72 views

Settings class implementation

I have a settings.txt file with the following format: ...
1
vote
0answers
18 views

split verticle instantiation and configuration loading in vertx application

I am using Vert.x. I've got a single verticle for my application that looks like this ...
1
vote
1answer
62 views

Extract Common Data From List of Objects

I have a list of orders and for some order fields I need get the data that is common among the orders. If the data is not in common, I should indicate null. I collect the common data in a ...
6
votes
3answers
135 views

Rotate array to the left

I am a beginner in programming. To rotate the array to left, I have written the below code. Please point out how to optimize the code and anything I am doing which is not good programming practice. <...
1
vote
1answer
32 views

slow JavaFx PostgreSQL CRUD app with complex object

I've created a JavaFX app to the data about Vessels, Employees and Jobs. The current version works but it is quite slow which I need to fix. I understand the root of my problems but I do not know how ...
2
votes
0answers
35 views

Comparing Java Semaphore versus ReentrantReadWriteLock

In this post, I attempted to compare the performance of two concurrency constructs: java.util.concurrent.Semaphore, ...
1
vote
1answer
44 views

Validating variables/fields from a schema object

Can someone help me to create a generic method that validates common fields/variables comes from multiple objects, if that is possible? The below code validates some bunch of variables/fields from a ...
3
votes
1answer
25 views

Mortgage calculator with Swing for Helsinki MOOC

New to Java, just finished the Helsinki MOOC course. I programmed a basic mortgage calculator as my first solo project and while it works, I have a few questions about coding style: The listener and ...
3
votes
2answers
186 views

Trip planning algorithm

I was presented with an interview question described as follows: Receiving an int[] A of cities, where each A[i] has an appeal ...
1
vote
0answers
21 views

Fetching SQL table names and dynamicly insert values

I need to make a UI where I can edit/insert/remove records of my SQL tables through my app. Edits and deletes of records works fine except of insertions when it comes to tables with auto-incremented ...
4
votes
2answers
59 views

Android NDK Low performance

I am trying to write a NDK program for quicksorting an array. However, in my benchmarks C is doing consistently worse than Java, as indicated by my results: Java 1190625 C 1809218 Java 895104 C ...
1
vote
1answer
60 views

Abstracting getter and setter method references for testing

Is the following code easy to understand? If not how should it be changed to be more understandable. The purpose of this is reducing similar code in unit tests. This avoids repeating lines for calling ...