Stack Exchange Network

Stack Exchange network consists of 174 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.

3
votes
0answers
30 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 ...
1
vote
3answers
30 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....
0
votes
1answer
25 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. ...
0
votes
1answer
14 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 ...
3
votes
0answers
33 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 The board is ...
3
votes
3answers
80 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 ...
-3
votes
0answers
8 views

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

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 ...
0
votes
1answer
21 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. ...
-1
votes
0answers
28 views

Cleaning up Sequential Master Update [on hold]

I'm creating a version of the classic sequential master file update in java. There's some problems with it that I'm trying to clean up. Here's the code: ...
2
votes
3answers
66 views

Printing a monthly calendar on console

This is an implementation of mine to an exercise found in the book Core Java SE 9 for the Impatient. Goal is basically to print a monthly calendar by accepting month and year information from the user....
24
votes
4answers
26k views

Reverse a String in Java

Here is the code for the CString class that I created. ...
3
votes
1answer
50 views

Implementation of generic Graph class and Dijkstras

I participate in competitive programming contests, and I found myself implementing and re-implementing graphs constantly. So I decided to create a reusable implementation of a Graph class, and ...
0
votes
0answers
23 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
14 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
39 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
1answer
54 views

Counting number of pairs in an integer array

So, I wanted to have the count for number of pairs of same integer there are in an array for which I used a HashMap Input contains two lines: Integer n: Signifies the size of input Input ...
4
votes
1answer
90 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: ...
2
votes
1answer
40 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 ...
5
votes
1answer
3k views

“Deal or No Deal” console game

Can anyone check this code of mine for improvements? This was coded using Java with OOP concepts. Game Class ...
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 ...
1
vote
1answer
34 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: <...
-1
votes
2answers
46 views
-1
votes
0answers
20 views

Null Pointer Exception based on HashMap [on hold]

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 ...
-2
votes
0answers
21 views

Calling Salesforce Live Agent API in Java [on hold]

I haven't used the objects in the java.net.* library before. This is all taking place in the run() method of a subclass of ...
4
votes
2answers
71 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: ...
18
votes
6answers
5k views

Vector (physics) implementation

I recently started learning Java, and I decided to implement a basic vector system for another particle system I was building. ...
1
vote
1answer
29 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
26 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
55 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 ...
3
votes
1answer
85 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 ...
-2
votes
0answers
18 views

Shopping List Creation [closed]

For my coding class I have to build a shopping list by having the user enter the number of items they need and then each item (one at a time). I then have to output the final shopping list in a multi-...
0
votes
0answers
33 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 ...
-3
votes
0answers
12 views

Trouble reading and printing content of my text file in Java Main Method [closed]

I have a text file shown below with different input types on a line that I am trying to read accordingly as shown below. I put the text file "Vehicle.txt" shown below directly in the src folder of my ...
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 ...
-4
votes
0answers
37 views

How to do it? in java [closed]

please help me how to change decimal number in string like string 12.345+34.567=46.912 ...
3
votes
1answer
122 views

Hackerrank “Almost Equal” solution

I've spent the best part of a day on this question. It is marked as Expert level. There are about fifteen submission test cases and my solution manages to satisfy the first four. However, from there ...
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 ...
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 ...
3
votes
2answers
75 views

Find the longest sub string of a word after concatenation of given words array

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 longest possible substring composed of ...
2
votes
2answers
46 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 \$\...
2
votes
1answer
46 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 ...
0
votes
1answer
35 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 ...
2
votes
1answer
64 views

Determine whether a word appears in a sentence

Given an array of words representing a sentence and a word to search for, the method must determine whether the word appears in the sentence. Specifications Case insensitive. The arguments are never ...
3
votes
1answer
61 views

Reference service for a cache

I'm using JDK 11. This is my code: ...
-4
votes
0answers
18 views

java variable not expected result [closed]

my code is based on a form in a servlet, issue is with java the bmr is not returning the appropriate answer ...
1
vote
0answers
43 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 ...
14
votes
1answer
75k views

Pong game in Java

I have recently written the following Pong game in Java: Pong class: ...
0
votes
0answers
48 views

Please check my HTTPServlet route parsing extension for quality

Please critique my codebase https://github.com/davidbyng/acme-simple-servlet-extension ...
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: ...
4
votes
1answer
297 views

Simple directory monitoring and processing file on appearance

Currently I am working on some kind of mechanism which will be able to monitor directory and when file with extension .pdf appears I need to mock some kind of ...