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.

693 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
2
votes
1answer
96 views

Stopwatch utility class in Java

Looking for input on my code for a Stopwatch utility written in Java. ...
2
votes
0answers
64 views

Color picker using WritableImage in JavaFX

I am making my own JavaFX color picker just for learning more about JavaFX. I am rendering a color wheel in JavaFX using WritableImage and I have a ...
2
votes
1answer
76 views

Determine whether a word appears in a sentence

Given an array of words representing a sentence and a word to search for, the method must determine whether the word appears in the sentence. Specifications Case insensitive. The arguments are never ...
2
votes
0answers
144 views

Mouse wheel scrolling for nested scrollable Swing components

By default, mouse wheel scrolling in Java Swing behaves differently than in web browsers. In Swing, when you have an inner scrollable component and an outer scrollable component, the mouse wheel ...
2
votes
0answers
77 views

My first Java app: a calculator in Swing

I have created my first Java app. I am very familiar with C++ and thus without reading any books (just introduction, googling and IntelliJ auto-completion) I directly jumped into Java. So I made a ...
2
votes
1answer
36 views

Printing all the combination of indexes for 2 sum exact outcome

Can somebody review the code and provide suggestions on where I can improve on the code like use of better data structure etc. Input: {1,7,2,8,3,6}, 9 Output: [0, 3] [1, 2] [4, 5] ...
2
votes
1answer
98 views

Calculate arithmetic expression represented by a string, in Java

I saw that interview question online and gave it a try: Implement a function that gets a string which represents an arithmethic expression: contains only numbers or the the operators: '+', '-', '*', '/...
2
votes
0answers
108 views

Object Oriented design for a live auction taking in bidders

My goal is to design an Auction that will take in data like this: ...
2
votes
1answer
199 views

Helper class for Fragments management

A Helper class for Fragment Management. The FragmentsManager class has methods to add and replace fragments. The replace method checks if the given fragment is present in backstack or not and if the ...
2
votes
1answer
583 views

Simple Java OOP calculator with GUI

I'm learning Java and I've tried to write my own calculator with GUi based on this post. Here is the repo: https://github.com/MurDaD/java-calculator Could someone check my code and tell me how to ...
2
votes
1answer
62 views

Enforce printing sequence using wait() and notify()

This is a follow-up answer "implementation" to a question I posted on SO. For the sake of convenience, I will repeat my intent: I want one thread (called sub-thread) to print 10 times under outer-loop ...
2
votes
0answers
35 views

Comparing performance of multi- and single - thread search of a maximum number

I have a class that compares the performance of two methods (multi- and single- thread) that searches for maximum number in the string of numbers. I want to improve the performance of a multithreaded ...
2
votes
0answers
170 views

Longest Palindromic Substring challenge

My code is a mix-up between dynamic programming with the HashMap and brute force with the way I reach out the results and substring. I don't know how to optimize my ...
2
votes
0answers
65 views

Yoga Android app

I have created a yoga app on Android Studio. Can someone review the code to see if I have used the best practices of programming? MainActivity: ...
2
votes
0answers
66 views

DFS logic to traverse a graph

I tried to literally convert recursive algorithm taught here to iterative, by simulating the recursive stack exactly as much as possible. I have tested my code and it passed all test cases. Please ...
2
votes
0answers
540 views

Create HttpClient using PoolingHttpClientConnectionManager

I have a java service class which will call a REST service and get response back. It is working fine in developer environment where less requests are made, but I still wanted to get a review. My ...
2
votes
0answers
58 views

Classical Single Pivot QuickSort implementation in Java using Generics

I have coded the following quick sort implementation. There are few things that still makes this code ugly and redundant. 1. Handling Arrays of Primitives I have to write a separate implementation of ...
2
votes
0answers
34 views

Wait until thread is stopped from within thread

This is an abbreviated version of a serial receiver that can be started and stopped like a resource. The idea is that a thread will listen to an InputStream and ...
2
votes
0answers
78 views

Java GUI application for selecting players

I have automated a small task. My application is a windows based application. I was using Java language and worked with Winium tool. I have to select players from the GUI and there is a scroll up and ...
2
votes
1answer
2k views

Check for timeout in wait() loop

I want to check for a condition in a guarded wait() loop with a user-specified total timeout, similar to how ...
2
votes
0answers
95 views

Tic Tac Toe game becomes more inefficient as time goes on

I designed a tic tac toe using 4 classes. The game class being the main class, the board class being the board, the player class being the decision making, and the AI class keeping the previous game ...
2
votes
0answers
35 views

Using a Queue of Supplier<Boolean> to control flow

I have a sequence of methods which should only be called if the previous returned successfully. If a method is successful it returns true, otherwise it returns false. Please tell me what you think of ...
2
votes
1answer
2k views

Accessing Adapter data from ViewHolder

In my Android app, I need to disable a button in Layout if the api return status as 0. I get this status in the Adapter and based on it, I have disabled the button in ViewHolder which is inflating the ...
2
votes
0answers
35 views

Security exceptions

I'm trying to configure security exceptions to all JavaScript/CSS of my pages. I need to login to access the JSP files, except the login page, but all pages needs ...
2
votes
0answers
51 views

Implementation of MVC pattern for single and multiple objects

I've implemented a student administration with MVC pattern (Tutorial: Link). I've decided to divid the students in "SingleStudentModel" and "MultipleStudentModel", but I'm not sure if that make sense ...
2
votes
0answers
74 views

Classes for shapes and development

Task You should create an abstract Shape class that contains the stuff that would be similar across all shapes, and change Line and Rectangle so that they extend Shape. Then, in the DrawingModel ...
2
votes
0answers
116 views

Throttle submissions to ExecutorService

To prevent an XY problem, I'll first explain the problem I am trying to solve: Problem I am trying to solve I want to send the contents of a MongoDB collection with a size of around 3 million ...
2
votes
0answers
37 views

XML Input Parser To Load Test Data into Dev Database

I wrote an XML input transformer to ingest data from test directory and essentially store anything into a DB table. I attempted to make this as generic as possible. I'm new to Java and also realize ...
2
votes
0answers
43 views

Shortest path via intermediaries

Created a shortest path finder that must pass via sets of intermediary edges (either one in each set counts as a pass) in order. Primarily I would like to know if there are logical fallacies in the ...
2
votes
0answers
133 views

Unit/Integration Tests for Maven plugin that creates Skipper packages

I am writing an extension to a maven mojo (spring-cloud-skipper-maven-plugin) and I am now writing tests that interact with a skipper server. However, getting the ...
2
votes
0answers
216 views

Show mobile SoundCloud player in WebView

Demo for a SoundCloud player in WebView for specific song or artist stream as a workaround because SoundCloud is not accepting API key request anymore. SoundCloudWebView: ...
2
votes
0answers
447 views

Three sum using binary search

Given an array and a value, find all the triplets in the array whose sum is equal to the given value. For example, if the given array is {12, 3, 4, 1, 6, 9} and the ...
2
votes
0answers
49 views

Write one string to a socket within 10 seconds or another string if the time is out

I have implemented a method which will send one data to the server if it (Raspberry Pi Pin Input HIGH, in this case) occurs within 10 seconds. If this doesn't happen within 10 seconds then I should ...
2
votes
0answers
132 views

Encapsulation of putpixel is terribly slow in JavaFx

I am trying to write a simple rendering engine in JavaFx and I manage encapsulate putpixel in the way that I pass x,y coordinates and color and it draws pixel of that color to the screen. I also wrote ...
2
votes
0answers
86 views

Computing most-cost effective loans in financial graphs using Java

Problem statement We are given a directed graph \$G = (V, A)\$, where \$V\$ is the set of actors and \$A \subseteq V^2\$ is the set of directed arcs. Existence of an arc \$(u, v) \in A\$ is ...
2
votes
0answers
143 views

Implementing a tabular pretty-print using Java 8 Stream API

About six years ago I implemented a simple tabular pretty-print Java class that mostly simulated MySQL CLI query result tables. I don't really like it because it was implemented in a, I believe, ...
2
votes
0answers
60 views

Iterating through every permutation of every subset

I have this code witch I use to iterate through every permutation of every subset in an array witch holds integers. One big problem is the efficiency of course, another problem is the fact that if I ...
2
votes
0answers
61 views

Initiate, propagate, validate, send, and marshal a message in Spring

Purpose of code The goal of this code is to: Initiate a message propagation to other systems Validate that the given message adheres to its XSD schema, and then marshall it Send it on a Camel route ...
2
votes
0answers
78 views

Biometric data representation in Java

This code represents biometric data averaged over a 1min period, beginning at the given UTC time. Please review my code: ...
2
votes
0answers
34 views

Optimizations for Knapsack with 3 dimensions

Problem Statement: I am given a set of prices for \$n\$ items I have to find out what is the maximum value I can get with \$M\$ money by selecting exactly \$C\$ items without exceeding the amount of ...
2
votes
0answers
97 views

Find a (nearly) optimal route among several locations that can be found by Google Maps

The README should give you all of the information you need for a comprehensive review, and if it doesn't then please say so. If you would like to contribute a review but do not have time or desire to ...
2
votes
0answers
1k views

Implementation of reactive file write from InputStream

I want to implement reactive write to file. In low level, it uses NIO and Futures. After reading this section I created this code but maybe there's more clean or less code solution. Thanks. ...
2
votes
0answers
49 views

Filter results on response

I call remote server to get my result. Result might contain artist,track and album depends on API method but there will be only one response (artist or track or album) at a time. It mean the other two ...
2
votes
0answers
97 views

Affine transformations in 2D space

During the past few days, I played around a bit with an SVG file, trying to minimize its size. One thing I stumbled upon was this transformation: ...
2
votes
0answers
217 views

Calling PL/SQL functions using JDBC in a Spring clone

I started to modify some old code and ended up creating a sort of spring jdbc framework. I know just the most popular design pattern, so I was wondering if my design was good. For example, to call ...
2
votes
0answers
351 views

Wrapper for sql.Connection

I wrote wrapper for Connection. It uses my Connection pool implementation. When the wrapper closes, the connection goes back to pool. ...
2
votes
0answers
468 views

Flattening a map into a list of records

In my everyday work I'm trying to move away from traditional iterating over collections to a more Java 8 streams-like behavior. I'm currently working on a project where I have a collection defined as: ...
2
votes
0answers
65 views

Scala code that loops through Java annotations decorating Scala classes

I have code written in Scala that reads annotations decorating other Scala classes. These annotations are written in Java. The sticking point is that annotations don't allow advanced data structures, ...
2
votes
0answers
283 views

Java Crypto library number of padding bytes using PKCS5Padding

I have implemented AES encryption in Java using the following function. What puzzles me is the number of padding bytes added using the PKCS5Padding method. For example, when calling the following ...
2
votes
0answers
80 views

Computing divisibility and multiplication

Please check my Java program to see if I use the global variables, nested loops and two functions with parameters correctly. I also need suggestions to improve my program. ...