Tagged Questions
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 byte-code and run in a virtual machine (JVM) enabling a "write once, run anywhere" (WORA) methodology.
3
votes
2answers
53 views
Determine if a function is bijective
Concise Problem Specification
Given an integer \$n\$ and a function \$f : X \to X \$ where \$X = \{1,2,3,..,n\}\$ Determine whether the given function is a bijective function or not.
Definition:
...
2
votes
0answers
17 views
Inserting data into a file
So, given a file with the following format:
[header]
line of data
line of data
line of data
line of data
[header 2]
line of data
line of data
line of data
...
I add a ...
-3
votes
0answers
18 views
Generate random sequence except prohibited one [on hold]
I need to generate random sequence, but problem is that one sequence is prohibited. I wonder how can I do this code that it will generate correct code in 100% of the cases. This one is still can fail ...
0
votes
0answers
28 views
Time limit exceeded for solving longest palindromic substring by dynamic programming
I have seen plenty of longest common substring search code by dynamic programming and it is an O(n^2) operation. My motivation is to solve leetcode problem longest-palindromic-substring by this ...
2
votes
3answers
103 views
Pattern printing with Name
Found this problem somewhere online and wanted to try this out with my beginner skills. I was able to solve this problem but how can I make my code better?
We need to print a pattern like this (each ...
-3
votes
0answers
29 views
Completing a chess move and setting the initial Location of chess pieces [on hold]
I am currently developing a beginner 2-player chess game with java Netbeans. I have a class PieceMovement, which works on the movement of Pieces. In this there is a MoveDone() method, which completes ...
3
votes
1answer
109 views
Find items that appear the same number of times in two collections
Here is a Java collection puzzle I found online. I was wondering if anyone can provide me with suggestions on how Appearance and tests can be improved. Suggestions ...
3
votes
0answers
19 views
Progresses a text adventure by user input [on hold]
I'm coding a text adventure and I'm trying to have both unique and general inputs.
The style I'm currently using looks like:
...
0
votes
0answers
18 views
Glueing Java collections into a heap
I have implemented this heap (priority queue) data structure using java.util.TreeMap and java.util.ArrayDeque. The operations ...
0
votes
2answers
63 views
Java synchronization task
I have the following task:
Implement a simple command line Java application for booking bus
seats. For simplicity suppose there is only one bus, initially all
seats (lets say 50) are free. ...
3
votes
1answer
49 views
Shopping cart program in Java with a text menu
I wrote this program to implement a shopping cart. It supports adding/removing items to the cart, viewing the current order, and completing the checkout process.
...
0
votes
0answers
22 views
Updated version of app which does CRUD on a database table
A while ago I created my first Java application. I tried to follow the MVC pattern. I posted my code for review and with the answers I got I did more research and rewrote my code.
I gave every ...
0
votes
1answer
58 views
Implementing movement in a Pacman game
I am making a Pacman Player vs Player game in Java, and I am wondering if I am implementing movement in the game in a good manner. Anything that will reduce the code size or make the program faster is ...
1
vote
1answer
26 views
Documentation for a Minecraft server plugin
I'm working on a minecraft plugin for my Spigot Minecraft server.
I have a class which works as expected. I've done my best to hammer every single bug out (famous last words, I know) and am now ...
-4
votes
0answers
17 views
How do I loop a specific piece of code in Java with the Switch Command [on hold]
I want to loop MultipleChoice1 if the answer is not either A or B, hence the case "A" and case "B" but when I try to loop it using:
int loop = 2
while( loop < 2)
(The other codes)
case "A":
case ...
3
votes
2answers
88 views
Listing employees whose employee number is divisible by some given number
Here I want to improve the code in addListofEmployees and mainMethod. How can I do so?
...
4
votes
1answer
35 views
Binary-octal-hexadecimal conversion table
I solved this exercise of displaying a table of numbers from 1 to 256 in binary, octal and hexadecimal. I made this program to convert from decimal to binary and took that binary number to convert to ...
2
votes
1answer
29 views
Sorting the array of strings on their lengths in Java , Using Maps, ascending order…
I wrote the java method to answer this question :
Write a Program to sort String on their length in Java? Your method should accept an array of String and return a sorted array based upon the length ...
0
votes
1answer
28 views
Square ImageView
This is good practice, to make square image? Side of the square container is equal to its width.
...
1
vote
1answer
41 views
Am I doing cookie authentication right?
So I have to write a little social network for a case study at university. I have done some simple webapps before but nothing that required authentication, login and so on. So I wrote this little ...
-3
votes
1answer
62 views
If my code is propely way of Java programming [on hold]
I'd like to ask question about my programming. I am beginner in Java so I want to know if my code is right. Should I change any habits? I'd be grateful for any advice.
This is my working Server code:
...
-1
votes
0answers
36 views
Calculating my shocking monthly electricity costs [on hold]
I've been learning Java for a few months now and have finally tried my first project from scratch. I succeeded partially in some of it, but I'm really confused by some other parts of it. I was hoping ...
1
vote
1answer
60 views
Retrieving location coordinates from SQL database and plotting on a map android Gmaps
I am new to Android development. I am currently working on an Android app that fetches changing location coordinates from a SQL database, and plots on a Map view at regular intervals. But I think this ...
4
votes
2answers
283 views
Guess number game with mines
I've made mine first Java program and it was Guess a number game and got some great code review, so I've decided to first implement that suggestions and to make a game a bit more complex/advanced.
So ...
4
votes
2answers
75 views
DB-to-Java value mapper
In my company, I've inherited some Java library that I'm now writing tests to, refactoring and fixing Sonar issues.
One particular point that Sonar is complaining about is a big chaining of ...
1
vote
1answer
29 views
Logging in to Android application using Firebase
I currently have an app that uses Firebase for logging users in and I would like to know if I can make this code any better. I currently have 4 files:
auth/models/User.java
...
-1
votes
0answers
26 views
4
votes
1answer
67 views
Comparing three data structures for dealing with probability distributions in Java
Introduction
Suppose you are given three elements \$a, b, c\$ with respective weights \$1, 1, 3\$. Now, a probability distribution data structures will return upon request \$a\$ with probability 20%, ...
3
votes
1answer
57 views
2
votes
2answers
48 views
Simulate the “cd” command of a file system
Write a function that provides change directory (cd) function for an abstract file system.
Notes:
Root path is '/'.
Path separator is '/'.
Parent directory is addressable as "..".
Directory names ...
1
vote
1answer
55 views
Mini Twitter (in memory, single threaded)
I am new to Java and would like to know whether my program is idiomatic. Please help me write idiomatic, terse code. My solution is functionally correct.
Design a simplified version of Twitter ...
-3
votes
0answers
17 views
Created JTextField and JButtons which are very hard to see, how to scale them up? JAVA 4k screen [closed]
I have a program which creates three JButton:s and one JTextField. But when I run it, I can barely see them. I have tried to change the parameters to setPreferredSize and JTextField, but that will not ...
-1
votes
0answers
32 views
How to regroup all data for API Endpoints in one place? [closed]
I would like to have every endpoint with parameters, method and endpoint url in one place, so it is easy when I want to change it.
To register an account, it is POST ...
1
vote
1answer
108 views
Winning logic for Tic Tac Toe and OO design
I'm a Java beginner and I've just started learning about GUI. However, I'm not sure about GUI coding conventions and whether I'm getting the object orientation part of it right. I feel like I'm ...
9
votes
1answer
90 views
Naive parallel Sieve of Eratosthenes in Java
My naive version now is too slow. I think setting/accessing concurrent atomic bit is way slower compared to access/modify an array of boolean. Second, the parallel execution only happens on the ...
3
votes
1answer
48 views
Queue Using Stack java implementation
Implemented this solution for the problem. Feedback and review if this can be improved in an way. Appreciate your help.
...
3
votes
1answer
70 views
Conway's Game of Life Java Implementation
Keep state the same if it doesn't fall in the following conditions:
Change to 2 if there are exactly 2 ones in the neighbors
Change to 3 if there are more than 2 ones in the neighbors
It is also ...
9
votes
2answers
165 views
+50
Constant-time string equality check
This is my attempt to answer my own equally named question on SO. In this case, I need a method comparing two strings so that the running time is input independent.
...
1
vote
1answer
126 views
Random iteration over an array using divide and conquer
I have created a utility class which allows random iteration over an array.
The idea is pretty much a divide and conquer approach.
...
-4
votes
1answer
51 views
What is a good practice to generate a HTML table from a java class [closed]
I am rewording my earlier question. Below is a code that I am using to generate an HTML table based on some criteria. This is just a sample class, in real we are using a class with complex business ...
-2
votes
0answers
41 views
Dice rolling game [closed]
I created this program and coding for the task mentioned. Could some advice if this is right.
...
2
votes
1answer
34 views
Updating certain values in text file
So I need to update some certain values within text file based on actual values there. Any advice on making it more effective or just readable is appreciated.
Example text file:
...
3
votes
1answer
59 views
Printing longest lines
Challenge
Write a program which reads a file and outputs a specified number of lines, sorted on length in descending order.
Specifications
The first argument is a path to a file.
The file ...
-3
votes
0answers
27 views
NullPointerException in JavaFX methods [closed]
I am getting null pointer exception when try to use a method in Controller class. I am new in JavaFX, so don't know why its happening.
...
1
vote
1answer
54 views
File Writing optimizations - FileOutputStream vs Writers
I'm using a simple logger on a server, which uses a method that looks like this:
...
0
votes
0answers
17 views
Getting my methods to add grade letter to my array [closed]
I have the code below for a program that using arrays and superclass can calculate the grades of multiple students and take the average and give them the grade letter. I've been going back and forth ...
2
votes
1answer
33 views
DisjointSet with O(1) find and O(1) amortised union
Does this code outperform the common implementation with path-compression and union-by-rank? I'm still okay with a review.
GitHub
...
10
votes
3answers
243 views
Finding Pythagorean triplet in array
We have an integer array as:
private int[] arr = {1, 3, 5, 14, 18, 29, 78};
We have a function which takes three inputs of the array and checks whether:
...