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
2answers
108 views

Determine if the student has passing grades

I made a program in Java that asks for the student's name, course, and grades. After the required text inputs are filled, the program will then show the result. If the student passed, the program will ...
4
votes
1answer
280 views

Java Temperature Converter

I have made a program that converts Celsius to Fahrenheit and Fahrenheit to Celsius. How is my code? ...
-2
votes
1answer
95 views

Programming challenge - report fraudulent banking activity times out

How can I optimise this code there is time out error Program Challenge: HackerLand National Bank has a simple policy for warning clients about possible fraudulent account activity. If the amount ...
3
votes
0answers
47 views

Traversing a binary tree using a Node interface and an abstract Traverser class using a strategy pattern for order

I have written this code for depth first tree traversals. It feels like a lot of boilerplate, and I want to refactor it to remove this boilerplate. However I haven't done a lot of refactoring before, ...
4
votes
1answer
59 views

Calculator console app in Java

Here is my source code for my very first app in Java. I am completely new to the language; any help and criticism is welcomed! ...
3
votes
2answers
73 views

Set default value for remaining size of list by use of Java 8 and Stream

I have written a method which will return the size 16 List every time. If the input List has size less than 16, the remaining list object will be filled with default values.  Is there any way to ...
2
votes
1answer
54 views

Simple Playlist Editor/Player

I am starting with Java and at the beginning I would like someone to catch what mistakes I make. I would like my code to look its best and I want to learn good Java writing habits. Could anyone ...
3
votes
1answer
49 views

Checking inactivity with periodic tasks in Java

I have created a simple HealthCheck service. I have two approaches: Create a task canceling the previous one if the system is active, rescheduling the new task. Create a periodic task and regularly ...
6
votes
5answers
642 views

Enhanced Hashmap - Add a number to all keys/values

I had the below problem in a coding test and I got 28/30 tests passes and 2 failed due to a time-out. Problem You have created a programming language and now you have decided to add ...
3
votes
2answers
79 views

Tic-Tac-Toe in Java

I am currently learning Java; I could really use some help from more experienced programmers. How can I clean up my Tic-Tac-Toe code? What mistakes have I made? Can I use more exception handling? I ...
3
votes
2answers
90 views

Java Reflection-based CSV Parser

I'm an experienced Java developer, however I don't have experience with reflection or Annotation classes. For fun, I tried to develop a CSV Reader class which can parse each row into a particular type....
1
vote
1answer
47 views

Renaming and deleting video file

I am using below code to rename and delete video. Need review for the following: Code optimization Performance Overall code review ...
7
votes
4answers
2k views

If/else produce code duplication

I have the following class: ...
2
votes
1answer
69 views

LeetCode 146: LRU Cache III

I'm posting my Java code for LeetCode's LRU Cache. If you have time and would like to review, please do so. Thank you! Problem Design and implement a data structure for Least Recently Used (LRU) ...
2
votes
1answer
44 views

Reviewing the file download controller in spring rest

In my project, so this controller is working perfectly, my objective is to read the log file from the server which is created on daily basis, so I have to read the log file which is heavier in size ...
4
votes
1answer
64 views

Webscraping tennis data 1.1

I incorporated the substantial changes suggested in my previous question that involved building a web-scraper for gathering tennis data. The improved code is shown below: ...
5
votes
1answer
74 views

How to merge two descending singly linkedlist into one ascending linkedlist using Recursion without any helper method?

Here is my solution: I want to know if my solution fits the requirement 100%? Or if there is any better solution? Constraint of the question: must be singly linkedlist must use recursion, and no ...
3
votes
1answer
194 views

Hackerrank problem: Climbing the Leaderboard (Java)

I am solving the following Hackerrank problem: Climbing the Leaderboard. The problem statement: Alice is playing an arcade game and wants to climb to the top of the leaderboard and wants to track her ...
0
votes
3answers
127 views

Fastest way to create random pixel image

I want to create a very big gigantic PNG image. The image pixel are generated randomly, being How can I improve the below code to create a fast random pixel image in java? ...
1
vote
0answers
25 views

Multiple functions to run SQLite queries and save the output to a variable

I am building an Android quiz app. I want to display a progress bar showing how many questions a user has answered correctly and how many they have left. Questions are split by difficulty level; easy, ...
8
votes
1answer
131 views

Webscraping tennis data

So as a starter Java project I decided to web scrape some data (specifically all historically No. 1 ranked players for weeks starting from 1973) from the ATP website, and do something with it (IPR). I'...
3
votes
1answer
199 views

Meme (title with picture) exchanger

Project structure without code: Packages: Classes in packages: In ConfigConstants I store path to folder, where I save pictures. Also in ...
4
votes
1answer
94 views

Minimax based Tic Tac Toe

I am attempting to make an unbeatable Tic Tac Toe game using a simplified minimax algorithm. The code looks like this: ...
2
votes
0answers
99 views

LeetCode 218: The Skyline Problem II

Here I'm posting my Java code for the skyline problem. If you have time and would like to review, please do so, I'd appreciate that. Problem A city's skyline is the outer contour of the silhouette ...
2
votes
0answers
148 views

LeetCode 767: Reorganize String

Here I'm posting my code for the Reorganize String problem on LeetCode. If you have time and would like to review, please do so, I'd appreciate that. On LeetCode, we are only allowed to change the ...
4
votes
1answer
98 views

Bank with factory method for accounts, multithreaded deposit and withdraw

I have a couple questions about this program Should I implement runnable instead of using thread class? I like the idea of the consumer and producer being thread objects, it seems simpler to me, but ...
2
votes
1answer
51 views

Command Line app for calculating payroll in Java

I had an assignment last semester to program a payroll app utilizing methods. I went back to it and re-wrote it to include an extra class as well. I would like some feedback regarding whether my code ...
-4
votes
1answer
47 views

Time limit exceeds in this simple program [closed]

Link to problem: https://www.codechef.com/JUNE20B/problems/EVENM Iam trying to solve a simple problem challenge, but getting TLE. I had a different approach earlier, so tried this, again with no ...
0
votes
1answer
96 views

LeetCode 76: Minimum Window Substring - Java

I'm posting my Java code for the Minimum Window Substring. If you have time and would like to review, please do so, I appreciate that. Problem Given a string string...
1
vote
1answer
51 views

Maximum subset sum with no adjacent elements

Write a function that takes an array of integers (Both Positive and negative) and return the maximum sum of non adjacent elements. Note that even if all values are negative, I don't have an option to ...
1
vote
1answer
115 views

LeetCode 560: Subarray Sum Equals K - C++/Java

According to LeetCode, the following question is one of the most frequent interview questions asked by companies such as Facebook and Google. Here, I'm posting C++/Java codes, if you'd like to review, ...
4
votes
1answer
108 views

Hamming distance implementation in Java

I'm exploring String relativity and comparison techniques, and I found Hamming distance algorithm in my search so I give a try to implement that approach in Java and below I'm sharing my ...
-3
votes
1answer
84 views

Java xPath: simple expression evaluation [closed]

This code is using XPath to expose a library function that can check whether an XML file contains a string or an expression: ...
1
vote
5answers
789 views

LeetCode 1: Two Sum

This is an easy level LeetCode question, obviously not much code to review. I'm posting C++/Java/Python here. If you'd like to review, please do so. Thank you! Problem Given an array of integers, ...
1
vote
1answer
58 views

How to break my code into subroutines? - Java

I have written a code for data management and parallel arrays but it has to be broken into methods/subroutines. Whenever I try to do so, some aspect of my code stops working. Would it be possible for ...
1
vote
2answers
72 views

Overriding static method with different static variable in java [closed]

Suppose I have 3 classes, Animal, Dog, and Cat ...
5
votes
2answers
126 views

How to optimize Karatsuba algorithm (using arraylist and java)

I was using Karatsuba algorithm to multiply two polynomials and return the coefficients and I am using java, we are asked to use arraylists here, however, my code is too complicated and it takes much ...
5
votes
1answer
73 views

Count of request per second, minute in java

I want to count number of requests per second, minute. I want do it fast and thread-safe. I have 2 variables to count: ...
1
vote
2answers
143 views

How to efficiently find if numbers in a given range contains either 1 or 3, but not both?

I am having a trouble speeding up my implementation. The question is, given a range of numbers from long a to long b, find how many lucky numbers are between a and b inclusive. A number is a lucky ...
1
vote
1answer
82 views

Sum of all Paths in Binary Tree

Problem For the given binary tree return the list which has sum of every paths in a tree. i.e Every path from root to leaf. I've written following solution. ...
2
votes
2answers
90 views

Console dice game

I wrote a simple dice game with the purpose to practice arrays and classes. I would like some critique on my code structure and quality - as well as thoughts on my thoughts to improve it. Here's the ...
1
vote
0answers
72 views

Kosaraju Algorithm in Java

Problem statement In simple words it say, count total Strongly connected components in the graph. All edges are undirected. I have the following code that uses ...
1
vote
0answers
46 views

Flatten nested lists in Java

I'm developing a complex app with Spring Boot and MongoDB. I have a Video class like the following. Note: All getters setters are omitted. ...
1
vote
1answer
41 views

Encasing a string in double quotes

I need to add some characters to a String before using it for an API call. The idea is to add a " char both at the beginning and at the end of the String, to make ...
4
votes
2answers
182 views

Java: Conway's Game of Life

I have just finished implementing a version of Conway's Game of Life using Java. Being only a college student, I am sure that my code is no where near perfect, and was wondering if you could look at ...
6
votes
2answers
194 views

Fleissner-Grille / Turning-Grille

Background About the Fleissner-Grille The Fleissner-Grille is a really easy possibility to encrypt text. You just have to take a grid of size n*n with (n*n)/4 holes (example). You then just write ...
2
votes
0answers
44 views

Generic Graph Traverser

I have built this Generic Graph traverser, I have this implemented with DFS, I feel it will work equally fine with BFS too. What do you think of this implementation? I want help in reviewing the <...
4
votes
1answer
55 views

command-line demo app

I started learning from the book: head first design patterns. As I am trying out different programs in the book, I am compiling them in this one demo app. Below is the code for its driver function. ...
5
votes
2answers
83 views

Sorting squares of an integer array

I had this question in an interview recently. Given a sorted array of integers, return a list of those integers squared, with the squares sorted. So given an array of these numbers: ...
4
votes
3answers
894 views

Student Grade Calculation

Develop a smart application as Student Grade Calculator(SGC). Create a class Student with following private attribute : int id, ...

1
3 4
5
6 7
206