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)

5
votes
0answers
18 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 ...
10
votes
0answers
21 views

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
0answers
23 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
150 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
30 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
23 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
38 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
60 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
23 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
53 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
31 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
241 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
16 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
88 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
61 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
128 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
46 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
672 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
38 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
323 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
28 views

Java implementation of QuickSort [on hold]

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

Making this arraycopy more efficient

I'd like to find out how I can make my function more efficient: ...
12
votes
2answers
159 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
599 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
140 views

Concurrent activity on ArrayList

I have an immutable Point class and a CollectionPoint class which manages instances of my ...
6
votes
5answers
276 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
47 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
157 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
51 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
240 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
35 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
22 views

Text-Based Calculator having errors with the Scanner [on hold]

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
26 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
73 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
222 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
103 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 ...
6
votes
5answers
139 views

DP solution to min triangle path

I am studying for interviews for various companies. I wrote a solution to this problem, but if an experience programmer looks at it I am sure there are certain areas the code can be made in to a more ...
-1
votes
0answers
16 views

Java API initialization [closed]

I am developing an Android Library which involves both Network and Bluetooth communication. In order to start using the library it must be configured. In other words a request to the backend must be ...
8
votes
5answers
679 views

Project Euler #1 efficiency

I've started solving Project Euler problems. Is the code completely optimized? Question: 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 ...
0
votes
1answer
73 views

Reduce complexity of method

I would like to reduce the complexity of this calculate method as it is too long in my opinion. There is already a number of helper methods exist which are called throughout the method. I can't really ...
5
votes
1answer
35 views

Unit testing annotation processors in Java

I'm working on a micro-brenchmarking framework in Java. To give you some context, this is how it will work: Given multiple implementations of some algorithm, and you want to compare which one ...
3
votes
2answers
148 views

How do I (beautifully) extract this part of code to a subclass?

I have thought a lot about this but can't come to a proper solution. Also, it's hard to google things like this. Note: The code itself is irrelevant, it's about how to do such a thing in general. I ...
7
votes
4answers
60 views

Android Global Variable Setup

I am using the Android library Retrofit for networking in my app. The library calls for creating a RestAdapter for making service calls. I want to use this same instance of the RestAdapter for all of ...
1
vote
1answer
48 views

Trying to catch and throw exceptions if error message window is found

I'm writing a test to validate that while clicking through a series of menu items, an error message pops up, and if it does, then I should throw an exception. Now I wonder: Is it appropriate to use ...
6
votes
5answers
568 views

Given a String, return a boolean if it is a number

Yesterday in an online interview, the interviewer asked me this question: If I give you a string, you have to return if a string is number or not. You are not allowed to use any parse function ...