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
1
vote
0answers
40 views

Flatten nested lists in Java

I'm developing a complex app with Spring Boot and MongoDB. I have a Video class like the following. Note: All getters setters are omitted. ...
0
votes
1answer
37 views

Encasing a string in double quotes

I need to add some characters to a String before using it for an API call. The idea is to add a " char both at the beginning and at the end of the String, to make ...
4
votes
2answers
146 views

Java: Conway's Game of Life

I have just finished implementing a version of Conway's Game of Life using Java. Being only a college student, I am sure that my code is no where near perfect, and was wondering if you could look at ...
-1
votes
0answers
20 views

Sorted Doubly Linked List with Comparable [closed]

I'm trying to create a Sorted Doubly Linked List with an Insert and Remove function. I've managed to create the Insert function, but I'm struggling to figure out how to remove elements. Also, I want ...
5
votes
2answers
173 views

Fleissner-Grille / Turning-Grille

Background About the Fleissner-Grille The Fleissner-Grille is a really easy possibility to encrypt text. You just have to take a grid of size n*n with (n*n)/4 holes (example). You then just write ...
2
votes
0answers
42 views

Generic Graph Traverser

I have built this Generic Graph traverser, I have this implemented with DFS, I feel it will work equally fine with BFS too. What do you think of this implementation? I want help in reviewing the <...
3
votes
1answer
47 views

command-line demo app

I started learning from the book: head first design patterns. As I am trying out different programs in the book, I am compiling them in this one demo app. Below is the code for its driver function. ...
4
votes
2answers
68 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: ...
4
votes
3answers
201 views

Student Grade Calculation

Develop a smart application as Student Grade Calculator(SGC). Create a class Student with following private attribute : int id, ...
2
votes
1answer
54 views

Graph coloring in Java

I'm solving the m-coloring problem using java. and I have following code that uses concept of recursion and backtracking. ...
1
vote
1answer
58 views

Feedback on ArrayList using OOPs

Please review my code for the problem statement below. Many Thanks. You job is to create a simple banking application. There should be a Bank class: It should have an ...
3
votes
2answers
500 views

Time and Space Complexity of Prime factorization

I have written a function that prints all the prime factors for a given number. Here is my code ...
2
votes
0answers
46 views

Random generation java logic used in Nifi [closed]

I was just reviewing the source code of Nifi, see explanation and public version of the source. This got me wondering whether there are any obvious improvements here to increase the performance of the ...
1
vote
2answers
73 views

number of items that can be prepared with given ingredients

Find the limit to the number of items that can be prepared with given amount of ingredients - Let's try to understand with input/output pattern: Input ...
2
votes
1answer
67 views

Max sum of abs difference in array

I am just trying to understand the algorithm of the problem statement Given an array, we need to find the maximum sum of absolute difference of any permutation of the given array. Here is my ...
11
votes
2answers
299 views

Stack Overflow clone

I have to write a simple web application using the Java Spring framework as my course project. So I decided to write a simple Stack Overflow clone. My application has the following features: ...
4
votes
2answers
64 views

Performance Enhancement of A Star Path Finder algorithm with 1024 multidimentional array

I have the below code for a A* pathfinder, however it is taking upwards of 10 minutes to find a solution using a simple 1024 x 1024 array. I had to comment out ...
2
votes
1answer
72 views

Listing words from text, provide lines where appears, count them

I applied for Junior Java Developer in some company. Got a task:"Listing words (without duplicates) from text, provide lines where appears, count them." Output should looks like: Alphacoronavirus - 3 ...
1
vote
1answer
101 views

Sudoku-Solver with GUI - follow-up

Background A few months ago, I asked this and this question on my implementation of a Sudoku-Solver. I now tried to further improve this little project. Changes Minor GUI-changes Input validation "...
1
vote
0answers
24 views

Designing a public facing Java interface for future extensibility (API evolution)

I develop an in-house Java framework. I provide an interface so that my end users can provide their own custom implementation (i.e. plugin/SPI). ...
0
votes
0answers
32 views

Lags caused by bad Game Loop

I need help fixing my gameloop. Sometimes the game feels very laggy and I think the reason is that the tick() method is called slower then the render() method. What I want is that update is called as ...
1
vote
2answers
54 views

Scraping news articles from various pages

Scraping news articles from various web page is the main goal of this code. For starting all spiders(web crawlers) at the same time, I try to implement the facade design pattern. It works but I feel ...
0
votes
2answers
82 views

Architecture and error handling in simple java program

I'm trying to get my basic coding principles right but there's still a long way to go. This is an exercise for CodeGym. They logic itself isn't very hard and I passed the exercise easily but I'd like ...
1
vote
1answer
38 views

Writing a for loop to build a String using Streams

I have the following code which works. Been trying to write it in Java 8 streams to make it more readable but unable to get my head around it. Looking for any feedback to make it more readable. Thanks....
1
vote
2answers
43 views

List with object and index filtering out the object depends upon the index present at list

I have a following list which indicates the indexes. List<Integer> integerList = Arrays.asList(1, 3, 5, 6); // index I have the following collection of ...
1
vote
1answer
49 views

DnD-like Fight (Single Round)

Let's Fight: one Entity can perform an attack (thus making him an attacker) on another Entity (defender). This follows some ...
1
vote
3answers
154 views

First Code, But I Feel It Is So Ugly, Can You Explain Why?

Question:- Why is this code so ugly ?? This is my first code, it is working fine, but I feel it doesn't looks as standard code … I am still studying java through youtube, as I have just completed two ...
2
votes
0answers
41 views

Is it bad practice to update Graphics in Swing outside of paintComponent like this?

I'm currently implementing a Minesweeper clone in Java using Swing. Rather than updating the tiles like so ...
5
votes
1answer
90 views

Sort Characters By Frequency Java

For context, I worked on the LeetCode May 2020 Challenge Week 3 Day 1. The challenge was described as this: Given a string, sort it in decreasing order based on the frequency of characters. ...
1
vote
1answer
96 views

Exporting Stock Transaction Data to Excel

I am looking for improvements in the code below which is taking a long time to finish. Initially when I export around 26k+ records, it will take around 20-30 mins to finish. Usually then either the ...
2
votes
0answers
57 views

Fibonacci Heap Implementation In Java

From my repository. This is my first time implementing a Fibonacci Heap, and since it's pretty complicated (at least to me), I would like to check if it is all correct. ...
4
votes
3answers
120 views

How can I optimize my code that uses nested for loops?

I am working to solve a problem where I need to determine if a Point lies on a line connecting two other Points. For example, ...
2
votes
1answer
44 views

Java multithreaded withdrawal and deposit banking

i'm exercising Java multithreading on an example of simple banking funcions. The programm is able to perform multiple transactions at once on different threads.All accounts transfer money to the ...
-3
votes
1answer
61 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 ...
0
votes
2answers
52 views

Return a 404 when a resource is not found in Spring Boot

I wrote this code in order to return a http status of not found to my users in case the resource is not present in the DB. ...
0
votes
0answers
33 views

Run non overlapped periodical tasks on user specified executor

I have concurrency tasks in my module: user code is able to instantiate my object and specify Executor service, then user can submit requests to this object which ...
1
vote
1answer
60 views

Hash table in Java with arrays and linear probing

I did some manual tests by instantiating the class and it seems to be working okay. I wanted some feedback on the following: Is the code well structured? I notice I have a lot of redundancy. The ...
2
votes
2answers
55 views

Universally unique 64 bit long generator

I'm trying to make an ID generator that generates 64 bit longs. The IDs should be globally unique even between two offline machines. This is the same idea as UUID (GUID), but UUID is 128 bit long and ...
1
vote
1answer
105 views

Generating all variations of M*N matrix containing boolean values

I've implemented an algorithm that generates all variations of a matrix of size \$M*N\$. My approach is that I see a matrix as a list where the position of elements can be calculated from the position ...
2
votes
1answer
60 views

Constructing House using OOP

I am new to programming and I have tried to recreate below lines into OOP's code. Please review and provide comments. House has Rooms.Rooms are drawing room, bed room, bathroom etc.Each room has ...
4
votes
4answers
202 views

LeetCode: Roman to Integer in Java

I tried solve this easy leetcode challenge in java. Challenge link Here is my solution ...
1
vote
0answers
17 views

regex on a log file utilizing stacks and queue's in Java

This would be for a MUD client, which has elements of a sort of telnet bot. Here, there's ...
2
votes
0answers
305 views

My Java matrix multiply code single thread faster than multithreading, any mistakes?

I'm implementing the matrix multiply function using Java's multithreading. Below is my code: So I first tried the normal single threaded approach, then tried the ExecutorService approach, I don't know ...
1
vote
4answers
80 views

Java Fluent Wrapper [closed]

My gut tells me this is poor practice, so, I thought I would ask for some feedback. The goal here is to fake a fluent API design for any class without using reflection while keeping it as pretty as ...
2
votes
2answers
90 views

List Filtering Code

I am developing applications for android. In my application, the user can add information about his weight and watch the progress of weight change. I decided to add filtering of the elements according ...
1
vote
1answer
52 views

Reusing multiple switch cases and if-else statements [closed]

I am creating a 2D text-based Drawing Application which can draw basic shapes like Line, Rectangle, Triangle, Circle, Oval. The Line can be drawn in eight directions on a 2D plane and can be moved by ...
2
votes
2answers
61 views

(Java) Read .txt and organize activities for hours / minutes

Doubts in logic to generate the output file according to the example I need that even if he reaches the total_min <720 condition he continues to travel the lines. 720 is the total number of minutes ...
2
votes
1answer
36 views

Example using Object lock synchronized blocks

Here's my attempt at trying to understand synchronized() blocks using an Object lock, using wait() and ...
4
votes
2answers
99 views

Sanity check a simple RPG character

I'm writing an assistant for the tabletop RPG Pathfinder in Java. I intend to use the MVVM pattern using JavaFX, possibly through mvvmFX. Before I go into the V-VM phase, I have built a first ...