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

Employing 3DES algorithm in Java

I am making a project just for fun that employs the 3DES algorithm in Java. I was wondering if my algorithm looks secure. Is there any advice or feedback you could give me? Do I need to include an IV? ...
2
votes
1answer
63 views

library having two types of books

I need to make a project related to a library catalog. It should have following methods relevant to these books: add delete list There are two types of books: novels and poetry. Both types have ...
6
votes
4answers
773 views

Return a String containing only alphabets without spaces

Scenario: Return a String that contains only alphabets without spaces. input = "A man, a plan, a canal: Panama" output = "AmanaplanacanalPanama" Can you please critique my code? ...
12
votes
2answers
8k views

Ping-Pong game in Java

I wrote a simple game in Java using Swing. Code is working so far but I have no certainty that "spliting" into classes is done well. I would like to know what "design" problems I have in my code. Also ...
4
votes
2answers
2k views

Spell Checker program using dictionary implementation

This is a small program written for a small assignment to check spelling. The assignment asks for the following output: A list of words that are misspelled in the file A count of the ...
3
votes
1answer
94 views

Rubik's Cube in Java

I have this Java implementation of a Rubik's cube's state. My primary concern is DRYness of my code: RubiksCubeNode.java ...
2
votes
1answer
63 views

Implement search for JPA and Spring

I'm trying to implement properly search functionality for database table. I tried this approach: Controller: ...
6
votes
1answer
98 views

Minimax implementation of tic tac toe

I have the following working tic tac toe program. Someone said it's a convoluted mess and I'm looking for pointers on how to clean it up. ...
1
vote
3answers
182 views

Generic implementation of binary search tree in Java

The following is my binary search implementation in Java: ...
0
votes
1answer
73 views

Optimize this code of adapter's overriden method getItemCount() [closed]

How can I optimize this code of adapter's overriden method getItemCount() into simpler form? ...
2
votes
0answers
46 views

Faster k-shortest path algorithm in Java

In the \$k\$-shortest path problem, we are searching for (at most) \$k\$ distinct, shortest paths connecting two given terminal nodes. You can see the previous version here. This implementation, ...
0
votes
1answer
1k views

k-shortest path algorithm in Java

(See the next iteration.) This snippet is about computing \$k\$ shortest paths in a directed graph using this algorithm. I would like to hear about API design, naming/coding conventions, and so on. ...
2
votes
1answer
63 views

Converting hex strings to byte arrays and back to hex strings in Java

Here is my attempt at converting hex strings to byte arrays and converting byte arrays to hex strings: net.coderodde.util.ByteStringConverter ...
1
vote
3answers
1k views

Simple version of the Game Of Life

This is just a very simple version of the Game of Life made in Java. Please let me know how I could have improved this. I am also hoping for some feedback on how the formatting and conventions are ...
4
votes
2answers
2k views

Loop for inserting a node into a binary search tree

I am trying to implement binary search tree. One method which I am trying to implement in the most efficient and stylish way is node insertion. I am under the impression that while (true) is a bad ...
5
votes
0answers
98 views

Java multithreading many readers one writer implementations

I have a shared data object with writer threads and reader threads. Number of threads can read from the shared data at the same time (in the code getmethod), and ...
9
votes
5answers
2k views

Java guess the number

I have just returned to college to finish my associate's in programming. The language my school uses for all of the programming classes is java, so I've been trying to get used to the language. The ...
6
votes
3answers
136 views

Rotate array to the left

I am a beginner in programming. To rotate the array to left, I have written the below code. Please point out how to optimize the code and anything I am doing which is not good programming practice. <...
3
votes
2answers
109 views

Test if a number is within 2 of a multiple of 10

I have solved this exercise, but it looks really redundant. Is there a built-in function in Java or a cleaner way to caluclate mod of a value + deviation without multiple OR statements? If I had to ...
6
votes
2answers
79 views

Multiple null Checks or try/catch NullPointerException [closed]

There is A LOT of information online stating that you should NEVER catch a NullPointerException. Generally I agree, but I am wondering about this one case. I have inherited code that requires me to ...
7
votes
4answers
10k views

Reversing a singly-linked List

Is this the best way to reverse a singly-linked list? Can it be done with two, or fewer pointers? Any other comments? ...
6
votes
2answers
6k views

Sending n requests in one time

I need to test my new functionality by sending about 100 requests in one time. ...
5
votes
2answers
94 views

Filtering conversation by filter type and value

I have been assigned to developed a feature that filters a conversation. For example, I want to filter the conversation by user id then export it to something either JSON or text file. In this case, I ...
1
vote
2answers
157 views

Turing machine schoolwork

Our teacher doesn't give much feedback on our code itself. Was just looking for some feedback on how I could improve on this. This is the method that tests the string against the Turing machine that ...
4
votes
1answer
29k views

Passing a generic function as parameter

Ran into this idea and I'm curious if it's possible. I'm trying to make a single function that can test ALL of my sorting algorithms dynamically. I want to be able to pass the sorting function as a ...
5
votes
1answer
921 views

LRU Cache Implementation with HashTable and LinkedList

Problem Statement: Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and put. get(key) - Get the value (will always be ...
3
votes
2answers
178 views

Java implementation of well-separated pair decomposition

I was trying to implement the algorithm of the 3D well-separated pair decomposition WSPD using an octree. First, I begin by implementing the class OctreeNode as ...
1
vote
0answers
61 views

Spring boot for a blog REST API

I'm working on a blog REST API and I would like to get some opinions on where to place the logic for a single operation to filter posts. I have Category and Post in the model package. A category has ...
3
votes
2answers
116 views

Evaluation of a variation of quick-sort (pivot-selection)

Here is a variation of quick-sort where-in the pivot selection is based on calculating the average of the values of the highest and lowest numbers. ...
1
vote
2answers
73 views

Java lexical analyser

I created a lexical analyser in Java recently, but I don't think the performance is very good. The code works, but when I debugged the program, it take around ~100 milliseconds for only two tokens... ...
2
votes
1answer
56 views

Removal of subtrees in tree on condition optimally

I have a small program that removes subtrees of a tree based on following condition: If a subtree consists only of nodes with "rank" 1, remove it. I am using recursive DFS approach. Trees or ...
22
votes
6answers
24k views

Simple text-based RPG in Java

I was looking for suggestions on how to improve the general flow of this code, as well as minimizing if / switch conditionals. ...
0
votes
1answer
43 views

Country, city, and address tables for a customer

I need to create a customer and I have foreign keys for each table. Below is an image displaying the relationships of the tables when I want to insert a new customer. Then below the diagram I list out ...
1
vote
2answers
67 views

Merging K Sorted Linked Lists

Specifically, how can I improve the time complexity of my algorithm (currently it is O(listLength * numberOfLists))? It only beats 5% of accepted LeetCode solutions,...
4
votes
2answers
114 views

Heights of Cats

I have an assignment to solve this problem. However, I have exceeded the time limit required, can anyone suggest where to improve my code? Cats like to sit in high places. It is not uncommon to see ...
1
vote
0answers
53 views

JavaFX lazy loading of images in TableView

This code is based off https://stackoverflow.com/questions/25711103/javafx-combobox-lazy-loading-images but modified to work with a TableCell Firstly, the model object should have an observable ...
7
votes
3answers
8k views

Texas Hold em Poker Hand recognition algorithm and implementation

I am designing an in-depth poker game. I am first focusing on recognizing the strength of a hand given the set of cards. Is the following algorithm suitable for the stated purpose? Am I using correct ...
5
votes
3answers
720 views

Note class for managing information on various musical notes

I just finished (re)reading Clean Code, and one of the ideas I learned was the SRP. However, I am not quite sure on what defines a "Single Responsibility." In the piece of code below, I have a ...
5
votes
3answers
683 views

Java Langton's Ant simulation

I have implemented a simulation which is called "Langton's Ant" with Java. Here is a short summary of basic rules: A ant is placed in a 2D matrix and looks to north, west, east or south. First, all ...
0
votes
1answer
63 views

Two-player Yahtzee game

I am working on a Yahtzee game development for two players that consists of all the categories Full house, Yahtzee, ones, twos, threes, etc. I have implemented the interface that works for two ...
9
votes
3answers
35k views

First attempt at a Java Blackjack game

I just completed my first multi class program, Blackjack, and it works! It allows the user to play Blackjack against a single dealer, with no other players at the table. I was wondering, seeing as it ...
1
vote
3answers
1k views

Can I avoid nested for loop in this case?

this code works fine but i want to know if this can be improved in any manner . For every user I am fetching the namesList corresponding to that user and for each fetched nameList , i am fetching the ...
2
votes
1answer
47 views

RecyclerView with different ViewHolder using generic

I have different ViewHolder for different Feed implementations. But I can't use the best practice of having each ...
1
vote
1answer
112 views

Implementation of Dijkstra algorithm

I am trying to implement Dijkstra algorithm. I try to calculate cost of reaching every node from first node. Though I have tried with couple of graphs and results are correct but I have one doubt ...
5
votes
0answers
87 views

Java objects for a network sniffer program

I'm working on a network sniffer program, whose structure uses 3 main classes: Frame Class - One per monitored frame, holds reference to all the other sub frames Parse Class - Holds the hex value of ...
2
votes
2answers
147 views

TLE in JNEXT problem in SPOJ

Problem Statement: JNEXT DevG was challanged to find the just next greater number which can be formed using digits of a given number. Now DevG needs your help to find that just next greater number ...
3
votes
1answer
95 views

Random String Chooser

I was tasked with creating the class RandomStringChooser that prints the strings in the passed array in a random order, based on the ...
0
votes
0answers
18 views

Given a resource ID, instantiate, retrieve and localize a Linked Resource for a REST API call

During a question on Stack Overflow, another user had some comments about the way this code works. He had a few choice words for it, including "magic", "ugly contraption", "you're doing things you ...
0
votes
1answer
66 views

Graph Implementation in Java using Set and Map

There is a Graph implementation. I'm using Set to store unique Edges and Map to store Vertices and their associated edges. Assume Vertex and Edge class has been defined somewhere else implementing ...
7
votes
2answers
5k views

Simple Mastermind game in OOP form

I'm currently learning Java. I'm trying to get a good grasp on determining what becomes a class. I've started translating old games in to simple Java programs. I'm looking for any critique of use ...