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 byte-code and run in a virtual machine (JVM) enabling a "write once, run anywhere" (WORA) methodology.

learn more… | top users | synonyms (2)

2
votes
2answers
46 views

Let me fix thou number

Problem Statement: Write a program that cleans up user-entered phone numbers so that they can be sent SMS messages. The rules are as follows: If the phone number is less than 10 ...
6
votes
0answers
32 views

Game Tutorial in Java

I’ve been working on a Rampart inspired multiplayer game for a few weeks now, and it is finally in a playable state. The big thing left to do before going alpha was to add a tutorial to the game. I ...
4
votes
1answer
43 views

12/24h Time format converter

I am really new at this and I was wondering if there is a more efficient way of writing this code, which converts time format to 12-hour from 24-hour format, and vice-versa. For example ...
-1
votes
0answers
25 views

Calculating a string using stacks, Not getting the right answer [on hold]

If someone doesn't mind could they take a look at my code? For some reason, I keep getting the wrong answer when the logic seems fine to me. Mainly the solve is what is probably wrong, but if needed I ...
1
vote
1answer
54 views

Shortest path in maze

Please help review my code. ...
-6
votes
0answers
16 views
1
vote
2answers
52 views

Enum for converting between field naming conventions

Based on this question and this answer, I decided to try the enum approach to do some more conversions I need in my application. This time I required to convert between the different field naming ...
5
votes
1answer
40 views

Let's have a meetup

Problem statement: Calculate the date of meetups. Typically meetups happen on the same day of the week. Examples are the first Monday the third Tuesday the Wednesteenth the ...
2
votes
0answers
24 views

Comparing linear time strongly connected component algorithms in Java

So I have implemented three linear time (\$\mathcal{O}(V + E)\$) algorithms for finding strongly connected components of a (directed) graph. A strongly connected component is just a maximal subset of ...
3
votes
4answers
243 views

Checking if String has unique values

I have a small function which checks if the given String has all 0's. This method would be used quite often and want to know if it's effectively written. Any help would be greatly appreciated. ...
2
votes
2answers
284 views

Clean Code: Improving readability and refactoring

I'm curious how I can improve the readability of this short program I wrote. Mainly if and how there is a way to remove the for loops and maybe refactor the ...
0
votes
1answer
25 views

Optimizing and accounting for edge cases in Dijkstra's algorithm

I just recently wrote a program to simulate how multicast routing works. The program uses a weighted graph to represent the network and simply runs it through the algorithm. I would like to know if ...
4
votes
1answer
73 views

Calculating running average in Java

I have a library which makes HTTP calls to my service. I was trying to calculate running average of how much time my service is taking on an average. Here is the core logic of how I am calculating ...
-1
votes
0answers
14 views

Something is wrong with my infix to postfix conversion in JAVA [on hold]

I have been doing this for hours and checked other codes but when I implement them, the postfix is still not how it's supposed to be. It would be great if anyone could check them. Thank you so much ...
3
votes
1answer
32 views

Composite implementation of a prototype singleton registry

I am studying design patterns and I've implemented a composite prototype pattern which is also a singleton (one instance per JVM). The main and most important part of the code is the ...
11
votes
5answers
1k views

Generating Robot Name

Problem: Write a program that manages robot factory settings. When robots come off the factory floor, they have no name. The first time you boot them up, a random name is generated, such ...
2
votes
1answer
27 views

Thread-safe Bloom Filter in Java

I have tried to implement a Bloom Filter in Java here. https://github.com/srirammanoj/skynet/tree/master/bloomfilter I just wanted to know if my implementation can be called 'thread-safe' , and if ...
2
votes
0answers
38 views

Final Java TicTacToe MVC Program

After my previous post, I decided to work on the project myself for a while (two weeks) to see how far I could get after reading a few of the really helpful answers to my previous posts. I read up on ...
1
vote
1answer
46 views

Mergesorting a stack in Java

I have this small program for sorting a stack using mergesort. Basically, the aim was to use as little aid from JDK library as possible. See what I have: StackMergesort.java: ...
4
votes
2answers
113 views

Simple builder pattern implementation for building immutable objects

This is a builder pattern implementation to build immutable Person objects: Person class ...
6
votes
1answer
64 views

Genetic algorithm to find the maximum binary number of a given length

I have written some codes in java implementing simplest genetic algorithm. The code finds (or rather tries to) the maximum value possible for a user-defined number of bits. For example, for 16 bit ...
1
vote
0answers
47 views

Updating many fields based on data from a web service

I have to receive data from a webservice and need to compare the received data with the data in our DB. Its easy like: get a streetname from the WS, if its not null and not equals the Db entry -> ...
1
vote
0answers
17 views

Passive FTP port assignment synchronization

I've created the following class to manage the assignment of port numbers to passive FTP server sockets. Notice that Semaphore here is to make the thread wait in ...
1
vote
1answer
50 views

Java application processing GUI input when “Done” is clicked

Right now, I've got this really ugly loop in my code that waits for a boolean to be true before the method can return. It's triggered when "Done" is clicked. I'm ...
3
votes
2answers
33 views

Automatically keyed map

I have written a class that is designed to be an automatically keyed Map in Java. Here is my implementation: ...
4
votes
0answers
53 views

Pseudo-parallel depth-first search

I'm writing a small program, that generates a file containing an adjancency matrix, it then reads from that file, constructs a graph and does something like a parallel dfs on it. How can I make the ...
5
votes
0answers
44 views

Making a logic Prolog compiler simpler with Java

Good morning! I'm student in philosophy taking some course in programing in order to have a better understanding of artificial intelligence. I'm actually doing my own Prolog compiler just like SWISH ...
18
votes
3answers
3k views

What does the Bob say?

Description: Bob is a lackadaisical teenager. In conversation, his responses are very limited. Bob answers 'Sure.' if you ask him a question. He answers 'Whoa, chill out!' if you yell ...
4
votes
1answer
55 views

Sort a stack in descending order

Maintain current element as the top element in the input stack. Pop all the elements on the ordered stack which are greater than the current element and push them in to the input stack and maintain a ...
3
votes
2answers
74 views

ResourceManager class consisting of multiple singletons

I've implemented a class, which provides access to different static resources, which are used by different frontends. I'm hesitating, because in Java getters and setters are quite wide spread. So my ...
3
votes
3answers
82 views

Calculate the Hamming difference between two DNA strands

Write a program that can calculate the Hamming difference between two DNA strands. GAGCCTACTAACGGGAT CATCGTAATGACGGCCT ^ ^ ^ ^ ^ ^^ The Hamming distance between these two ...
2
votes
1answer
70 views
+50

AsyncTask method

Even I know that this isn't a good way of writing code, but I need to improve this. Here I am retrieving data from Server in Json format by Posting some variables in doInbackground. Getting all the ...
2
votes
1answer
105 views

Searching two different elements in a same list

I have a list of conversion histories, where information about user channels is stored. For example user may have app for iOS and Android installed. Each time user logs in, I store a conversion ...
2
votes
0answers
38 views

Android login system

I am completely unaware of all the Android features and available libraries. I just designed a login system to practice it. I have referred to a few books and tutorials. Layout I am using relative ...
1
vote
1answer
43 views

Implementing builder pattern In Java with a static inner and a Concrete standalone class

I am studying Gang Of Four design patterns and I want to implement a builder pattern in Java. It seems there are two options to build a builder pattern: Using two different classes: A target class ...
5
votes
4answers
117 views

Finding the longest sequence of positive numbers in integer array

I am preparing for a coding interview and I have the following questions: Find the biggest positive number sequence in the Integer Array. If Input is ...
3
votes
2answers
72 views

Parsing a string with named sections and a key-value pair on each line

I have a response String as shown below which I need to parse it and store it my class. Format is shown below: task name followed by this dotted line ...
3
votes
0answers
23 views

Reader-writers problem using semaphores in Java

I have written my own solution to the Reader-Writers problems using semaphores based on the psuedocode from Wikipedia. I would like to gauge the correctness and quality of the code. ...
5
votes
6answers
332 views

Find maximum difference between values in an array

My task is to use the following pseudocode and improve it (make it run faster). Also I have to analyze the runtime of the given pseudocode and of my new code that i improved. What does this algorithm ...
0
votes
0answers
41 views

Student information system using swing [closed]

Each student has roll, name and score as attributes. Add a method to store the student objects in STUDENT.DAT file. Develop a GUI with a query panel, output panel and a search button. In the ...
2
votes
3answers
143 views

Convert string to mixed case

This method converts a string to mixed case, id est mixedCase("hello, world!") -> "HeLlO, wOrLd!". ...
4
votes
2answers
54 views

Fraction class in Java - follow-up

(See the previous iteration.) I have improved my Fraction implementation taking the answers in the previous iteration into account. Differences Both numerator ...
2
votes
1answer
33 views

Pen-and-Paper Dice Roller Tool

A friend asked me to write a pen-and-paper dice roller, so I put this together. I'm still pretty new to Java Swing, so I was hoping I could have some advice on how I handled the layouts and ...
5
votes
3answers
144 views

Interview coding test: Searcher

I did a task for an interview and the solution was not accepted. The task was to implement the class search function by name. The number of classes in the input data from 0 to 100000. Class names are ...
3
votes
1answer
44 views

Java Connect Four “Four in a row” detection algorithms

I am making a connect four type game for my end of the year project in my programming class. I am about to start building off of the console based version I have made and add a GUI, but I feel sort ...
5
votes
1answer
37 views

Three stacks in a single array

I have implemented three stacks in a single array in Java. Any advice on object oriented design, coding structure, logical part or any sort of advice would be appreciated. ...
3
votes
2answers
25 views

Thread Safe Servlet

I am working on a JSP MVC web application. I am confused about Thread-Safe Servlet concept. Following is my code, please tell me is it thread safe or not. Also, tell me the reason that why it is ...
0
votes
0answers
11 views

Getting data with Rxjava and retrofit

I am using rxjava with retrofit to get data from an api then filtering the data with for loop in the onNext Method. Is there anyway not to use the for loop and just use rxjava to filter or improve ...
4
votes
2answers
43 views

Counting from 0 to a number and back to zero, and space-padding the result to be a given length

I completed a task: The objective was to create a method with 2 arguments: a number to count to, and how many char/numbers in the resulting string. Result: Let's say that "number" is 5, so it will ...
1
vote
1answer
33 views

improved HibernateDao

I have this HibernateDAO.java Class: ...