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

How do I simplify the following code which solves the attached challenge? [closed]

I recently downloaded an app called "SoloLearn" to improve my coding skills as I am a beginner with Java while I am not at home. Today I solved the following challenge: Everything worked but I have a ...
4
votes
1answer
103 views

Codility Fish (queue) programming challenge

Today I have attempted a Codility exercise "Fish" (https://app.codility.com/programmers/lessons/7-stacks_and_queues/fish/), and I have to say I found it to be: 1) Not necessarily "easy" as implied by ...
9
votes
4answers
951 views

Building string with max length

I need to run a evaluation for large (1 Million) number of components and build a string with error which has comma separated error codes. As the final string is to be persisted in RDBMS TABLE.COLUMN ...
2
votes
1answer
81 views

Optimizing minHeap implementation

I have implemented a java class for minHeap but it is not working as fast as I want . I want some help to change it to work faster in insertion or deleting the minimum node. Here is my implementation:...
2
votes
1answer
137 views

Optimizing a Partition Method

I am looking for assistance in optimizing a partition method I wrote for a class. It does its job correctly, but I only received half points on it, so I was wondering if there was a way to make it ...
3
votes
2answers
69 views

Digit sum loops+random positive number generator

I have to prepare program that summing the digits of two given by user numbers and then give back the random number which is natural number the digit sum of this number is bigger then the digit sum ...
3
votes
1answer
71 views

Discount card reduction calculator

I have started programming a couple of months ago and have recently applied for an internship. One of the assignments was to create a console application, the assignment can be seen here - > HERE My ...
2
votes
2answers
129 views

“Smart” sudoku brute-forcer

After running my C-brute-forcer for two days on a 25x25 sudoku, I decided to re-write in Java so that it would solve it in an acceptable time frame. The idea: Make smart fields that contain all ...
3
votes
2answers
286 views

LeetCode: Longest String Chain (Java)

For the question, I had a pretty messy solution so I would like some advice on how to better use Java to make the code a bit cleaner. Also, a semi-hack that I did that I'm not proud of is checking if <...
2
votes
1answer
132 views

Java Cryptography AES/GCM/NoPadding without IV

I'm implementing a PAKE-protocol as a university project and one step of the protocol involves sending encrypted data from a key created via a hash function (I'm using SHA-256). I want to use AES/GCM ...
4
votes
3answers
121 views

A simple Java login system

I created a simple log-in system in Java for a project. Security isn't a concern here, hence the plaintext password, but I'm interested in how I can improve the quality of my code. Everything seems to ...
3
votes
3answers
137 views

Deleting three consecutive numbers in an array

I am a beginner in programming, started about 2 months ago with Java, changing careers from law. I have recently applied for an internship but was denied because I failed to do the pre-interview test ...
1
vote
3answers
132 views

Spring boot application web service

It's a web application. It should provide a service for entering data. Data is then evaluated and uses itself another service. It was part of an interview process where I was given that task to solve....
9
votes
5answers
3k views

Palindrome checker program

I've been studying Java for some days and I'm just now starting to make some simple programs, I'd like to know if there's any 'noob' mistakes or habits that I could avoid. In other words: how could ...
2
votes
0answers
58 views

Parsing a Graph To Convert It Into Adjacency Lists And CSR And Then Make Connection Queries Using Bidirectional BFS

I was assigned an university project where I had to parse directed graph files coming from SNAP and then convert them into CSR (Compressed Sparse Row) format. Then the client must have the ability to ...
6
votes
3answers
989 views

Supermarket Product Inventory Management with Polymorphic Product Types

The following method is used to add objects to a polymorphic ArrayList from a file. It reads lines from the file, and based on a specific line which denotes the ...
2
votes
0answers
56 views

Construction of external sorts from comparison ones

Here's an example how to construct an external sorting algorithm from the Quicksort. The method may be applicable to other known internal comparison sort algorithms. I have checked that it shows N*...
4
votes
2answers
210 views

How can this code for applying filters to data by date and size be improved?

I am going to undergo a code review shortly at work. I feel that my code is too verbose, could log more sensibly, and I feel that my if/else statements are somewhat duplicative/repetitive and can be ...
2
votes
2answers
98 views

Is this a reasonable algorithm for shuffling cards?

So I based my "algorithm" on the poke method defined by Persi Diaconis. You start with the card at the bottom of a given deck and then poke the top card into a random position in the deck. At first ...
0
votes
1answer
56 views

Compare two map objects and show relative information Java 8

I have 2 maps. First map consists of order in which a specific set of services is executed. Second map contains execution time each service took. I need to display this information. Following is my ...
5
votes
2answers
161 views

HackerRank: Friend Circles (DFS in Java)

I got this problem on a HackerRank challenge and this was the best I could come up with. It's basically just using DFS to find connected components (in this case, friend circles). I was having a tough ...
1
vote
2answers
92 views

Binary tree pruning with BFS

Below the text of the exercise: We are given the head node root of a binary tree, where additionally every node's value is either a 0 or a 1. Return the same tree where every subtree (of the ...
-3
votes
2answers
69 views

Naming insecurity [closed]

I'm having trouble with proper naming. That issue appears when i try to apply to first class collection to my class and use sonar as well: ...
0
votes
0answers
71 views

Is it a good idea to implement Spring GrantedAuthority in UserRole Model?

I am trying to implement an authentication via Spring Security. In all tutorials people build a List of GrantedAuthority records from the List of ...
7
votes
4answers
2k views

Simplifying constructing native SQL query with nested if-else's

I've a method which is used to build a native sql query. I've 4 String builder as input and based on different conditions, I need to build my query. Here is the code ...
4
votes
1answer
168 views

Securely hash passwords

Since hashing algorithms isn't something to mess around with as a beginner. Several howto's explain that one should use already made solutions. Examples of such pages: https://crackstation.net/...
1
vote
1answer
95 views

Java wrapper for a movie database API

I am still a beginner and I would love to hear some feedback on a small wrapper I wrote for the TMDb API (https://developers.themoviedb.org/3/getting-started/introduction). It is used for queries on a ...
1
vote
3answers
81 views

Transpose 2D Matrix in Java - Time & Space Complexity?

Here's my algorithm / approach for transposing a 2D Matrix on the main diagonal. Before: a L M d b G c N H K e F I J O P After: ...
0
votes
2answers
86 views

Java Palindrome - Time & Space Complexity

Which of these three methods is the most efficient? Also, what is the time & space complexity of each? ...
4
votes
2answers
79 views

Rotating an array by mentioned digit to rotate

I have developed the program to rotate the array in java request you to please check it and let me know if there are any flaws in it or where further it can be improved ...
4
votes
2answers
73 views

MySQL JDBC integration into App from tutorial

I was following this tutorial for JavaFX and Gradle: JavaFX with Gradle, Eclipse and, Scene Builder on OpenJDK11 After completion of the tutorial you will have a simple GUI which you input a lower ...
-1
votes
2answers
99 views

Messaging System Object Oriented Design

I have designed a messaging system below regarding the following assumptions I would be appreciated for the valuable reviews. Especially considering; Multi-threading / SOLID principles / Design ...
2
votes
3answers
73 views

Compute Hamming Distance

How can I make this code snippet better? Those for loops in if don't please me but they are covered with code lines that is ...
5
votes
4answers
649 views

Reviewing custom array List class of java

I am using JDK 12 and I have developed the custom array list in java with a basic understanding Please let me know if there are any flaws in it that I can correct the same First the POJO class <...
2
votes
1answer
78 views

Improved Backtracking with nqueen

I am implementing conflict-based backjumping with nqueen. I want to optimize my code especially in recursive call. In short,backjumping is similar to backtracking and it uses conflict set. When ...
2
votes
1answer
73 views

Find all substrings that contain k specific characters in a string

Given a string, return the count of the number of substrings that contains characters A, B and C. Two substrings are considered different if the starting, ending or both positions differ. Example - s ...
2
votes
3answers
130 views

Online Book Reader Object Oriented Design

I have designed and Online Book Reader System. You can find the classes below. I would be appreciated for the valuable reviews. Assumptions: "Online Book Reader System" is a system includes online ...
4
votes
2answers
78 views

Filtering product ids

As regarding the following question I have completed the code as below. But I am curious about other effective solutions. I am also curious about if there is any solution that could be applicable by ...
0
votes
2answers
106 views

Refactor method to Java 8

I have a method that iterate a list of maps if a certain element is found then set value of certain variables and break the loop. I'm trying to revamp this into Java 8. And further if it can be ...
1
vote
1answer
65 views

Better Filtering on Java Streams

I need to run filtering on nested Lists and return a List of items from back I will put a sample code here with my model ...
1
vote
3answers
116 views

Is this a correct way to utilize classes and methods in JAVA?

I am currently learning JAVA. I barely have any coding experience. I wrote a program which asks a user for a sentence. It then swaps the words of the sentence (first with last, second with second to ...
6
votes
3answers
245 views

Make my XML Parser in Java using WoodStox run faster and use less memory, or just generally better

I have an XML Parser in Java using WoodStox that I wrote. This parser is going to be parsing through extremely large files, could be 5+GB. The goal of the parser is to convert a nest XML file into a ...
5
votes
1answer
117 views

Parsing weather station XML on raspberry pi

This if for a school project that is all about getting the most performance possible out of a relatively weak computer. For this project we have received a weather station report generator that ...
4
votes
2answers
106 views

More efficient way than creating scanner of .txt file twice

I am working on a simple personal project to build a Hoffman Tree. In my constructor, shown below, I am reading in a file, creating HoffmanNodes that represent each char in the file then I got through ...
1
vote
5answers
123 views

My program generates a yearly workout program in the variation of 5/3/1

I've been building this program for around a week or two on my spare time because I'm slowly starting to figure out how to code better. This program generates a yearly 5/3/1 cycle that is exported to ...
8
votes
6answers
3k views

Class that defines a person

I have been programming for a while, but I've only made games and less serious stuff. I want to get more serious. I would like some feedback on this class that defines a person. Structure, readability,...
3
votes
2answers
152 views

How could this Java CLABE control digit calculation be enhanced

I recently wrote the following Java 1.8 snippet to generate a CLABE control digit based on the following subheading on the CLABE page on Wikipedia and I was curious on how it could be improved. ...
5
votes
1answer
71 views

Command Pattern: Does my implementation make the point?

Asking for a review of my implementation of a command pattern. In a Editor, words can be entered and the entering of words can be undone. General purpose Interface ...
2
votes
2answers
96 views

Langton's Ant in Java

I've wrote a simulation of Langton's Ant in Java, and hope you have some suggestions to improve the code. The class Control.java contains just the main: ...
3
votes
1answer
75 views

Chat Viewer working with files

I am writing a textual chat app for exercise purposes. All Chatters using my program have access to a network directory, and there my program is stored. This chat app consists of three programs. The ...

1
3 4
5
6 7
201