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
-4
votes
0answers
18 views

Which of the following methods is declared incorrectly?

Which of the following methods is declared incorrectly? ...
2
votes
0answers
43 views

No hardcoded path

Since i develop in Java, i got into the habit of not putting hardcoded text in my code. For paths to files and folders I use the code below. I did it in a way that it was easy to set up and quick to ...
1
vote
1answer
51 views

JTextPane with line-numbers

What I wanted to do As part of a larger project, I needed a simple text editor with line numbers. The editor should also be able to highlight the current line (line number in bold) and define the tab ...
3
votes
2answers
67 views

I made basketball program using Java that runs on console

I made a simple console basketball game using Java. ...
-2
votes
0answers
32 views

Very Simple JavaFX Calculator

I am a mere beginner in java, with just two months spent with it. I finally made a calculator, which do simple calculations. I used Javafx with FXML to build it. It has a calculator class, by what I ...
1
vote
0answers
12 views

Find Invalid User Relationships in User to Manager Map (validate map as valid tree structure with no circular relationships)

We have a new service where an admin can upload a spreadsheet of new users they want to add to our application. During our processing we make a union map of all the users both existing and new ...
2
votes
1answer
113 views

Prime factorisation in java

I came across this question in a coding contest (Java-restricted) and I got TLE. I am unable to provide the link of the question as the contest is closed now. Can I know how can I optimise this? Four ...
2
votes
0answers
43 views

Count unique subsequences

I came across this question in a coding competition (Java-restricted) and I got a time-length-exceeded. I am unable to provide a link as the contest is closed now. Can I know how can I optimise this? ...
0
votes
0answers
48 views

Is this good OOP design for Producer Consumer?

The idea is to have consumer-producer solution that writes timestamps to db in strictly chronological order. In case the connection to db was lost, try to reconnect every 5sec. Does this code github....
2
votes
1answer
51 views

I made a Java quiz program

I made a Java quiz program. The program will let you take the Java quiz and then display the quiz's result according to your score. ...
3
votes
2answers
66 views

Java insertion sort implementation

I have written code for insertion sort. I just want some feedback whether the above implementation is correct and can be improved. ...
-1
votes
1answer
76 views

How can I optimise my code with BufferedInputStream

Suppose I have an InputStream that contains text data, and I want to detect all words and their numLine. I reach for every word ...
1
vote
0answers
36 views

Webscraping tennis data 1.2: Optionals, Streams, Callbacks(?)

Through my previous questions, I developed a web-scraper that gets tennis ranking data. Webscraping tennis data: major refactor of code style and program modularity Webscraping tennis data 1.1: ...
-3
votes
1answer
56 views

Return reversed integer - Java [closed]

The question is from Leetcode. Given a 32-bit signed integer, reverse digits of an integer. ...
1
vote
0answers
44 views

Simple proof-of-work (based on HashCash)

I'm trying to build a simple (yet effective) brute-force protection for my App-API. The client requests an identity - the server supplies a random string (called ...
2
votes
2answers
711 views

Custom Thread Pool - Reusing non-busy threads

This is an exercise in thread pooling in which I attempt (hopefully in a successful manner) to reuse existing threads (much like Java's own ...
3
votes
3answers
73 views

Ensuring threads running infinite loops are terminated before exiting the program

As a hobbyist programmer, I gain knowledge where I can find it from google searches. I tend to write code that utilizes threads that have infinite loops using while loops, where the while condition ...
4
votes
3answers
97 views

Hotel booking with multiple options. Improvement through subclasses?

The code below runs perfectly fine as I want it to. I'd like to create more subclasses to get a better overview over the whole code. Can I place the setter and getter as well as the methods into the ...
1
vote
1answer
8k views

Compare large text File in java line by line

Dear fellow developers I am doing a java program which compare two text files line by line, first text file has 99,000 lines and the other file has 1,15,000 lines. I want to read the files and compare ...
1
vote
2answers
99 views

Determine if the student has passing grades

I made a program in Java that asks for the student's name, course, and grades. After the required text inputs are filled, the program will then show the result. If the student passed, the program will ...
2
votes
1answer
695 views

Implementing an HotelManager interface in Java

Got a mission to implement an Hotel Manager interface. I will post the interface and the attached class Reservation, and will add my code. What I am asking you is ...
0
votes
0answers
55 views

Can I replace instanceof if I cannot use a common interface (third pary API)?

I'm using Telegram API and I've different methods wich returns different type of information like this: ...
0
votes
1answer
74 views

Implementing a singly linked list with empty list represented as null

I've implemented a singly linked list in Java and would like a code review as I am still learning and this is a different method I've found to do this. The logic is still fuzzy as well to me and ...
3
votes
2answers
63 views

Set default value for remaining size of list by use of Java 8 and Stream

I have written a method which will return the size 16 List every time. If the input List has size less than 16, the remaining list object will be filled with default values.  Is there any way to ...
5
votes
2answers
71 views

Sorting squares of an integer array

I had this question in an interview recently. Given a sorted array of integers, return a list of those integers squared, with the squares sorted. So given an array of these numbers: ...
-1
votes
3answers
111 views

Fastest way to create random pixel image

I want to create a very big gigantic PNG image. The image pixel are generated randomly, being How can I improve the below code to create a fast random pixel image in java? ...
4
votes
1answer
244 views

Java Temperature Converter

I have made a program that converts Celsius to Fahrenheit and Fahrenheit to Celsius. How is my code? ...
-2
votes
1answer
79 views

Programming challenge - report fraudulent banking activity times out

How can I optimise this code there is time out error Program Challenge: HackerLand National Bank has a simple policy for warning clients about possible fraudulent account activity. If the amount ...
4
votes
1answer
76 views

Bank with factory method for accounts, multithreaded deposit and withdraw

I have a couple questions about this program Should I implement runnable instead of using thread class? I like the idea of the consumer and producer being thread objects, it seems simpler to me, but ...
14
votes
3answers
5k views
5
votes
3answers
5k views

Simple Java addition calculator

I made this simple addition calculator in Java and I'm wondering how I can improve it. ...
3
votes
0answers
44 views

Traversing a binary tree using a Node interface and an abstract Traverser class using a strategy pattern for order

I have written this code for depth first tree traversals. It feels like a lot of boilerplate, and I want to refactor it to remove this boilerplate. However I haven't done a lot of refactoring before, ...
4
votes
1answer
58 views

Calculator console app in Java

Here is my source code for my very first app in Java. I am completely new to the language; any help and criticism is welcomed! ...
3
votes
3answers
4k views

Game of Life (Java)

This is a simple implementation of Conway's Game of Life in Java. The algorithm I use is inefficient however. Every Cell's neighbors (alive or dead) are checked on every iteration. ...
15
votes
2answers
2k views

A button, as a “Clean Architecture” plugin

You can call it ports and adapters or hexagonal architecture. Regardless, what's facinated me about this picture isn't the layers. It's the Clean Architecture UML diagram over in the corner of a ...
2
votes
1answer
2k views

Simple Banking application in Spring boot, JPA, REST where balance can be transferred among predefined accounts and transaction history retrievable

I want to create a very simple banking application where (i) predefined accounts with a positive balance can send money (ii) requesting balance and a list of transactions can be found. I have ...
3
votes
1answer
2k views

Minesweeper JavaFX app

This is my Minesweeper JavaFx app. It is working without any weird bugs, at least none that I found. I am not too concerned about the way it looks either, the main reason I post this here is to get an ...
0
votes
0answers
39 views

Retrieving and filtering DB entries

I have a class which I created it contains static factory methods for, retrieving and filtering DB entities. Could you give me some tips on how this can be converted to a singleton class? So that it ...
2
votes
1answer
44 views

Checking inactivity with periodic tasks in Java

I have created a simple HealthCheck service. I have two approaches: Create a task canceling the previous one if the system is active, rescheduling the new task. Create a periodic task and regularly ...
4
votes
2answers
85 views

Enhanced Hashmap - Add a number to all keys/values

I had the below problem in a coding test and I got 28/30 tests passes and 2 failed due to a time-out. Problem You have created a programming language and now you have decided to add ...
2
votes
1answer
53 views

Simple Playlist Editor/Player

I am starting with Java and at the beginning I would like someone to catch what mistakes I make. I would like my code to look its best and I want to learn good Java writing habits. Could anyone ...
6
votes
4answers
10k views

Finding the longest sequence of positive numbers in integer array

I am preparing for a coding interview and I have the following questions: Find the biggest positive number sequence in the Integer Array. If Input is ...
3
votes
1answer
195 views

Meme (title with picture) exchanger

Project structure without code: Packages: Classes in packages: In ConfigConstants I store path to folder, where I save pictures. Also in ...
3
votes
2answers
78 views

Java Reflection-based CSV Parser

I'm an experienced Java developer, however I don't have experience with reflection or Annotation classes. For fun, I tried to develop a CSV Reader class which can parse each row into a particular type....
3
votes
2answers
68 views

Tic-Tac-Toe in Java

I am currently learning Java; I could really use some help from more experienced programmers. How can I clean up my Tic-Tac-Toe code? What mistakes have I made? Can I use more exception handling? I ...
7
votes
4answers
2k views

If/else produce code duplication

I have the following class: ...
1
vote
1answer
36 views

Renaming and deleting video file

I am using below code to rename and delete video. Need review for the following: Code optimization Performance Overall code review ...
2
votes
1answer
65 views

LeetCode 146: LRU Cache III

I'm posting my Java code for LeetCode's LRU Cache. If you have time and would like to review, please do so. Thank you! Problem Design and implement a data structure for Least Recently Used (LRU) ...
3
votes
1answer
87 views

Hackerrank problem: Climbing the Leaderboard (Java)

I am solving the following Hackerrank problem: Climbing the Leaderboard. The problem statement: Alice is playing an arcade game and wants to climb to the top of the leaderboard and wants to track her ...
2
votes
1answer
40 views

Reviewing the file download controller in spring rest

In my project, so this controller is working perfectly, my objective is to read the log file from the server which is created on daily basis, so I have to read the log file which is heavier in size ...

1
2 3 4 5
202