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

AddressBook help needed

I new person in the java world. I began my adventure with java one month ago. I trying create my own address book where I can add, edit, search and delete contacts. Right now I was stoped because don'...
2
votes
1answer
20 views

moving player right or left depending on swipe

In my Player.java class, I want to incorporate a function that moves my player according to the left or right swipes. I also used time in seconds in order to vary the movement in an cyclic way: ...
-2
votes
0answers
15 views

Edit and delete contacts - address book in java [closed]

I new person in the java world. I began my adventure with java one month ago. I trying create my own address book where I can add, edit, search and delete contacts. Right now I was stoped because don'...
-7
votes
0answers
23 views

How to find the index position of last occurrence of a given value in an integer array? [closed]

Below is the example what I'm trying to get. Integer array: {1, 2, 3, 4, 5, 1} Value: 1 Output:...
2
votes
0answers
27 views

String Permutation

Below is my permutation function and I'm looking to make it more elegant and efficient if possible. The function should return a string which includes all the permutations of the given string (...
1
vote
0answers
32 views

Java - parser for html-table

I wrote a program that saves the data from the first table of this wikipedia-article (in german) and then saves the column "Gesamt" (contains daily update of absolute numbers of Covid-19-infected ...
-6
votes
0answers
30 views

health care managment application using java enums [closed]

Write a Health Care Application in which use an enum to store the available doctors with attributes name, consultation fee and specialization. Ask the user to enter the patient_name, age and create ...
3
votes
1answer
58 views

Building an email generator using abstract factory pattern

I'm trying to build a customer email generator in java using the abstract factory pattern. I understand how to use the factory method pattern; however, I'm a bit confused about the abstract factory ...
4
votes
2answers
193 views

Reader for graph-file with ugly return and questionable use of streams

I wrote a class that contains a static method that reads in files from NetworkRepository and converts them into a list of integer-arrays, each representing an edge. The file format from ...
3
votes
1answer
30 views

I need to know that if everything okay in my BTS put and get method

I implement BinaryTree (K extends Comparable, V) concept to binarySearchTree and I have written get and put method. As far as I check, there is no problem in my code. So now I wonder that are there ...
2
votes
2answers
37 views

Does iterating through a large data set in a Map each time i click impact the performance?

I need to get values from a Map by Adapter position i get from a RecyclerView. As you can see each time i click on an Album Art i create a new array of album objects. ...
0
votes
1answer
43 views

How to Unit Test a Thread which has an infinite loop? [closed]

I wanted to be sure the thread being tested would complete its job by the Assert statement of the unit test, but I couldn't be sure bc of the way I designed the threads. I designed them to run forever ...
2
votes
1answer
42 views

Iterator-Pattern for an iterator that returns one objects that changes

I wrote an algorithm that returns all k-sized subgraphs of another given graph. Because I don't want to make the runtime of the next() call of the iterator depended on k, I don't want to return a new ...
4
votes
2answers
57 views

Builder design pattern pass object

Good Morning This is a builder design pattern .. the builder problem is duplication so I want to know from an expert with explanation which is better on quality on this code: (1) ...
-2
votes
1answer
25 views

How would you resolve paths according to given uri formatting? [closed]

Currently, I do this with the following. ...
-4
votes
0answers
16 views

Pixel Tinting: Can I reset the color variables so my colors come out correctly? [closed]

I am having trouble with this part of my assignment; here are the instructions: Part 4: Animate! Make an animation of your headshot that goes "psychedelic" 3 times, then goes "Dutch", and then slowly ...
0
votes
0answers
46 views

Anonymous class and interface, returning a List

I have a main that call the method genericQueryFromTable, that return a list of objects that are modified by an interface ...
-6
votes
0answers
35 views

How do I write a float function that accepts float n and returns the floor of n without using java.lang.Math? [closed]

I tried converting n to an int, and somehow it worked. static int floor(float n){ return (int) n; } Is this okay?
0
votes
0answers
32 views

Verifier for multi-purpose scripting language

I rewrote a compiler project right now containing semantics, parser and verifier, in Java. Links: source code, language overview. The language is familiar for ECMAScript. As an example, the verifier ...
1
vote
2answers
63 views

integer log base 10 function without using java.lang.Math?

I am assigned to a task of creating a function int logBase10Estimate(int n) that returns the log of a number base 10. The answer is integer part only.(w/o using the Math class) Is this okay? ...
-3
votes
0answers
17 views

It create a file but no data inside [closed]

I've view several solution by adding flush(), but the problem still not solved. The code function in I'll add data after clicked on jbutton1, and print the file by clicking jbutton2 ...
0
votes
0answers
29 views

Block Bootstrap Estimation in Java - Part 3

This is an extension of Block Bootstrap Estimation in Java - Part 2. The text file text.txt can be found at https://drive.google.com/open?id=1vLBoNmFyh4alDZt1eoJpavuEwWlPZSKX (please download the file ...
-4
votes
0answers
17 views

Spring - on validation failure of the form the list built on model object renders empty [closed]

I am learning spring from Sping in Action 5th edition by Craig Walls. I have searched the internet for the issue but did not land at any solution. Issue: ...
2
votes
0answers
41 views

JWT authentication system login through API

This is my first time writing an authentication system. Here's how it works, first client needs to send credential within authorization header like { Authorization : 'Basic ' + credential } through ...
7
votes
2answers
234 views

Extracting all nouns, verbs and adjectives from a large text dataset

For a project I am using the yelp dataset (found here: https://www.yelp.com/dataset) to create a Hashset of all verbs, nouns and adjectives found in the restaurant reviews. I have it up and running ...
2
votes
1answer
61 views

Block Bootstrap Estimation in Java - Part 2

The following is my attempt at parallelizing (I learned about parallel computing over the last weekend, so I'm very new to it) and making more efficient the code in my previous question Block ...
3
votes
1answer
56 views

System generated Social Network

In a particular social network friends are automatically allocated to users by the system and users cannot add friends of their choice on their own. There are currently N users on the social network, ...
2
votes
1answer
66 views

LRU Cache Example

Please check the following the LRU cache implementation. Thanks for the valuable comments ...
7
votes
3answers
555 views

log_e approximation

The natural logarithm can be approximated by the following formula: $$ln(x) = 2\sum_{k = 0}^{\infty}\frac{(x-1)^{2k+1}}{(2k+1)(x+1)^{2k+1}}$$ I've implemented this formula using Java. Parameter <...
4
votes
2answers
110 views

Block Bootstrap Estimation using Java

The data are in a file called test.txt, which is available at https://drive.google.com/file/d/1g0ffvH5oP5C4Cp6ciEp_L1Rst6WeTuYG/view?usp=sharing. There are some odd ...
3
votes
1answer
54 views

Finding out the indices of common elements in two array lists having duplicate elements

I have two lists which are also having some duplicate elements , i am converting this list to map as key value pair with element index as the value for the key - element List 1 : [1, 2, 3, 4, 5, 6, ...
3
votes
2answers
89 views

Code for saving / loading a class object

As I was advised, I broke my code into 2 classes. Could you take a look at the repository class and report what problems this code has ...
5
votes
2answers
318 views

Creating and listing a song collection

Songs Class: ...
8
votes
3answers
833 views

Refactoring multiple boolean conditions?

I have a Predicate which takes employee object. Predicate<Employee> getPredicate() { return emp -> filter(emp); } Now the filter method is very ...
1
vote
0answers
43 views

Map of objects sharing characteristics [closed]

What I'm trying to achieve From a list of lists of elements (one element can be in multiple lists, but only once in each list), I want to generate a map whose keys are each elements and the values ...
4
votes
3answers
521 views

Using static final Strings for SQL Query in Spring Boot

This is regarding code quality and coding standards with respect to Spring Ecosystem. Here there are two methods: isRecordExists is using a class level static ...
0
votes
2answers
107 views

ProjectEuler.net problem #50, Consecutive Prime Sum

I am trying to solve ProjectEuler.net problem #50, Consecutive Prime Sum. Here is the problem: The prime 41, can be written as the sum of six consecutive primes: ...
2
votes
1answer
45 views

Parallel SQL queries using completable future

My problem is I'm having a table and 7 child table. I'm fetching details using querying the main table first then querying the child tables one by one sequentially. To improve performance I decided to ...
5
votes
1answer
259 views

Getting key-values for set of date ranges by calling different lib methods and using results to create DTOs

I have three methods that I need to call multiple times only varying the date parameter of each. The natural solution to avoid code duplication is to put the three methods in a loop and iterate over ...
2
votes
1answer
59 views

Spring boot loadbyusername

I have the following classes. I wonder if this structure makes sense in any terms especially the usage of the UserDetails class from Spring. Should I use ...
1
vote
0answers
50 views

Defensive Fluent Interface Implementation [closed]

Introduction At this moment in time, I'm in the process of creating some fluent interface, as a result, I've created a DSL style solution for authentication & authorisation. As a result, the ...
2
votes
1answer
34 views

Reading bytes between two quotes from a stream and decoding it to its appropriate character set [closed]

This is a component for a lexer which operates on a byte input stream that handles reading and decoding the contents of a string contained within double-quotes. The validity of the encoding is handled ...
-1
votes
0answers
38 views

Best way to optimize multiple search on Lists java

Anyone could help me to optimize this block of code, I already did a bit improvement but since I'm really bad with this kind of algorithms this all I've done so far. Much appreciate if you can explain ...
0
votes
1answer
42 views

Possible Test Cases in Tester [closed]

I am trying to write a human-readable tester for a functioning program. There are four methods in the class Polynomial: ...
5
votes
0answers
36 views

Implementation of Gitlab CI + Docker + Spring Boot

i would really appreciate if anyone could invest a bit of time to review what i did. Basically this is first time i do this, and that is reason why i need another set of eyes. I have Spring Boot ...
-4
votes
0answers
68 views

Given an array and an integer k, find the count of contiguous elements after k swaps

Given above the question of some codility challenge, I tried solution given below. Given solution passed all the given test cases but not passed performance test. Please help me to know where my ...
12
votes
4answers
3k views

Unit testing Video Service class

I wrote my first unit testing code on a service class using Mockito. The code looks like this: ...
2
votes
1answer
43 views

RemoteFile in Java - follow-up

(See the first and initial iteration at RemoteFile in Java.) I have added some new facilities for convenience. Now I have this in mind: com.github.coderodde.utils.io.RemoteFileDownloadListener.java: ...
0
votes
0answers
45 views

Code for creating a dialog for choosing a date

I have code that creates an AlertDialog to select a date by a user. I ran into a problem that this code began to take up a lot of space. Could you offer ideas on how to shorten this code / put it into ...

1
2 3 4 5
199