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
48 views

Recursive Graph coloring issue

I have a graph with nodes to color, where for each node a dataset (a collection of rows / tuples) is associated. The nodes are colored according to these rules: If two adjacent nodes have ...
-1
votes
0answers
18 views

I tried to print a Connectfour board in java but the error says "cannot load from object array because () is null". Can anyone please point out issue [closed]

I tried to print a Connectfour board in java but the error says "cannot load from object array because () is null". Can anyone please point out issue this is my Board class containing two ...
-1
votes
0answers
16 views

anyone pls can help me how to read the board of public board() [closed]

public class map { private final int COLUMNS = 10; private final int ROW = 11; public map() { } public void printmap() { } i don't right under how to make a map ...
0
votes
0answers
29 views

Temperature conversion with user input [closed]

I'm trying to create a program that converts temperature readings. Interactively, the user gets asked for both temperature and the type of conversion (c or f), plus an option for a retry if the user ...
1
vote
1answer
63 views

pointer jumping on a GPU using Aparapi

Classic pointer jumping algorithm summarizing values from an array adapted to run on a GPU instead of a PRAM. Read about openCL and Aparapi yesterday for the first time, so this is my first trial: ...
1
vote
0answers
23 views

Building a native package using Maven

After finally having enough of the hacky batch-based workflow for a project, I tried "porting" it to Maven. This is my first time using a build tool for Java, so there's probably a lot of ...
0
votes
0answers
45 views

Spring boot: better way to handle response and exceptions

I am working on a quite a big Spring Boot web service and I wanted a standardized and simplified way to handle responses and exceptions by following fluent API design. So this is what I did and it ...
1
vote
1answer
56 views

Optimizing Code for Project Euler Problem 04

I just finished Problem 04 on Project Euler, and I was looking at ways to optimize my code, just started learning functions too, so I'm pretty sure it's very bad, hopefully you guys can help me. ...
1
vote
2answers
63 views

Improving Project Euler code problem #10

So, I just finished Problem 10 on Project Euler, but it took about 3 to 4 minutes for my output to come out, due to bad coding, I guess, any suggestions on how could I optimize my code? Question The ...
0
votes
0answers
49 views

Better Approach for the House Robbery Problem (LeetCode 198)?

The problem states that you have to rob the maximum money stashed in the houses but you cannot rob two adjacent houses. array[i] denotes the money in the (i)th house. I got the following code ...
0
votes
1answer
45 views

Transformations on a game board represented as a bitset

I'm using a long as a bitset to represent a game board. If a field is set (X) the corresponding bit is set, if it's empty (...
2
votes
1answer
40 views

Simple Swing tool which displays a few procedurally generated dungeon levels

I've been teaching myself Java programming. I thought it would be an interesting exercise to program a simple utility for procedurally generating dungeon levels. This program creates a small, random ...
-1
votes
2answers
110 views

Serving In Tennis

Alice and Borys are playing tennis and it is unknown who served the first game. After each game, the serve changes to other player. If the server wins the game, then it is said that s/he holds the ...
1
vote
1answer
66 views

Refactoring duplicated code with abstraction and generics

I have written simple command line project with Spring. And from what I think quality of code is pretty poor. I see what I could improve to remove duplicated code, but somehow I have no idea what ...
-1
votes
2answers
134 views

A simple java game engine [closed]

I'm starting an object orientated game engine in Java. My plans for the engine is to be able to split things easily into multi-core loads. My idea is that a Unique (interface with a ...
1
vote
1answer
66 views

Find Kth Element in the merged two sorted arrays?

We have been given two sorted arrays and a number K . We have to merge the two sorted arrays in the sorted manner and return the element at the Kth position. My approach is to use two variables ...
4
votes
5answers
578 views

Implementation of Sieve of Eratosthenes in Java

I have implemented Sieve of Eratosthenes in Java as follows. Is there a way I can modify the below code to make it more efficient? The current execution time is 0.8481224 seconds ...
2
votes
1answer
50 views

Simple game of Chutes and Ladders

I recently made a new project for Chutes and Ladders (the Hasbro version of Snakes and ladders) and it is located here: https://github.com/vchittar/ChutesAndLadders BoardLogic (implements an interface)...
0
votes
0answers
27 views

java lib to easily build Guice scopes and gRPC scopes lib built on top of it

I've been working on a collection of few open-source java libraries related to Guice. They are a collection of classes that I was previously copy/pasting/customizing across subsequent projects I was ...
1
vote
1answer
46 views

Java grouping based on date and counting

I have an use case where I want to see how many slots have been used for a date in a restaurant. The slot can be deducted based either number of diners or per booking. Also I have to cater a case ...
2
votes
0answers
33 views

Measuring Performance of Class Instantiation with JMH

I'm new to writing benchmarks and would like some advice whether I am doing this correctly. I currently have two classes: Person.java and ...
5
votes
5answers
645 views

Comparing 2 distinct sieve of Eratosthenes algorithms in Java

In this post, I will present and compare two distinct algorithms for sieve of Eratosthenes: com.github.coderodde.math.prime.PrimeFinder ...
2
votes
2answers
93 views

Variable length array

I just started learning java and wrote this variable length array as my first program. I wanted people's opinion on how "java" this code is. For example coding conventions, idioms that I ...
4
votes
3answers
277 views

FIFO array/queue

I'm new to programming and was tasked with programming a generic circular FIFO queue, without using anything but an underlying array and self-programmed methods. I still don't know how to approach ...
2
votes
1answer
83 views

Generate anagrams and write them to a file

This is the code I've written that'll take a word as input and write all its anagrams to a file. The java compiler forces me to use try-catch statements every time I wish to do something with the file....
5
votes
2answers
339 views

Randomized Queue with ArrayList from Princeton's Algorithm Book

In the book they recommend to utilize an Array, but I think that it's easier to use an ArrayList instead, is there any problem with that? Is this code well designed? ...
0
votes
0answers
41 views

Circular Resizing Array in Queue Impl [duplicate]

I am going through a course and after learning the theory I decided to implement the DS on my own. I write a few test cases and all operations seem to be working fine but once I tried to double check ...
-1
votes
1answer
49 views

Better way to format a query string in Java

description I'm using influxDB, I need use Java to generate a query command. The TestingTag struct maybe missing 0-3 fields. code: ...
4
votes
4answers
321 views

Make surrounding elements zero in a matrix, when you find a zero value

Please can you suggest a better / Optimized logic or code for the question. It has been asked that when you find a zero value in a matrix, make that element the sum of its upper, lower ,left, right ...
0
votes
2answers
76 views

Inventory maintenance for a company

This code was done to allow a user to input, edit, search, delete and print a report of all the products in the company. Is there any way to improve my code? ...
1
vote
1answer
58 views

Comparing 8 different Disjoint-Set data structure variants in Java

The Wikipedia page on Disjoint-Set data structures presents \$4\$ distinct algorithms for finding the root node of the tree, and \$2\$ distinct algorithms for performing the union operation. In this ...
3
votes
3answers
88 views

Remove Minecraft formatting codes from a String

I obtain strings that contain chat messages, and they sometimes have formatting codes imbedded in them. A formatting code is a § followed by a character, and this ...
2
votes
1answer
52 views

Is it good way to user dao when assembling dto to entity or not?

I have User entity that has relationship to other entities(Order,Profile) When I assemble entity from dto and back I need assemble order and profile entity too. User entity: ...
0
votes
0answers
20 views

Loan graph simplification in Java: an arc minimization algorithm

In this post, I will present an interesting (to me) algorithm for reducing the number of arcs in a financial loan graphs. (The class belongs to this GitHub repository.) ...
0
votes
0answers
22 views

Loan graph simplification in Java: the graph data structures

This post presents the loan graph implementation. The class belongs to this GitHub repository. net.coderodde.loan.model.Node: ...
1
vote
1answer
38 views

Loan graph simplification in Java: the recursive DFS for searching for directed cycles

The class in this post returns a directed cycle in a financial loan graph. A financial loan graph consists of nodes and directed arcs. If there is an arc \$(u, v)\$ with weight \$w = w(u, v)\$, then ...
1
vote
1answer
72 views

A simple Java integer integer hash set - follow-up 2

(See the previous version.) Now I have this: com.github.coderodde.util.IntHashSet: ...
1
vote
2answers
81 views

Optimal Price of Products after Discounts

Input consists of 2 lists Products: [[20, 'discount1', 'discount2']], [15, 'discount2'], [10, 'NONE', 'discount1']] Discounts: [['discount1', 1, 30], ['discount2', 2, 5.5]] = = = Each product list ...
1
vote
0answers
58 views

A simple Java integer hash set - follow-up

(See the previous version.) (See the next version.) After incorporating changes in the previous post, I came up with this implementation. However, I left hashing as it is. ...
6
votes
4answers
1k views

A simple Java integer hash set

(See the next version.) The following data structure implements a hash table based set for int values: ...
1
vote
0answers
36 views

Graph stored as adjacency list or as endpoints and intervals

I tried speeding up my Graph class, so I removed the Node class and Edge class, and decided to use arrays and ArrayLists. My 2 implementations seem very similar, ...
1
vote
2answers
152 views

Parsing words from string

I am learning Java, so I am beginner. I know I can do this with split function but I want to improve my algorithm knowledge. I will be glad if you help me. Thanks. inputStr variable is contains the ...
0
votes
1answer
41 views

A Java EE7 web application for counting views in a static HTML page - follow-up

(See the initial and previous version.) This time, I have incorporated all the good points made by mtj. See what I have: ...
0
votes
1answer
63 views

A Java EE7 web application for counting views in a static HTML page

I have this blog lurking around in the web. It's just static HTML, but I was interested to keep track of all the views on that blog. Finally, I end up with the following web application: (The Java ...
0
votes
1answer
67 views

How to save/get different type of data with less duplicated code

description: I'm using thrift to save and get data by filter. The data have many types, and the types may increase in the future. So I use ...
1
vote
2answers
77 views

Merge in list from another list that are not present in the former list

The two list have different structure. The list originalPgs is a list of PGRatingConfig and has this structure: ...
1
vote
1answer
71 views

Scoring system for events

A newbie here. I have done this assignment that my university gave. Requirements Participants may enter the tournament as individuals or as part of a team** It is expected that will be 4 teams each ...
0
votes
0answers
27 views

Chain the same Runnable using Handler in Android

Which approach to creating repeating Runnables is better? ...
2
votes
1answer
56 views

Leetcode 1584. How to make my Kruskal&Union Find algorithm faster?

The question was on Leetcode 1584. Min Cost to Connect All Points. My answer to this question is: ...
19
votes
8answers
6k views

The car plate problem: generate from AAA0001 to ZZZ9999 skipping the 0000

I was given the problem (called "car plate problem") to write all the values that go from AAA0001 to ZZZ9999 with the following premises: Create all the possibilities from AAA0001 to ...

1
2 3 4 5
213