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)

4
votes
2answers
74 views

How can I refactor onClickListener applied to different buttons?

I have several buttons and I want to toggle between them like radio buttons. The way I have it set up now is that each button have this same code but the buttonValue varies depending on which button ...
1
vote
1answer
13 views

Method to Return a Hibernate Session

Can this method be improved?: ...
0
votes
0answers
6 views

Getter within loop returning null after assigning values [migrated]

I've got a slight problem with my program. Simply put, what I do is this: Choose the option to "Add a new Student record". When I try to display the newly added values (First Name, Last Name, ...
0
votes
0answers
18 views

Java - I have a partially working pacman game but would like tips for improving [on hold]

I am creating pac man for a project, but i've ran into trouble moving around my character. Specifically implementing wall collision, I can move the character fine just not when I try to put in wall ...
2
votes
1answer
29 views

Precognitive waiting - waiting for something to finish, before it starts

I have implemented a class that has a method to wait until "something else" has happened. When this has happened, the current thread stops waiting and returns from the method. This is my current code: ...
1
vote
0answers
29 views

Generate Cartesian product of list in Java

My code, which generates Cartesian product of all lists given as arguments: ...
4
votes
3answers
407 views

Estimating stars' attitude

I have to refactor this method: it seems to duplicate two code blocks with some slight variation. Any suggestions? It is a bit of a mess :) ...
-3
votes
0answers
31 views

How do I finish this up? Sorting a list of arbitrarily generated integers [on hold]

Write a program that will sort a list of arbitrarily generated integers in descending order. Let the user determine how many arbitrary and unique numbers to sort from 1 to 10000. Use the random ...
2
votes
1answer
20 views

Filtering JSONArray by Branding & Modelling

I have a small function that takes in a list of JSON objects that has the format below. The function below that wants to see if the brand and model of car passed to it can be matched against the List ...
8
votes
2answers
61 views

Optimizing String combinations in Java

I need to obtain all combinations of a String of length k from the given elements. For example, for ...
13
votes
1answer
67 views

It's Friday! - Zeller's Congruence Revisited

A couple of date-related questions have come up recently, and on both occasions I have been taken back to my 'early' days where one of my first forays in to programming involved implementing Zeller's ...
0
votes
1answer
34 views

Optimizing Dijkstra implementation using PriorityQueue in Java

I am trying to make Dijkstra implementation more efficient. Below is the code for class Node which implements Comparable so it ...
5
votes
1answer
158 views

Logging with date in Java

I write my log messages in JTextArea. Each message should have a time added. I created a following method: ...
1
vote
0answers
34 views

Generic Java Task Scheduler (Followup) [on hold]

As a followup to my previous question, and after receiving a great answer, here is the updated Scheduler class. I would also like to state some goals & ...
0
votes
0answers
26 views

Potholes in a multiplayer snake where players can use their own algorithms [on hold]

Topic originating from stackoverflow. I'm developing a snake-like multiplayer where players can use their own algorithms to determine the next move of their snake. A little background: My game ...
3
votes
1answer
46 views

Improving efficiency of Prim's Algorithm

I have implemented Prim's Algorithm in Java. I am wondering how it can be made more efficient. Below is the class Node for vertices. ...
6
votes
1answer
63 views

Generic Java Task Scheduler

I wrote this generic task scheduler for executing tasks in fixed-delay intervals, can you find anything wrong with it, or issues that may arise from using it for sending something like queued mails in ...
0
votes
0answers
24 views

Best approach to a defined datascructure [on hold]

I've here a TXT file with some data that I can't change. So I have to create a datastructure to read this file and with that datastructure do some thousands of iteractions. The file follows a ...
4
votes
0answers
57 views

Transformation of abstract models

In one of my recent projects I faced the problem of transforming an abstract class into another abstract class. The classes were structured like this and are part of an api for questionnaires: ...
-2
votes
0answers
33 views

are there any test cases whose answer comes out to be wrong for following code? [on hold]

I have tested the following code and it works perfectly, yet the Hackerearth tells that it is wrong for 3 inputs, You are given two integer numbers: the base a (number of digits d, such that ...
4
votes
4answers
242 views

Get the environment variable's value

I've written a function which can get the environment variable's value. The input parameter would one of the following: ${machine}/bin ...
0
votes
0answers
17 views

How to “adapt” DOM (which read XML file) to a Jtree (which display parserized XML file) using Adapter Pattern [on hold]

'm making an exercize using Adapter Pattern and I would to adapt Jtree interface to a DOM class. Here there is my DOM class (Target): ...
24
votes
2answers
2k views

Quicksort implementation seems too slow with large data

I've written a program to compare different sorting algorithms with the array size being 10, 1,000, 100,000, 1,000,000 and 10,000,000. I, of course, expect Insertion to win out on 10 and merge heap ...
5
votes
3answers
89 views

Monitoring params via JMX

A task for hiring on a new job (I failed it with reason "very bad code"). Write a program, which will be monitoring the params via JMX. Param should have name, type and observabale value. Why my ...
1
vote
0answers
63 views

Using basic methods to make a high/low game [on hold]

This is my first big project with using methods. My prompt is to: Write a Java program that plays the dice game High-Low. In this game a player places a bet on whether the sum of two dice ...
4
votes
2answers
130 views

Showing a list of plugins to filter

How can I refactor this function? I show a list of plugins in JSF, and I should filter them. I added function filterPlugins but I have some questions: Should we ...
4
votes
2answers
51 views

Managing FutureTask and ExecutorService

I have many unrelated tasks to execute and I have to get the result of the task so I use the FutureTask. I submit all the task to the thread pool and use a map to ...
9
votes
1answer
673 views

Memory-Test for Soldiers

I am solving the following problem on code chef: \$N\$ Soldiers are lined up for a memory test. They are numbered from 0 to N-1 from left to right. In the test, there are \$M\$ rounds. In each ...
4
votes
1answer
42 views

Error Handling in Servlets and JSPs

I have an HTML login form that is processed by a servlet, which then redirects the user to a result page. login.jsp: ...
11
votes
2answers
328 views

Introductory Currency Converter

This is my basic currency converter for my intro to Java class. I'm supposed to be able to convert between Yen, Dollars, Pounds and Euros using static rates. It works, but I was curious to know if I ...
0
votes
0answers
29 views

Java implementation of QuickSort [on hold]

How can I improve the following code: ...
3
votes
2answers
74 views

Making this arraycopy more efficient

I'd like to find out how I can make my function more efficient: ...
12
votes
2answers
163 views

Calculating the minimum distance of a linear code

This is a solution for the problem named Codes on the kattis platform: Given a generator matrix of a linear code, calculate the minimum distance of the code. I'm looking for reviews on ...
11
votes
2answers
605 views

Memory with a twist

Description This is the good old game Memory with a twist: Every time you pick a wrong pair, the two tiles you chose will switch their location. So sometimes you might think that a tile is at one ...
4
votes
2answers
142 views

Concurrent activity on ArrayList

I have an immutable Point class and a CollectionPoint class which manages instances of my ...
6
votes
5answers
278 views

Is there a more efficient way of executing multiple SQL prepared statements at once?

I'm updating more than one table at once and, as you will see, it uses a lot of similar looking code. Is there a more efficient way of doing this, perhaps some way of combining the queries? For ...
3
votes
1answer
49 views

MySQL Java in JTable

This is an assignment posted here. (Part-B) The aim here is to create a GUI in which the user can search for and insert data into a particular table of a MySQL database. Is this an appropriate ...
5
votes
3answers
160 views

Catching NullPointerException in Servlets

I have a servlet that processes user registration to a website. It takes inputs from an HTML form like username, password, email, etc. MySQL Table: ...
2
votes
2answers
222 views

Project Euler #3 Efficiency

I'd like to reduce the complexity of my code Problem : The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of a given number N? Solution : ...
4
votes
1answer
52 views

Fast regex to extract strings before and after a time

I want to get text1 and text2 by splitting time format Text1 10:24:02 Text2 Of the ...
6
votes
2answers
241 views

Project Euler #2 Efficiency

I'd like to reduce the complexity of my code. Problem : Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will ...
1
vote
2answers
36 views

Test Scores and Summary Statistics from a file

This program takes a file from a user, "example.txt". The file contains only positive integers, and the first interger in the file is stating how many intergers come after that integer (Ex. 3, 45, 98, ...
6
votes
2answers
129 views

Merge Sorting Lists

I'm fairly new to Java, arriving in the "future" from C and returning to type safety from Python. I'm looking for your suggestions to improve this code in the following areas: Correctness - are ...
-1
votes
0answers
23 views

Text-Based Calculator having errors with the Scanner [closed]

The goal of this project is to create a program that reads from an input file and process the commands. It compiles but I get an error when I try to run it from the Scanner that I'm using. Here's the ...
4
votes
1answer
47 views

BigDecimal made Simple - take 2

Following all comments on my original post: BigDecimal made Simple The following interface was derived from functionality provided by (mainly) Bigdecimal and is ...
1
vote
1answer
27 views

Self-made linked list implementing List<E>

I have to make a linked list as a quasi-homework task, about which I have already asked two questions about here and here. Since the whole code is really big (400 lines approx.), I will include only ...
9
votes
2answers
76 views

Min triangle path - bottom-up

I got a bit intrigued with the recent question DP solution to min triangle path and after a certain chat message I decided that I wanted to implement my solution. Given a triangle, find the ...
4
votes
1answer
42 views

Effeciency Project Euler #1

If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below 1000. Could ...
4
votes
2answers
224 views

How do I decrease compile time and execution time of following program?

How can I decrease the running time and compile time of the following code? Given three integers A, B and ...
5
votes
3answers
104 views

Custom linked list implementing Iterable used as stack

I have created a custom linked list that implements the Iterable interface. I am then using this linked list to implement my custom stack. I have also thrown a ...