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
3
votes
0answers
10 views

Dynamic-sized Hash table with Linked List

Below is an implementation heavily based on climberig's implementation on Leetcode for LeetCode 706. Design HashMap. Just to preface, I am doing this in preparation for an exam. The one below is ...
2
votes
0answers
27 views

DynamicClass - loads and instantiates classes at run-time

I needed to dynamically load and instantiate some classes from a generated jar and a generated .class file which depends on that jar. So I came up with this: ...
-1
votes
0answers
28 views

Downloading a list of images from a bucket java [closed]

Can some help me am trying to retrieve a list of images from s3 bucket below is my code but it's not compiling. images = imageResults.toArray(images); am getting ...
2
votes
2answers
43 views

Get all data from an external and paginated Swagger API using Java / Feign / Spring

I have written the following method that allows me to import from another API all the items stored there using Feign. The only issue is that the external API provides a size limit of 2000 and ...
1
vote
0answers
19 views

Method name if class already contains a part of it [closed]

I have a class called ComputerGameService. In this class I've methods with following names: ...
-3
votes
0answers
16 views

How do I volleyrequest to see if data does not exist in mysql table? I want to set an x drawable in an imageview if an entry does not exist [closed]

I am making an app that has users complete a survey. They are given a grade that is time based. This means if you complete the survey (called the monthly check in) within 5 days you get an A, 8 days ...
3
votes
2answers
58 views

Tips on my LIFO java code

I've been trying to learn java recently and I finally finish my first code. Any suggestions on where I can improve? Also, is it possible to send an argument to a class using something like an init ...
3
votes
2answers
73 views

Returning interfaces in Java without significant casting

I am writing some code that takes and returns interfaces following the patterns in Effective Java Third Edition. I understand the principle - we want to take in interfaces because in many cases we don'...
5
votes
0answers
79 views

Python version of Clean Code book example

I started reading Robert Martin's Clean Code. I'm trying to "translate" all his examples into Python, so I can understand them better since my domain on Python is greater than on Java. ...
2
votes
1answer
66 views

Add comma/and between string array in java

i get an array of authors from json response and i have to display authors name in TextView(android) in proper format like =>Viraj, Chetan and George R. R. Martin my code work fine, but it's a mess....
0
votes
0answers
26 views

Retry to connect to an SQL Database with variable retry rate: code style, testability and clarity [closed]

I just write some code that allow for the following functionality: Connect to an SQL Database and return the connection If the connection cannot be made, retry after a 0.5sec delay If it still cannot ...
5
votes
1answer
96 views

JavaFX clone of Snake game

I have made a Snake clone using Java 14 and JavaFX 14. My game uses an anonymous instance of the AnimationTimer class as the game loop. The basic UI for the start ...
1
vote
0answers
52 views

Self Running iterable state machine with Enums in Java

During development I needed to design a state machine with decision which runs to completion and performs state transition without the need to wait for events. So i come up with the following ...
-1
votes
1answer
74 views

Is performing IO in constructor good idea? [closed]

I have Java (or C#, Python, Kotlin, or other similar language) class that will be used to communicate with client over network. Protocol used by this application allows many different ways to create ...
3
votes
1answer
78 views

Concerned about thread safety

I'm writing start/stop module for my application. I have a class that manages application life cycle and I called it Work. Work ...
3
votes
0answers
30 views

Optimizing the topological sorting

I have implemented the topological sort. Is there any suggestion for optimizing the solution? Thanks. ...
2
votes
1answer
40 views

Optimize insertion from ArrayList to HashMap

I'm trying to insert data from ArrayList to HashMap<String, Language> optimally. Many items may have the same languge_name (code below), so I need to group items having the same language in ...
2
votes
0answers
24 views

Linkedlist & hashmap _duplicates removal

I have implemented a LinkedList removal fo duplicates class by using HashMap. Looking forward to your reviews. Thanks. ...
2
votes
0answers
28 views

Ranking Tennis No.1s

Previously, I built a scraper to get ranking data for ATP # 1 over the years. See Webscraping tennis data, and follow ups. Now, I use the data to rank the players on the basis of how many weeks they'...
2
votes
0answers
29 views

Collect messages from a job to send in body of one email

I have a Spring service that calls a few methods to ...
6
votes
1answer
117 views

Book library with borrowing support

I decided that in order to get better at programming, I should focus on building and improving simple projects. I have made a library program that contains collections of unique books of varying ...
-3
votes
0answers
25 views

trying to make a app that accesses music databases to gather information on songs such as popularity and metrics of the song [closed]

stuff like bpm that you can only find by opening up the file, or accessing the database that already has that information, popularity like on charts and such, etc. and other factors of the music. need ...
-4
votes
0answers
36 views
3
votes
0answers
49 views

Hashing and sliding window for string

I have implemented a solution for finding all anagrams. Are there any other suggestions for improving the solution? ...
5
votes
1answer
170 views

ZigZag array implementation

I have implemented a zigzag array which will sort smaller greater smaller and goes on... For example : 3 7 4 8 2 6 1 is a valid ordering. The relationship between numbers is 3 < 7 > 4 < 8 >...
2
votes
0answers
76 views

Ugly Number problem using dynamic programming

I am learning Dynamic Programming and tried to solve the nth ugly number problem using it. Here's my code for the problem in Java: ...
3
votes
2answers
65 views

Largest Sum Contiguous Subarray - Kadene's algorithm

I am looking forward to an answer to improve this code? Thanks. Test class ...
3
votes
1answer
99 views

In-place merge two sorted array

First post. Can you please review my code and help me improve my coding. Please also suggest improvements if there is a miss in this post. Problem Statement Given two sorted arrays ...
1
vote
0answers
44 views

Is it thread safe? [closed]

I'm working on a class that provides my application's start and stop method. Those methods can be called from different threads and I'm wondering if my solution is proper. Notes: ...
3
votes
1answer
70 views

Updates or creates an entity based on if a value is present in an Optional

I need to get car info from a 3rd party web service and persist the data in my application DB. If my DB already has the car, I only update property values that may have changed. Otherwise, I create ...
6
votes
2answers
84 views

In Java: convert an array of floats to bytes and vice versa

I'm just returning to Java after a multi-decade hiatus -- there are some nice new packages, such as java.nio. I need to convert an array of floats into bytes and vice versa. The ...
2
votes
0answers
32 views

Building a Tree using LinedBinarTree implementation

can someone review my code for me. Here is my algorithm: initialize dataQueue with all elements to be added into the nodes in order initialize parentQueue as empty queue create the tree's root node ...
4
votes
1answer
66 views

LeetCode 839: Similar String Groups II

I'm posting my code for a LeetCode problem. If you'd like to review, please do so. Thank you for your time! Problem Two strings X and Y are similar if we can swap two letters (in different positions) ...
3
votes
2answers
91 views

First Unique Character in Java by frequency

I have completed an implementation for finding the first unique character. Is there any way I can improve it? ...
2
votes
1answer
33 views

Producer-Consumer Semaphore Implementation

I have implemented a Producer-Consumer by Semaphore implementation. I am looking forward to for your code review comments. Thanks. ...
0
votes
3answers
20 views

Filter for duplicate elements

I wrote code to filter for duplicate elements in an array. I'd like to know your opinion, whether it's efficient at all, or if there's too many objects created, use of both array and list. That's in ...
1
vote
0answers
54 views

Java past paper exam revision [closed]

I am doing an OU module on Java, I have a resit exam coming up in September and am at presently going through past papers. Understandingly due to the current Covid-19 situation the OU are not running ...
1
vote
1answer
74 views

Binary Search recursive & iterative solution

I have implemented binary search solution by using recursion and iterative approach. I there any way to improve it? Tests ...
5
votes
2answers
139 views

Finding word count for a given string

I wrote a program to implement to find the count of words for a given string. I have applied two different approaches. The test works for these two approaches and I am looking for other approaches to ...
1
vote
1answer
31 views

any better way than using old servlet api for downloads

I am wondering if the following code can be modified to be used with latest version of spring APIs? The following code works fine. However, I wanted to know if servlet APIs can be avoided which i have ...
4
votes
2answers
83 views

In-Memory FileSystem in Java - Is there a better OOP approach?

I have implemented an in-memory filesystem - this is a design question from LeetCode. Is there a better OOP approach to represent files and directories? The current code uses a boolean flag ...
4
votes
2answers
63 views

Three Card Monte game using Java

I made a Three Monte Card game using Java Problem: This is the original "ball and cups" game where you try to find out which cup has the ball under it. You may play with three cups and a ...
7
votes
1answer
155 views

Using Collectors.toList instead of forEach and a new ArrayList

I have the following Java 8+ code (on Java 14). I have a (terminal) forEach call and I am adding each mapped object to a newly created ...
3
votes
1answer
82 views

Game of life GUI simulation using java.swing

I am fairly new to GUI programming and I am interested in improving my code from every aspect. Performance, security, readability, conciseness, and the look-and-feel aspects are all important to me. ...
1
vote
0answers
39 views

Tree kind of Object. Adding and Removing children

I am trying to work with a list of Person objects where the Person object has a property called "children" which is an array of same type. I idea is to have methods called “addChildrenToMain”...
5
votes
1answer
42 views

A Program that gets text from a client and puts it into a file on a server

I recently created a program that could get information from a client, a name and some text, and then put that into a text file. From there the user can get open the text file straight from the ...
7
votes
1answer
102 views

Chess application with GUI and AI in Java

I've included the files that I felt were relevant (i.e I haven't included the individual pieces in the inheritance hierarchy). I'm particularly curious as to whether the system as a whole is ...
6
votes
3answers
536 views

Print a christmas tree

...
4
votes
2answers
57 views

Online Reader System Object Oriented System

I have designed and Online Book Reader System as considering the previous reviews on this platform. You can find the classes below. I would be appreciated for the valuable reviews. Assumptions: "...
4
votes
0answers
29 views

Parsing HTTP request for webserver implementation

I'm writing a web server from scratch on pure Java in learning purpose. As a part of request handling, I worked on a class to parse HTTP request, I expect from it to be able to do next things: ...

1
2 3 4 5
204