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
1answer
24 views

Reduce Optionals to throw an error once

I have the following response coming from a rest call and performing some logic based on what is returned. This is what I want. If the overall status code is NOT 200 OR If within the list of ...
-3
votes
0answers
34 views

Snake doesn't move in Java snake game [closed]

I have just started learning Java last month and started the java snake game program. I need to write a java snake game where the snake grows when it eats an apple, and dies when it touches itself. ...
0
votes
0answers
13 views

Callback Url example with Okhtp [closed]

I have two rest application say a1 and a2 which is running on different containers. From a1 application i am calling the service exposed by a2 application for some processing. I am using okhttp to ...
4
votes
3answers
67 views

Create a list of assignments

Develop a program to maintain a list of homework assignments. When an assignment is assigned, add it to the list, and when it is completed, remove it. You should keep track of the due date. Your ...
0
votes
0answers
15 views

converting iteration of maps to streams [closed]

I need help refactoring the following code using something simpler: ...
-2
votes
1answer
66 views

Refactoring existing code with some design pattern [closed]

I have the following code, like a git command line system with various supported parameters and commands. But as can be seen, it involves a lot of if-else conditions which It doesn't seem that clean ...
1
vote
1answer
39 views

Producer/Consumer Multi-Thread implementation - Is the solution correct?

I recently faced this following question in a Java coding round, needless to say I did not get a callback. So I want to know where I am going wrong in my solution and also what can be done to improve ...
1
vote
2answers
48 views

Grade Statistics

I'm learning Java in a MOOC right now and this is my solution for exercise grade statistics. This is the exercise: In this exercise we create a program for printing statistics for points in course. ...
-2
votes
1answer
134 views

Fastest string search algorithm invented by me. It is called ""Choudhary String Search Algorithm""

I have invented the fastest string search algorithm. It is called ""Choudhary String Search Algorithm (choudharyStringSearchAlgorithm)"". I have compared my algorithm with Brute ...
0
votes
1answer
39 views

Objects for a face book

Consider the following two classes: ...
1
vote
2answers
55 views

Given an integer N, returns the smallest integer greater than N, the sum of whose digits is twice as big as the sum of digits of N

Write a function: class Solution { public int solution(int N); } that, given an integer N, returns the smallest integer greater than N, the sum of whose digits is twice as big as the sum of digits of ...
0
votes
0answers
41 views

Converting Audio Bytes to Array of Floats for Visual Representation

I'm trying to write a Java function that will take a byte array (of PCM audio recorded on Android) and return an array of data of floats that is intended to be used to create a visual representation ...
-1
votes
0answers
28 views

Mergesort unstable as Implemented? [closed]

I just had a realization about Mergesort possibly being unstable depending on how it is implemented while reading this post. Would the merge method below lead to an unstable algorithm? ...
0
votes
1answer
34 views

Safely and Quickly Trim a Byte Array of Audio in Java

I'm trying to take a raw byte array of audio and trim it. The user selects a start and end value using a range slider. ...
0
votes
0answers
17 views
-1
votes
1answer
36 views

Search in circular sorted martix

The method is given NxN matrix always powers of 2 and a number,it will return true if the num is found example for 4x4 size: ...
-1
votes
0answers
33 views

Console for Java JAR programs

When you run a jar file by double-clicking on it, you don't get console so all your input/output have to be on GUI. This program solves this problem and gives users/programmers a console which can be ...
0
votes
0answers
22 views

Quicksort Invariant and steps to determine correcteness

I am having trouble with applying to 3 steps needed to proof correctness, most likely because I did not formally study CS or Mathematics and am still learning about loop and class invariants. The ...
1
vote
0answers
30 views

Examples of many Java swing components in one program

This is in continuation of my previous post for code review of Java Swing Library: Java Swing Library Since the limit on total number of characters is 65K, I split my program in two parts. The first ...
0
votes
1answer
34 views

Java Swing Library

I have implemented a library which makes Java Swing programming easier. I am just posting the library. There is a program that uses this library to implement examples of many Swing components but I ...
0
votes
0answers
44 views

finding a value in circular two dimensional array [closed]

given a number and two dimensional array the method will check if the number is in the array the array is quadratic circular size n x n and each quarter of the array contains bigger numbers that the ...
3
votes
3answers
99 views

Find smaller angle between minute and hour hands of clock

In this code the angle between the minute and hour hands of an analog clock are found and calculated and the smaller angle between them returned. This code works perfectly and I am getting back the ...
4
votes
2answers
788 views

Method for create a copy of List<T>

I created a method to return a copy of List<T>, basically I convert the List<T> into an array ...
0
votes
1answer
71 views

Find the minimal distance between two values in an array [closed]

Given 2 values and an array, I must return the minimal distance between the indices of both values, as efficiently as I can in terms of run time and space. This is my solution: ...
3
votes
1answer
71 views

IOSP Kata: merge two sorted arrays without iterators

I wrote the code below as a Kata to practice the Integration Operation Segregation Principle (IOSP, clean-code-developers.com). I would like to have some feedback ...
2
votes
1answer
86 views

Finding better logic for addition and removal of Nodes in a Linked List

Consider the following piece of code I wrote (a templated Linked List): ...
0
votes
1answer
85 views

Convert month name to numeric string

This code converts a 3-letter English month abbreviation to its numeric equivalent (as a string). ...
0
votes
2answers
112 views

Java class loader for new instance

I at one time used class forname newinstance but newinstance is deprecated. I wanted to be able to pass a class name as a string and be able to load a class, so I came up with: ...
1
vote
2answers
59 views

my idea of validating data and bussiness logic

I'm experimenting with some variations of validation pattern. I've created Validator class: ...
4
votes
3answers
665 views

Find vowels count in each given country names using Java6 and Java8

I am trying to use Java8 for a piece of code which I had written in Java6 and am able to achieve the result using both the version of java but I am thinking there could be more better way to write the ...
-1
votes
1answer
41 views

is my Prim's MST implementation terse enough?

I did research because I want to learn Kruskal's and Prim's MSTs. I did research and after a solid understanding, I went to my textbook and got their libraries: https://algs4.cs.princeton.edu/code/...
3
votes
2answers
102 views

pattern matching coding challenge

I have implemented a simple pattern matching for the below algorithm in Java with time complexity of O(n)(n is the size of the input array). Any suggestions for optimization?? one of the most ...
1
vote
1answer
63 views

My Android app is really slow when getting simple data from PHP

I have a PHP API which echoes some data depending on the parameters in the URL: URL = "MyWebsite.com/MyAPI.php/username/password" When I try to access this API with Postman, I get the ...
2
votes
1answer
63 views

Merging and sorting queue/list implementation

My requirement is implementing a Queue<T> (where T is a Lexeme) that is capable of ...
2
votes
1answer
53 views

synchronized access to HttpSession attribute vs static ConcurrentMap with HttpSessionListener

As a part of library implementing websocket Guice scopes I need to maintain an object related to each HttpSession called ...
5
votes
4answers
350 views

Fastest function to find cumulative largest perfect squares of a single number?

I'm attempting to write an algorithm that will find the largest perfect squares of a given integer, subtracting their values from the total each time, as fast as possible. It's somewhat hard to ...
2
votes
2answers
56 views

Java BMI Calculator [closed]

I'm learning java this week. Please reviews my code for BMI calculator using java, need some your feedback. Thanks before! This Assignment: My code ...
0
votes
1answer
47 views

Recursive DFS to find Euler Cycle

I have referred to this for what constitutes as an Euler Cycle: https://xlinux.nist.gov/dads/HTML/eulercycle.html This assignment required me to use Depth First Search and have the methods I have ...
7
votes
7answers
2k views

DnD Die in Java with regex

For my game I need to roll some values with a die. A die is formally described as: nDs[+a] n amount of die (optional, 1 of not set, zero must be set explicitly) D ...
1
vote
3answers
68 views

I'm printing an "animated" ellipsis into the console but the code is incredibly clunky and repetitive, can I condense it somehow?

I'm at an intermediate-ish level in java programming in school (using repl.it), and I have a math related project I'm working on. After the user inputs their own measurements, "calculating.......&...
0
votes
0answers
40 views

Swap MIN, MAX object in a list

I have a List of Car with 2 props are String and Integer like this: (A,6) (B,2) (C,9) (D,17) (E,8) (F,17) (G,2) and the result look like this: (A,6) (D,17) (C,9) (B,2) (E,8) (G,2) (F,17) Purpose: Swap ...
3
votes
1answer
63 views

A controller for a Game Service

I have a Spring MVC controller but I'm not sure that it is a good or bad design. As far as I know, api versioning is missing but apart from that I implemented Swagger for documentation and added ...
1
vote
1answer
42 views

Removing a string element from an array when the array is set to 100 but only contains and prints the elements a user enters [closed]

first time posting here, as well as being new to coding in Java. I am trying to create a movie queue with an array that is able to contain 100 elements, but will only read and print the elements the ...
9
votes
1answer
197 views

Minesweeper implementation java

I'm writing Minesweeper implementation in Java. I have little experience yet, so I need some advices: about improving code, making it more readable and flexible about coding style about common ...
3
votes
2answers
64 views

Search code that performs in-memory search

This is the code I came across in our repository. This performs search in-memory and is invoked on service layer code. In our front end operators like EQUAL_TO and ...
1
vote
0answers
20 views

Connection pooling service using PoolingHttpClientConnectionManager

I created a service for Connection Pooling. And PluginAuth Class will handle those transaction to be send in the server. Is my code structure correct? ...
3
votes
3answers
614 views

Split List<String[]> into List<List<String[]>>

We have a list of string arrays i.e. List<String[]> (which we got from a csv) which follows the hierarchy: ...
1
vote
1answer
68 views

Get Interval by specific value from List using JAVA 8

First let's introduce the problem: I have a list like [{10,18}, {19,25}, {26,50}] and i have an input (n), when (n) inside one of objects in a list i will get this ...
5
votes
4answers
959 views

Check if time intervals overlap using integers

I need to check if times A cross with times B using integers and a 24hour clock. Times that are the same don't count as crossing, but meeting. For example: 16, 20 and 14, 18 (startA, endA and startB ...
0
votes
0answers
25 views

Java database connection and DAO implementation feedback

First things first, I made a DatabaseConnection-class which connects to the database like so: ...

1
2 3 4 5
214