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

Unix batch job execution from BDD automation framework

As part of my testing, I have to connect to Unix server using putty and execute few unix jobs. Feature file Steps for test scenario: ...
3
votes
1answer
54 views

Java i/o speed less than python i/o while printing an array

Motivation: I was solving an array based i/o problem and encountered Time Limit Errors, it was later found that the code for java ran roughly 10x slower than the ...
0
votes
1answer
71 views

A RESTful API with values dependent on query params

I have a RESTful service where clients provide product codes, start date and end date. In response, the service returns a list of price metrics for the products over the date range. Start date is ...
9
votes
1answer
191 views

Generate unique random strings considering collisions

I'm coding a random strings generator. It's working, but I'm not sure if this is efficient. ...
2
votes
1answer
65 views

Improvement in code written using Java8 streams - traditional for loop

I am writing API code using SpringBoot, Spring JDBC Template etc. In one scenario, I am fetching list of Object from DB and storing it like this: ...
0
votes
2answers
50 views

Bank Account GUI

I've decided it would be best to break this project down into several parts. Consider this Part 1(GUI Design). I'm looking for help making 2 main improvements: Whenever I make a GUI, its always very ...
1
vote
0answers
47 views

Java Polynomial, while I know this works, help me make it better

As stated, I know this works but I want to improve this code! I don't expect anyone to re-write this but if you have some "try this instead" then great! ...
0
votes
0answers
35 views

Print all combinations from dictionary which will result in number N

Print all combinations from dictionary which will result in the number N ...
2
votes
1answer
51 views

A simple clusterness measure of data in one dimension using Java - follow-up 2

(See the previous version here.) This time, I have encorporated all the suggestions made by Marc. Also, I changed the type of points from Double to ...
6
votes
5answers
256 views

Best data Structure for storing a phone keypad format

I was trying to code the phone keypad characters with its numbers. The first idea which came to my mind is using a HashMap. After trying various options I came up ...
1
vote
1answer
42 views

A simple clusterness measure of data in one dimension using Java - follow-up

(See the previous version here.) (See the next version here.) This time, I have incorporated all the suggestions made by Roman; my new version follows. ...
3
votes
1answer
62 views

Sample Breakout Game to introduce students who have covered the AP CS A syllabus to Java Graphics:

I am an AP CS A teacher but as the syllabus does not include Graphics this is really my first time in using Java graphics. I am looking to produce a project not far above the realms of the AP CS A ...
0
votes
2answers
63 views

Luhn algorithm using Stream API

Example ...
2
votes
1answer
41 views

Registering listeners according to SOLID pricipals

I'm practicing oop concepts these days. To figure it out I tried the below problem. There is a sensor monitoring system. It is a simple system that prints a value, ...
-3
votes
0answers
18 views

input month name correspond to the number and dectect if it correct or not [closed]

I want my program result to be like this Month 9: July wrong where 9 is the random number using random and July is the input using scanner I did something wrong and my code does not work, please ...
1
vote
1answer
86 views

A simple clusterness measure of data in one dimension using Java

(See the next follow-up here.) Problem definition Given \$X = (x_1, \dots, x_n)\$ such that \$x_1 \leq x_2 \leq \dots \leq x_n \$. Let \$x_{\min} = \min X = x_1\$, \$x_{\max} = \max X = x_n\$ and \$r =...
0
votes
2answers
49 views

Optimizing methods with multiple if checks on getter values

I have a method where I fetch user input, check if certain values exist, and based on that build my own custom input object that I would use to search in a database. The code for the search method is ...
3
votes
2answers
4k views

String 'expanding' - reinserting repeating characters

The challenge: Given a String, for each digit in that original string, replace that digit with that many occurrences of the character following it. So a3tx2z yields ...
2
votes
1answer
70 views

Java basic user account registration

I made a very simple user account registration program that works in the terminal using no external libraries other than java.util.Scanner. I want to know what ...
2
votes
3answers
13k views

Seasons by month and day

Write a program reads two integers representing a month and day and prints the season for that month and day. Assume that months are specified as an integer between 1 and 12 (1 for January, 2 for ...
-3
votes
0answers
25 views

How to get this code to work with negative numbers Java [closed]

I have a function for evaluating equations in the form of strings but I don't think (I didn't write it and I am not good enough at Java to understand it yet) that it works with negative numbers. Is ...
3
votes
1answer
52 views

Generic Scanner(System.in) Parsing

Often end up using a Scanner to grab some simple input and often when dealing with Number input it can result in a lot of little ...
3
votes
1answer
51 views

Testing DAO Delete User

I have several Dao classes, including a UserDao, below. The DAOs have many methods, but I'm focussing on deleteUser: ...
-3
votes
1answer
38 views

Creating two txt file for changed and unchanged records [closed]

Hello developers i have a got a code which is compares two txt files find their differences and notes them but i am wanting to add a feature which creates two txt files first one is for changed ...
24
votes
4answers
1k views

Refining AI movement logic

I have the below class which moves the AI towards the given plant, this works well however it feels really messy. Any input as to a better way to lay out the logic would be really grateful, the logic ...
1
vote
1answer
49 views

Sports DataSheet

This program asks the user for a players name, # of goals, saves, games played, etc. This information is ten organized on a .txt file along with the time the information was logged. users can also ...
0
votes
1answer
42 views

Evaluate my program with Java Mail + Sql + Swing

I'm 16 years old and no one to help me, no one to give any advice or constructive criticism, I'm aimless. I'll leave the link to my last code (github), a program that sends an email to everyone ...
3
votes
1answer
92 views

Find all combinations of numbers of a set that add up to a given target - avoid for loops

I am thinking about the following problem: Consider a 3-numbers lock, i.e. a lock which has three little number wheels that opens whenever the sum of these three numbers equals 75. I know, this doesn'...
2
votes
2answers
98 views

Streaming substrings of a string

Given a (long) string src, generate substrings (up to) len characters long on demand by iterating over ...
9
votes
1answer
18k views

Cash Register Challenge

Challenge: Design a cash register program Specifications: Your register currently has the following bills/coins within it: 'PENNY': .01, 'NICKEL': .05, 'DIME': .10, 'QUARTER': .25, ...
3
votes
2answers
77 views

Spring Boot API - Avoiding Concurrency issues

I'm still in the process of learning Java / spring and I think I'm getting better. Now at this point I'm able to build a rest api BUT I'm at a lost at how to ensure I've no concurrency issues . I've ...
2
votes
2answers
84 views

Treating Optional values

I have a situation when there could be and could not be values in database, which is why i return optional, so the response object that goes back to the UI could be different depending on the ...
3
votes
1answer
149 views

Aggregate data from a huge list under 50ms

I got this question as a coding challenge and was unable to get it done under 50 milliseconds (my solution takes >100 ms) :D Would you please review my code and share any idea how to do this within ...
5
votes
2answers
6k views

handle null in Comparator class

I have a class LoanAccount that contains an attributes creationDate and loanAmount. I ...
2
votes
1answer
54 views

program that sends an email to everyone registered in the database

I'm 16 years old and no one to help me, no one to give any advice or constructive criticism, I'm aimless. I'll leave the link to my last code (github), a program that sends an email to everyone ...
0
votes
1answer
83 views

Correct use of Serializable with lambda functions

I'm practicing saving and reading serializable objects when a friend told me serializable objects have no use in real life, that I'd better focus on JSON or XML to serialize my objects when I came ...
0
votes
0answers
50 views

Android app class serialization with static Load / Save method

This is a follow-up question for Android app class serialization. As forsvarir's updated answer mentioned "A static load that returns a new instance of a ...
5
votes
3answers
12k views

Unit testing a servlet in a meaningful way

I have to write a unit test for the method processRequest in the servlet below and I'm wondering if: It just shouldn't be done. The class should be rewritten / ...
2
votes
1answer
88 views

Writing a clean Predicate Builder

I have an inner class for filtering: ...
3
votes
1answer
76 views

SkylineProblem in Java

taken from leetcode.com: A city's skyline is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Given the locations and heights of all the ...
2
votes
3answers
257 views

Java logger (of doom!), updated

In a previous question, Java logger (of doom!), I had posted my own logger, written in Java. I have since taken the answers from that question and a few of my own things to update it. New code: ...
1
vote
1answer
41 views

Android APP FTP uploading file implementation in Java

This is a follow-up question for Android APP FTP host profile class implementation and Android APP connect to FTP server in Java. I am attempting to perform the upload operation to specified FTP ...
4
votes
1answer
626 views

Colour ramp for maps

I'm porting this code to Java and after a few tests all seems ok but I need to know if I'm doing this right. The code takes some colors and create a color ramp for maps and other stuff. You can see ...
9
votes
5answers
18k views

Locker Puzzle in Java

The author of my book does not release odd-numbered solutions to students, so I can't check my solutions. I was wondering if there was a better way to solve this problem without simply printing out ...
0
votes
0answers
56 views

How to split recursively a dataset according to one of its attributes?

I want to split a dataset recursively according to one of its attributes (attVal) and based on others datasets attributes values like the following : Given the ...
2
votes
2answers
67 views

Basic command-line calculator

Its an Basic Calculator I worked on, and now I wanna know if I can make something better like not so "much" Code or I made somthing to complicated? Have a nice day! Keep safe! ...
1
vote
1answer
36 views

Android APP user registration page implementation

This is a follow-up question for Android APP User class implementation. I am attempting to build a user registering system and this post shows the user registration page implementation. The ...
2
votes
3answers
106 views

Java logger (of doom!)

I wrote my own logger, but I dislike how many times I overloaded the log() function. If anyone knows of another way of doing that, feel free to share. ...
2
votes
2answers
4k views

For an array, check if an index exists where the sum of the elements to the left of it is equal to the sum of the elements right of it

Problem Extended from this HackerRank problem. Given an array A of length n, determine if there exists an element in the ...

1
2 3 4 5
211