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.

Filter by
Sorted by
Tagged with
-2
votes
0answers
19 views

To check if no. of occurrence of each alphabet in a string is equal or not(except for once when the no. of occurrence “may” exceed by at most one)? [on hold]

Please refer to this problem from hackerrank. Sherlock considers a string to be valid if all characters of the string appear the same number of times. It is also valid if he can remove just ...
5
votes
0answers
58 views

Evaluating a math expression given in string format

I am currently working on building a calculator using Java and JavaFX to practice my coding skills. I wrote the following methods to evaluate a given expression. What can I improve? Is there ...
4
votes
1answer
35 views

Count all X-shaped bits from 8 integers

I am given 8 positive 32-bit integer numbers. The task is to write program to count all X-bits. X-bits are groups of 9 bits (3 rows x 3 columns) forming the letter "X". task is to count all X-bits ...
2
votes
1answer
38 views

Implementation of Generic Binary Tree Code

I'm in the process of independently learning Generics as a way to build on a college assignment for Binary Search Tree. I've completed this program without Generics first and now I've converted over ...
6
votes
3answers
436 views

Counting multiples of 3 up to a given number

I'm attempting a practice problem in Codeforces that requires you to find the number of multiples of 3 less than or equal to a given number. I have written the following code but it gives a TLE once ...
-4
votes
0answers
22 views

I need to show if a triangle is a right triangle, using a boolean with three in-command arguments in java [on hold]

When I go to import numbers, it says some numbers are false when they should be true or viseversa. For example, when I put in -3, 4, -5 it comes out as true when it should be false. ...
-3
votes
0answers
22 views

What is the exact alternative of rand() % vector.size() in c++ to java [on hold]

I am facing difficulties of converting rand() % TDx.size() in c++ to java. I convert this as ...
3
votes
2answers
61 views

Finding unpaired number in an odd Array of integers

A non-empty array A consisting of N integers is given. The array contains an odd number of elements, and each element of the array can be paired with another element that has the same value, except ...
1
vote
0answers
73 views

Object-oriented calculator

I have solved an assignment (Exercise 3) from the MOOC Object-Oriented programming with Java, part II, but I'm not enrolled in said course. Assignment Summary: Make a simple calculator. You ...
2
votes
0answers
23 views

Java file transfer through sockets

I am making a program that transfers files from one client to another. Right now I am just working on sending the file to the server and then later I will work on transferring it to the other client. ...
2
votes
0answers
44 views

JAVA Shopping Cart Design

Recently, I have appeared for coding exercise to design the Shopping Cart which should have following features: handles barcoded (like Chips) and non-barcoded item (like Banana 400gm) Can add item, ...
0
votes
1answer
54 views

Bowling Kata in Java

I am sharing my Bowling Game Score Kata made in Java, it is available for whoever wants to code review it. I appreciate any comments. ...
7
votes
5answers
998 views

Finding all possible pairs of square numbers in an array

I am writing a program that allows me to find all possible pairs of square numbers including duplicates. We can also assume the array elements to be of positive integers only. e.g an array of {5,25,3,...
-2
votes
0answers
34 views

Building a Vehicle object from Excel data using Apache POI [closed]

I have the following code which is working but I am not satisfied with it and it seems like an ugly hack. NppColumn is an enum which contains the column indexes. The problem is when a POI row cannot ...
1
vote
0answers
48 views

Making text based Blackjack game in Java. Can't figure out how to deal with Ace(1/11) and Splitting [closed]

I've been learning java for about a year in University and decided to start this Blackjack game which I can hopefully animate into a full app in the future, although I'm still working on the ...
-3
votes
0answers
48 views

Are there any ways to reduce the complexity of the following java code? [closed]

I need to reduce the following Java method's complexity to an acceptable level according to Sonar. At the moment, it gives this Sonar issue: Here is the code: ...
2
votes
1answer
85 views

Create Node tree from list of paths

I have this list of paths: ...
-2
votes
0answers
20 views

Runtime Error with Check Balanced Brackets Problem [Java 8] [closed]

I am struggling with a HackerRank problem. Here is the problem statement: Given strings of brackets, determine whether each sequence of brackets is balanced. If a string is balanced, return YES. ...
3
votes
1answer
47 views

Pycharm plugin for imports cleaning

I have written Pycharm plugin for integrating pycharm with tidyimports. I have followed steps mentioned in Simple Pycharm Plugin Example. Below is the code that I have written, it works but I need ...
4
votes
1answer
80 views

Random password generator (Java)

I wrote this program recently to generate random passwords for myself. It works well but it's been a long time since I wrote any java and am just looking on ways to clean up the code. I'm also not ...
1
vote
0answers
21 views

Segmented (Bit) Sieve of Eratosthenes in Java

I am trying to create an efficient implementation of the segmented sieve of Eratosthenes in Java, similiar to the one in C found here: https://github.com/kimwalisch/primesieve/wiki/Segmented-sieve-of-...
2
votes
1answer
38 views

Finding the number of times the code will generate an alert depending upon whether the transaction is fraudulent

Please refer to this problem from Hackerrank HackerLand National Bank has a simple policy for warning clients about possible fraudulent account activity. If the amount spent by a client on a ...
-1
votes
1answer
21 views

Optional transformation of list with 1 item [closed]

I'm creating a method that returns an (Optional) value, only if there's 1 String in a List<String>. If there is exactly one element in the list, and it ...
3
votes
4answers
79 views

Java program to manage animal data and store them in text files

I made this program as a baby step to creating an animal shelter management system that will be used in a real life animal shelter. The goal is to move from text files to an online database, and from ...
2
votes
0answers
41 views

Java Perlin noise implementation

I've decided to code Perlin noise generator in Java. It works pretty well, I just want to know If I am doing everything right and if it is a valid implementation! PS : The ...
1
vote
0answers
41 views

Remediation for security vulnerability due to storing sensitive information in strings

Security assessment of our codebase reported the following vulnerability - Vulnerability Description The method x() in xyz.java stores sensitive data in a String object, making it ...
5
votes
2answers
92 views

Java program to detect the Java class File Format magic number, in a given file

Description: I wrote a Java program that checks whether the content of the given file begins with the Java class File Format magic number 0xCAFEBABE, in big-endian ...
2
votes
1answer
47 views

Find the number of all specific substrings in a string

I would like to ask a code review regarding a concrete exercise. Let's suppose I have to get the number of all specific substrings in a string. We call something specific if any of these conditions ...
0
votes
1answer
66 views

One try with multiple catch blocks vs nested try

I am creating program which will parse .csv file and I am using FileReader and Scanner classes from java API. ...
-2
votes
1answer
52 views

Bodyless Self-Closing *for* Loop [closed]

I use self-closing bodyless for loop to quickly find an element within an array or collection. Learned it from a Java teacher. But I'm seeing warnings on certain IDEs that have a code inspection tool. ...
1
vote
2answers
69 views

Simple subnet calculator and parser

I have started to learn Java for the past 20 days with no prior coding/comp science experience. My brother gave me an idea to make a subnet calc/ping tool to enhance my knowledge and mentored through ...
1
vote
1answer
53 views

HackerRank Code “Determining DNA Health”

I am working on this problem: https://www.hackerrank.com/challenges/determining-dna-health/problem passing some test cases and time-out on others (no wrong answers). The code is here: ...
3
votes
2answers
223 views

Calculate the largest palindromic number from the product of two 6-digit numbers (100000 to 999999)

Are there any efficient ways to solve this problem, for example using bitwise operator? ...
3
votes
0answers
50 views

Rest API in a trimmed model

I practiced my Java knowledge in the last couple of days. For that, I want to create a Rest API in a trimmed scale, because there a lot of aspects which must be considered in such an API (Login, ...
3
votes
0answers
94 views

Java implementation of Spider Solitaire

I recently cloned a classical Spider Solitaire game from Microsoft Windows XP. I implemented almost all features of the game. Please tell me anything I can do in order to improve my coding style. ...
2
votes
1answer
65 views

Kruskal MST algorithm

I came up with the following code by following Prof. Sedgewick's lecture on Coursera. Please review this code and let me know if there is anything that I got wrong in implementing Kruskal's ...
3
votes
2answers
101 views

Calculate total water drunk in a day

I would like to know how I might improve my code? I just started coding and liking it a few days ago so I am quite new to this whole world... The objective is to calculate the amount of water one has ...
7
votes
5answers
181 views

String combinations of 0 and 1

I was asked this question in an interview: Given a string s consisting of 0, 1 and ...
1
vote
0answers
34 views

Lightweight, modular Discord bot - tips and feedback on the code?

The full project is up on GitHub. The codebase is super small as it stands. I'm brand new to reactive programming and Spring, and would mostly like insight on those two things. Asynchronous ...
2
votes
2answers
79 views

Find all local maxima in a one-dimensional array

I implemented the following class (it works) and I just want to hear your opinions about best practices and what can be improved. The idea was to do it using mostly arrays. The class just finds the ...
5
votes
2answers
188 views

Is it worth to use if-else statement as Java optional pattern?

I came to a point while refactoring using if {} else {} code with Java optionals. While optimizing code it turned to a result to this: ...
1
vote
1answer
59 views

Using enum for singleton implementations to choose way of doing something

I have this service that reads emails from a mailbox as they come and I want to extract its contents in a map structure. For now I am interested only in the actual email (no images or attachments). I ...
1
vote
1answer
48 views

TCP server in Android to continuously listen to an RFID reader

I have created a TCP server thread which I want to keep running and listening to the IOT device (an RFID reader). I have only one client. Please review my code and provide your feedback. Are there ...
1
vote
1answer
46 views

What are the downsides of my Mergesort implementation?

Could I ask you to evaluate my implementation of mergesort? I think that it's consistent with \$\mathcal{O}(n \log n)\$ complexity but has a downside that I create a new ...
1
vote
1answer
55 views

Animation of adding / removing nodes from VBox

Method hide_old_show_new (I can't think of a suitable name) gradually, using FadeTransition, removes all nodes (from last to ...
2
votes
0answers
80 views

Improving rendering performance of 3D Voxel Game

Improving rendering performance of 3D Voxel Game Technical features added: Perlin Noise Generator 3D Explorable World (You can't break or place blocks) Free camera, you can fly and go through blocks ...
4
votes
2answers
351 views

Unisex Bathroom problem without semaphore

Could I ask you to evaluate my solution to Unisex Bathroom Problem? Problem description An office has a bathroom that can be used by both men and women, but not both at the same time. If a man is ...
1
vote
1answer
99 views

Light Security Local-Machine Password Encryption

I have a program that makes a call to an SQL database. I cannot use SSH to connect to it (as far as I am aware) or any other more secure method, so Java's SQL connector was used. As the connection ...
2
votes
1answer
55 views

An adventure game

So as you will soon be able to tell, I am very new to this programming. But I thought that the best way to learn would be to just jump on in and create my own game. Was wondering what things I should ...
3
votes
1answer
98 views

Invoking thread for each item in list simultaneously and returning value in Java

I made a wrapper for an API that I am using, basically what I'm doing is sending in a list of Series objects and for each item in the list, a thread ("worker"?) ...