Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

0
votes
1answer
64 views

Generic Binary Search Tree Implementation in Java

There is an implementation of Binary Search Tree. This is kind of based on Set Theory that duplicates are not allowed but an attempt to adding the same node twice will replace the older node. BSTNode ...
1
vote
2answers
38 views

Generic Min Heap Implementation in Java

There is a Min-Heap implementation in Java. BubbleUp() and BubbleDown() could have been coded using recursion but I prefer without recursion. Would there be a major difference if had used recursion? ...
2
votes
1answer
82 views

Find out whether a given text contains any of the prohibited words

We have been given a list of strings which are blacklisted. The goal is to identify if a given text contains any of these blacklisted strings. The restriction here is that the blacklisted string needs ...
1
vote
3answers
87 views

Simple Publisher Subscriber in Java

I am new to Java and had some difficulty creating this simple Publisher Subscriber class. It finally seems to be working and I wanted to check if I have been following best practices and see if there ...
2
votes
0answers
37 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 ...
4
votes
2answers
264 views

Grade calculator for a project with four aspects

I have a program that will ask the user to input their grades for 4 different sections of a project, then tell them what their total mark is, what grade they got and how many marks away they were from ...
3
votes
1answer
122 views

Hackerrank “Almost Equal” solution

I've spent the best part of a day on this question. It is marked as Expert level. There are about fifteen submission test cases and my solution manages to satisfy the first four. However, from there ...
2
votes
2answers
91 views

Calculator to add time intervals

I have written a little program that calculates the time by given strings. A time string in the context of this program consists of a number and a following letter that can be s, m, h, or d. You can ...
2
votes
0answers
60 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 ...
3
votes
1answer
63 views

Insurance Premium Quote Challenge

I was failed at coding challenge for my interview with the following reasons given by the interviewer: deep use of mutation and a not that well thought up internal API. I understand that my code and ...
2
votes
1answer
192 views

CSV file download in Spring

I recently worked on a module, in which I implemented the functionality of downloading the CSV files. ...
1
vote
1answer
33 views

Adapter class to display songs in an Android ListView

I am learning Android with Udacity nanodegree (having no support) and this is my assignment of music app. It is just an interface and no music I have to add. So far so the app is running without any ...
2
votes
1answer
29 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] ...
0
votes
1answer
46 views

Java splitting too large text file enhance performance

I have a too large data.txt file containing data as follows: ...
1
vote
0answers
22 views

Sorting an array of numbers in Java with an algorithm

This is pretty much one of my first programs that I have created in Java and I just wanted to ask if anyone sees some obvious errors or mistakes I made. The purpose of this program is to sort numbers ...
12
votes
2answers
5k views

Rock Paper Scissors game using OOP

I'm a complete beginner to Java and we have just started learning objects and classes in school. I'm trying to create a very simple text-based Rock Paper Scissors game. I do realise that my code is a ...
2
votes
2answers
80 views

Calculating the Factorial of a number

I am looking for feedback for the implementation for calculating factorial of a number. I have tried to do with a loop, recursion and in a mutlithreaded way. ...
3
votes
1answer
133 views

Speed up Magic square program

I have written a Java program to calculate magic squares with recursion and backtracking. A 3*3 Magic square is calculated in about 1 sec, but a 4*4 needs about 50 minutes on my laptop with Intel i5. ...
3
votes
1answer
64 views

Card based game in Android

I am developing a card game in Android. This is my first time I am working in Android,. The game contains following features: It will be a 6 player game. There are two decks on the table, one with ...
2
votes
1answer
81 views

Java => Caesar Cypher

I already asked for help in optimizing a simple Caesar Cypher code in java here : Cesar code in Java I tried to implement all the advice from that subject and now I am asking again. Do you have any ...
0
votes
2answers
36 views

Printing the status of a database insertion as JSON

The controller is currently inserting a record into the database and returning a JSON response as shown below in the try-catch block. I can see the ...
2
votes
1answer
91 views

Robot Block Command

Problem We have a robot that can pickup blocks from a stash, move them horizontally and lower them in place. There are 10 positions available to lower blocks number 0 to 9. Each position can ...
0
votes
1answer
83 views

A Java Quadrilateral Inheritance Hierarchy - revisited

This is an exercise from Deitel&Deitel's "Java. How to Program (Early Objects)", 10th edition. 9.8 (Quadrilateral Inheritance Hierarchy) Write an inheritance hierarchy for classes Quadrilateral, ...
1
vote
1answer
47 views

Calculate the number of days passed from a given year

I have this code for calculating the number of days passed from a given year: ...
3
votes
1answer
37 views

Static class for database access Java JDBC

I'm writing a small program to store data in a database (a discord bot mainly). I know cleaner ways of using dependency injections and DAO exist, but I haven't written a DAO (or the user class) and ...
2
votes
1answer
73 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
2answers
43 views

I/O-TxtFile Line Distance Program

I am trying to write a lab/program that loops through a .txt input file. Reads an entire line of data as a string, then splits that string into an array delimited by a space. If there are 4 items in ...
0
votes
1answer
52 views

Binary Reflected Gray Code generation recursively

I tried to write BRGC recursively. I've really recognized that intrinsic of recursion helps for some problems in which I think BRGC is included. is the way I wrote it recursively adequate solution? ...
1
vote
1answer
38 views

Testing a service that makes database calls, without a database

I'm working on a new service, for the past year I haven't needed to write tests from scratch. I've either been bug fixing, or adding features that require modification of tests, but not writing ...
1
vote
0answers
30 views

Getting Video file path from uri

I am using below code to get a video file path from uri. Need review for the following: 1.Code optimization 2.Crash(Code is working fine in the devices I tested but i need to make sure that it ...
2
votes
2answers
89 views

Substrings search (Aho-Corasick algorithm)

I have a code where the goal is to give score to strings based on how much score certain substrings are worth (including repeating substrings). The way my code (which is based on the Aho-Corasick ...
1
vote
0answers
59 views

Language-detection heuristic (English, French or German) based on Unigram and Bigram models

Given a string, for example "I hate AI", I need to find out if the sentence is in English, German or French. Unigram Model makes the prediction on the basis of each character frequency in a training ...
5
votes
2answers
292 views

A novice student record system

I am an extreme novice in Java and thus trying to practise some online exercises. One of them involved creating a basic student record system. This is what I've come up with but I think a lot of ...
2
votes
2answers
109 views

Find kth smallest element in binary search tree

I was faced with below interview question today and I came up with below solution but somehow interviewer was not happy. I am not sure why.. Given a binary search tree, find the kth smallest ...
4
votes
4answers
188 views

Cards shuffling and dealing program

The program interacts between cards and four players among whom cards are to be distributed. The Program do the following function Creates a deck of cards. Shuffle the deck. Shows the deck. Deal ...
2
votes
2answers
102 views

My own expandable list

I wondered how an expandable list could be implemented. My first thought: You could create a class that has an array and you can create a new array each time the user wants to append an element and ...
0
votes
1answer
102 views

Parsing messages with fixed-width fields into Employee objects

I'm writing a application that reads from a queue of messages from a legacy mainframe system. Some characteristics of message in the queue: Message from the Q is always fixed length plain text : 64 ...
1
vote
3answers
131 views

Cesar code in Java

I am coding in java since some time but I was not always really organized about methods and commentaries, here is a quick code to use the Cesar code : ...
3
votes
1answer
55 views

Read a single int from an optional .properties file

I am no newcomer to Java. One thing that confounds me is why it is so messy to load values from .properties files. I have an application where, if the .properties file is found, then the value if ...
1
vote
0answers
31 views

Handling slow processing the Spring batch way

We are using spring-batch to extract data from a SAP system, during processing we pass the extracted full texts to a tagging service, in the end the enriched documents are stored in Solr to be served ...
1
vote
2answers
206 views

Using decorator and strategy pattern for dynamically generating SQL queries

This is a link to my application that actually runs on the design specified in the image. The idea behind the image is that the SubjectInfoViewer behaves as the ...
3
votes
1answer
102 views

“Counter Game” Powers of 2 Game

I have been working on this hackerrank problem: Louise and Richard have developed a numbers game. They pick a number (1 ≤ n < 264) and check to see if it is a power of 2. If it is, they divide ...
1
vote
0answers
27 views

Dijkstra Implementation: Comparing my program with widely available Internet Java program

I wanted to discuss Dijkstra's implementation that I generally find on Internet, and then compare it with my own implementation. On Baeldung and on Vogella (Thanks to both and many others, that I ...
2
votes
0answers
66 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
3answers
66 views

Printing a monthly calendar on console

This is an implementation of mine to an exercise found in the book Core Java SE 9 for the Impatient. Goal is basically to print a monthly calendar by accepting month and year information from the user....
0
votes
1answer
68 views
1
vote
1answer
40 views

Get the most frequent number and least frequent duplicate in array

This code gets the most frequent number and least duplicate number in an array. How can I optimize it and improve its performance? ...
3
votes
1answer
81 views

Checking whether given array is sorted by divide-and-conquer

I've written a code that I try to use divide and conquer approach to determine if the given array is sorted. I wonder whether I apply the approach accurately. ...
2
votes
1answer
29 views

Testing a probabilistic prime-testing algorithm that may fail

I have implemented Pollard's Rho algorithm in Java. Due to the nature of it there is a small chance for it to fail (have not seen it happening yet). Since I do not ...
0
votes
2answers
45 views

Merging K Sorted Linked Lists

Specifically, how can I improve the time complexity of my algorithm (currently it is O(listLength * numberOfLists))? It only beats 5% of accepted LeetCode solutions,...