Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

5
votes
5answers
596 views

Checking if an integer permutation is cyclic in Java

A an integer permutation array[] is said to be cyclic if and only if we can choose an arbitrary element at position i, move it ...
-3
votes
0answers
24 views

Cache design with eviction policies

I am trying to come up with design for different types of cache with different eviction policies but I am facing difficulty linking the eviction policy with cache. Mainly what to pass in evict() ...
-4
votes
0answers
23 views

My HTML code is not working in IE while it is working in chrome [on hold]

Since my code is confidential (Company) I have 2 dropdown boxes lets say 1st Dropdown contains A B ...
10
votes
2answers
600 views

Given the mapping a = 1, b = 2, … z = 26, and an encoded message, count the number of ways it can be decoded

Given the mapping a = 1, b = 2, ... z = 26, and an encoded message, count the number of ways it can be decoded. For example, the message '111' would give 3, since it could be decoded as 'aaa',...
0
votes
1answer
28 views

A simple clusterness measure of data in one dimension using Java

Problem definition Given \$X = (x_1, \dots, x_n)\$ such that \$x_1 \leq x_2 \leq \dots \leq x_n \$. Let \$x_{\min} = \min X = x_1\$, \$x_{\max} = \max X = x_n\$ and \$r = x_{\max} - x_{\min}\$. Also, ...
0
votes
0answers
15 views

Java: avoid overwriting on a text file [on hold]

i'm a student at university and I am a beginner at Java. I had a job of writing an inventory program that add products in a list. I made a function to save and load data from the text file but ...
-2
votes
1answer
30 views

Is it good to pass dependencies as paramters? [on hold]

for example, here are two classes : ...
1
vote
1answer
40 views

Finding pairs that add up to a given sum, using recursion

I'm currently tasked with using recursion to find pairs that add up to a given sum. How would I make the function recursiveFixedSumPairs function more efficient and truncate this code? Also, what is ...
0
votes
0answers
12 views

Salesforce Live Agent Chat Client Code in Java

I have to use SwingWorker for the first time today, and I'm pretty pleased with the result. Would you mind helping check that I used it correctly? My class starts ...
-1
votes
3answers
62 views

A Java Calculator that could perform basic Mathematical Operations [on hold]

I've been working for few days to develop a basic Java Swing Calculator that could Add, Subtract, Multiply or Divide two numbers and also has other options like inverse(1/x) and square root. But I am ...
0
votes
1answer
20 views

use javax.xml.stream.XMLStreamReader [on hold]

I use stax to parse xml. ...
2
votes
1answer
79 views

First missing positive integer in linear time and constant space

This problem was asked by Stripe. Given an array of integers, find the first missing positive integer in linear time and constant space. In other words, find the lowest positive integer that ...
0
votes
0answers
19 views

Classifying test data into several classes in Java [on hold]

This program gives me error on Class Lege and class Spesialist. I can't figure out why I can´t run my test program at the bottom. ...
-1
votes
0answers
31 views

Object-Oriented Board Game [on hold]

I have an assignment for my class in which I have to write a simple board game in Java, but there are some parts where I just can't figure out what to do. I'm trying to figure out how I can assign ...
4
votes
1answer
50 views

Deserializing an XML Object without Reflection / Meta-Programming

I need to deserialize an XML file, without using any sort of "reflection" (or meta-programming). Instead, I need to do it via a raw object, that knows of it's structure and can properly identify and ...
8
votes
2answers
780 views

Concatenate words in such a way as to obtain the longest possible sub-string of the same letter

An array of N words is given. Each word consists of small letters ('a'- 'z'). Our goal is to concatenate the words in such a way as to obtain a single word with the longest possible sub-string ...
4
votes
1answer
86 views

Object-Oriented Breadth-First Search Implementation

My goal is to write a GUI application where a user can create a maze and select an algorithm. The passage of the algorithm from a selected start and end point should be visualized. The following ...
5
votes
3answers
122 views

Chess move validator

I have written code for making a Chess Validator, which will validate the moves of a chess game. There is a Main class which is taking the input from the user, about the move. Problem Description ...
-3
votes
0answers
11 views

How to store a range of generated numbers using IntStream to a text file [closed]

I wrote a program to generate a range of numbers using IntStream (java 8) but can seems to figure out a way to store the generated numbers into a text file. I know how to store Strings to a file but ...
1
vote
1answer
33 views

Incrementing time in a discrete-event simulation of a supermarket queue

A method has been written that increments time in minutes that simulates how much time it takes to process item in a supermarket queue and if there is an empty queue, skip it and loops around to find ...
1
vote
3answers
42 views

SPOJ Adding reversed number in Java

I just started to practice for competitive programming and just started to solve the most solved problems on SPOJ. This is what I made for ADDREV: Adding reversed numbers in Java (https://www.spoj....
3
votes
2answers
75 views

Battleship Game in Java

I wanted to make a very simply Battleship game in Java, any feedback is welcome. Nevermind the getters / setters. Just assume they are there. ...
0
votes
1answer
39 views

Insertion sort algorithm in Java

I have tested this code and it yields the expected outputs, but I want to verify if I have applied insertion sort algorithm correctly or not. ...
3
votes
0answers
65 views

Sequential master update

I'm creating a version of the classic sequential master file update in java. This is used when you sort two files by the same key for updating one file with the other. In this case, I'm pulling in all ...
0
votes
0answers
25 views

Templated JSON parsing methods that work with an element or elements array

Consider the following two Java methods. The first takes a JSON string representing one element, the second representing multiple elements. gson.fromJson() can be ...
0
votes
0answers
26 views

adding jms in the rest api flow

In my spring boot app, I am trying to fit in the sender and receiver logic for JMS queue as described here I've put the content of "Sender.java" and "Receiver.java" classes from the above ...
3
votes
1answer
44 views

Swap Elements in Array if first characters match but only once per first character

This is my solution to CodingBat problem p150113. My Java knowledge is from 2011 and I'd like to know if this is still the optimal way to approach such a problem. and if my code is clean and ...
0
votes
0answers
11 views

Make lambdas concise using enumerations? [migrated]

Generally, we are looking to create a logging framework that can target human readable output as well as various structured data formats. So, a goal is minimizing code duplication in packaging the ...
3
votes
3answers
94 views

LeetCode Problem 66 : Plus One

I have started practicing problems in leetcode and I solved the following problem on LeetCode. The challenge is : Given a non-empty array of digits representing a non-negative integer, plus one to ...
2
votes
1answer
50 views

Word Chain Implementation follow up

it's hard for me to implement all those features that were suggested, i did so many thing wrong. can you please review this update on my code, concerning OOP, clean code, and maybe an eye on the ...
1
vote
1answer
36 views

Token generator for Valve Data Format parser in Java

I'm looking to parse a reduced subset of the Valve Data Format (VDF). It is similar to JSON, allowing representation of key-value collections (maps) with arbitrary recursion. As a small example: <...
-2
votes
2answers
50 views

Refactor multiple if statements while creating object [closed]

I've got a class with few fields: ...
-1
votes
0answers
21 views

Null Pointer Exception based on HashMap [closed]

I am getting a Null pointer exception despite instantiating a general HashMap with constant values. I intend to track inventory of various car types in a car rental service; with car type serving as ...
4
votes
1answer
107 views

Word Chain Implementation

The idea originaes from the CodeKata19, find a word chain for two words of a wordlist example 1 turning lead into gold: ...
1
vote
1answer
30 views

A simple Java class for implementing code stop watches - follow-up

I have received a nice answer for this post. Now, it is my attempt for some improvement: ...
1
vote
0answers
29 views

Java: Note for monitoring buy/sell item list

I'm making note where you can add items that you buy or sell, any suggestions? ...
1
vote
1answer
57 views

A simple Java class for implementing code stop watches

(The next iteration: A simple Java class for implementing code stop watches - follow-up) Here is my attempt at more convenient benchmarking (yes, this time I am aware of JVM warmup, etc.), and it ...
4
votes
2answers
82 views

Follow up Implementation on Monty Hall Simulation

I have taken your inputs on my original question and formed a new implementation of the Monty Hall Simulation: Again keep an eye on CleanCode and OOP The Price to be won: ...
3
votes
2answers
77 views

Printing out a table in console

This program prints out a table in the console. Suggestions for improvements are welcome. Example output ...
0
votes
1answer
15 views

Generate n appointments in the next m months

I work with an API where I need to write code to generate n appointment dates in the coming m months (from today). For the purpose, I write a Random date generator class provided. One condition is I ...
0
votes
0answers
35 views

Split data equally to Thread in java

Is this efficient way to split the record which is comes from database? So that the thread will process the record based on the start and end points. Step 1: Get the total number of records from ...
1
vote
1answer
33 views

POSIX-ly finding a specific Java process

In this code I find a list all of the running java processes and give the below function a name to look for, it will do its best. But since I find my approach a ...
2
votes
1answer
48 views

Calendar holidays to XML

We are writing program which makes XML file which is a calendar with all free days in Poland (Saturdays, Sundays, and all hollidays). We tried to write this code as readable as possible so probably no ...
2
votes
2answers
51 views

Simple war scheduling algorithm in Java

Let \$\mathcal{C} = \{ C_1, \dots, C_n \}\$ bet a set of \$n\$ different countries. We associate with each country \$C_i\$ with its potential \$P_i\$. We choose a specific country \$C_e\$ in \$\...
0
votes
1answer
36 views

Bowling Game Kata

I wanted to practice my programming skill and I started solving exercises from kata-logs site. The exercise: The game consists of 10 frames. In each frame the player has two rolls to knock down ...
3
votes
1answer
63 views

Reference service for a cache

I'm using JDK 11. This is my code: ...
1
vote
0answers
48 views

Snake animation in Swing

I'm developing a simple Snake game in Java using Swing. So far I made the snake animation which is troubling me: when the snakes moves it seems like it starts to lag for no reason, but when I move it ...
0
votes
0answers
52 views

Please check my HTTPServlet route parsing extension for quality

Please critique my codebase https://github.com/davidbyng/acme-simple-servlet-extension ...
3
votes
1answer
106 views

Clean Code / OOP on Monty Hall Simulation Implementation

can you review the this code for the Monty Hall simulation, mainly on the aspects of OOP and CleanCode ...
3
votes
3answers
62 views

Simple boolean gate with two TriState inputs

As part of a code review I came across this isDummy(a,b)-Method and the question, whether it is more readable as a conjunction, or a disjunction: Original snippet: ...