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
3answers
380 views

Switch case implementation in Java for an integer pair combination

I have following Python code: ...
3
votes
1answer
71 views

Inserting 50k rows with Spring Data and JPA [closed]

I am using Spring Data JPA with Spring boot application. My requirement is to insert 50K rows in JPA entity table in one hour or less. I have 3 entities A, B and C. Entity A has a one to many ...
1
vote
2answers
38 views

Listing ordered components, recursively

I am trying to get ordered components of an interface properly without having a local variable orderedComponents outside, and here is my current code. Reason is because orderedComponents will be in ...
0
votes
5answers
85 views

Make repeating numbers 0 and putting them at the beginning of array

I am new to programming and I have made a program to make all repeating numbers in an array 0 and put those all 0s in left side: ...
3
votes
1answer
77 views

Counting subtrees where all nodes have the same value

A unival tree (which stands for "universal value") is a tree where all nodes under it have the same value. Given the root to a binary tree, count the number of unival subtrees. For example,...
3
votes
3answers
105 views

A more functional try…catch construct in Java

I saw a question on Stack Overflow asking for a review of a custom try...catch construct that made use of Optionals, and got the idea to try writing my own version. ...
5
votes
2answers
253 views

User input happy birthday program

For self-study homework I made a Java program that takes user input, creates people as objects, and says "Happy Birthday" to each person. I am just wondering what mistakes I made here or how it could ...
-1
votes
1answer
52 views

Reverse String in Java

I've been revamping on my coding puzzles practices. What is the complexity (both time and space) for this method: ...
5
votes
5answers
712 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 ...
10
votes
2answers
794 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
35 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, ...
1
vote
1answer
74 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
16 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
81 views

A Java Calculator that could perform basic Mathematical Operations [closed]

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 ...
3
votes
1answer
113 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 ...
4
votes
1answer
57 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
986 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
111 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
228 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 ...
2
votes
1answer
53 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
49 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
178 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
46 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
71 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
31 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 ...
3
votes
1answer
47 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 ...
3
votes
3answers
105 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
58 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
38 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
62 views

Refactor multiple if statements while creating object [closed]

I've got a class with few fields: ...
4
votes
1answer
134 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
35 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
2answers
56 views

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
102 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
128 views

Printing out a table in console

This program prints out a table in the console. Suggestions for improvements are welcome. Example output ...
1
vote
2answers
35 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 ...
2
votes
2answers
42 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
55 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
55 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
43 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
65 views

Reference service for a cache

I'm using JDK 11. This is my code: ...
1
vote
0answers
75 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
55 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
129 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
65 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: ...
0
votes
1answer
42 views

Usage of static block vs. direct static variable initialization [closed]

Suppose, I have a data access layer class, where I want to specify database connection parameters. Usually, I do it as static variables and initialize it right after definition, e.g. see ...
4
votes
1answer
302 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 ...
2
votes
1answer
49 views

split items of batch into multiple categories

I have a batch job that contains a lot of items. I need to split these items into 4 categories - 1,2 category should be moved to a separate jobs as is; ...
1
vote
2answers
128 views

Item class/system for RPG/DND type game

Thanks for the enormous response on my last question! I've returned with another question, hoping for more insight. I'm developing an Item class and system, and I ...