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
8
votes
2answers
2k views

Make Depth First Search program more time efficient

This is a problem from programming contest. The original problem can be found here on hackerearth.com. In the first line there is one integer T denoting the number of test cases. Description of T ...
0
votes
0answers
41 views

Is having a collection of predicates on a resource in an interface vs on the resource itself a code style or is there a best practise? [on hold]

I am working on a project using Java 8. I recently came upon this interface that has a number of static methods returning predicates for a class. My first inclination was that it doesn't look right ...
2
votes
1answer
31 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 ...
4
votes
0answers
22 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 ...
7
votes
3answers
411 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
1answer
32 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
5answers
760 views

Award Budget Cuts implementation in Java

PRAMP Award Budget Cuts The awards committee of your alma mater (i.e. your college/university) asked for your assistance with a budget allocation problem they’re facing. Originally, the committee ...
2
votes
0answers
78 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
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. ...
1
vote
2answers
216 views

Android MVVM application architecture

Inspired this guide: https://developer.android.com/jetpack/docs/guide I try to build some app with similar architecture. App interact with remote API via http protocol (json responses from server). ...
1
vote
0answers
29 views

Benchmarking k-shortest path algorithms in Java without JMH

In this post, I have the demo driver that benchmarks two \$k\$-shortest path algorithms. The entire GitHub project is here. net.coderodde.graph.kshortest.Demo <...
-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 ...
5
votes
0answers
53 views

SQLite In-memory Database That Inserts Data Read From a CSV File

I wrote this program to make a simple in-memory database using SQLite and JDBC. Requirements I was trying to accomplish are below. It should consume a CSV file, parse the data, and insert it into the ...
3
votes
2answers
55 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 ...
8
votes
2answers
484 views

Android Tetris App Design

Recently I have finished my first bigger Android project. I made a little Tetris App. Here is a picture of my app in emulator: My Tetris has following functions: fast drop down play tetris music ...
1
vote
0answers
69 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 ...
8
votes
1answer
5k views

Highest pit - only climbing through the pit once

Problem description: A non-empty zero-indexed array A consisting of N integers is given. A pit in this array is any triplet of integers (P, Q, R) such that: 0 ≤ P < Q < R < N; ...
7
votes
5answers
989 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
22 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. ...
1
vote
1answer
56 views

Simple local cache that checks by date else get from db

I'm looking for feedback on how this can be improved. Basically what I'm trying to do is check if the cache has the object, else check from the database. I have a list of ids, then I separate them ...
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. ...
2
votes
0answers
43 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, ...
-2
votes
0answers
34 views

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

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
47 views

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

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
47 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: ...
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 ...
5
votes
4answers
5k views

Simple object oriented console calculator

I'd like to learn OOP. Could someone check my code and tell me how to improve it? ...
4
votes
1answer
79 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 ...
-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
4answers
77 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 ...
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-...
4
votes
2answers
60 views

Thread-safe stack in Java with fixed capacity

Implement a multi-threaded stack, with freedom to use existing implementations of stack. On top of being thread-safe, it must block (not busy-wait) a pushing thread when stack is full and 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 ...
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 ...
-3
votes
0answers
25 views

almostIncreasingSequence CodeSignal [closed]

I have this issue. 35/38 sample tests passed. Execution time limit exceeded on test 36: Program exceeded the execution time limit. Make sure that it completes execution in a few seconds for any ...
6
votes
1answer
6k views

Palindrome using stack

I recently started learning Java, algorithms, and data structures. I am trying to check if a string is palindrome. I would like a review to see where and how I could improve. ...
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
0answers
40 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 ...
15
votes
3answers
14k views

Comparing strings with different newlines

Recently, I was burdened with the task of finding a bug. It turns out the problem was strings from different systems containing different newlines. Comparing two strings with different newlines (but ...
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 ...
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 ...
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 ...
17
votes
2answers
4k views

It's Friday! - 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 ...
6
votes
1answer
499 views

Pretty print a tree

When you're working with trees one of the most useful methods to implement is a clear way to print them, the following is my solution to print a tree in Java: ...
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
1answer
47 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 ...
6
votes
2answers
5k views

Extremely Simple Paint Program in Java

I have written a very basic paint program in java using AWT and Swing. I have separated the program into two different class files; one of them holds the JFrame and ...
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 ...