Tagged Questions

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)

1
vote
1answer
24 views

Simplifying WebView

I started to code on Android, but I think my code is very heavy and may slow down the performance of my app. For example, when I run my app and I try to drag the page in one of my webviews, it's ...
11
votes
4answers
560 views

Beginner number guessing game in Java

I am a first year CS student. We are currently learning Java and my latest assignment was to create this random number game. I am hoping to get some feedback on code style etc so that I know what not ...
1
vote
2answers
46 views

String compression using repeated character counts

Implement a method to perform basic string compression using the counts of repeated characters. For example, the string aabcccccaaa would become ...
6
votes
6answers
257 views

Finding unique triplets adding up to 0

I am working on a problem "3Sum", in which, given an array S of n integers, are there elements ...
1
vote
2answers
65 views

Finding logic operators [on hold]

We get the search string from the UI. Based on the search parameters we need to create a back-end query. This is similar to "Feed Item Query Language(FIQL)". I have wrote the code to find the logical ...
1
vote
3answers
60 views

Use of Exception to log execution stack trace

I've been back and forth with a colleague over the use of Throwable.fillInStackTrace. This Log class is meant to wrap the Simple ...
0
votes
2answers
40 views

Simple print function, passing in various arrays [on hold]

I wanted to create a print method that could take in a given array and print it. I can only seem to make the print function specific to my specific array. My print function only can print 1 array, but ...
5
votes
3answers
78 views

Can I simplify my phone look-up program?

I needed to make a phone number look-up program with 10 contacts. I feel like I can shorten the program up a bit, it seems very long, but I don't know how. Any suggestion? Do I need all of the Java ...
4
votes
4answers
443 views

Should I copy list both in constructor and in getter?

I have a simple immutable class: ...
3
votes
2answers
44 views

Correct way of implementing thread safe factory with caching?

I have a ConnectorFactory that creates Connector objects based on parameters like URLs, username and passwords. The ...
2
votes
2answers
103 views

Producer/Consumer Program

I am a semi-new Java programmer that tends to be a perfectionist. What I'd like to know about my code: How it compares to common practice. Is it readable? Are my comments appropriate? Any ...
-3
votes
0answers
37 views

Port-scanning on a website [on hold]

I've assembled code in Java to do port scanning on a website and I'd like to have the code reviewed. I got the basic point for the code on Google but I changed it to display the port, its name and it ...
3
votes
0answers
71 views

Dividing a number half into words and half number

Example: If I have a number 1000: I first put commas (In English Standard) that makes it: 1,000 I split the above at the first comma: I get 1 I convert 1 into words: I get One, name it ...
8
votes
4answers
496 views

Text-based BlackJack game

I am a new programmer (I've been doing Java for about 7 weeks) and I am of the type who wants to get it right straight away, so I wonder how this code: Compares to the common practice is structured. ...
4
votes
2answers
64 views

Reflection and Project Euler

I have made a Project Euler runner in order to facilitate the running of the various problems. I have never used reflection before, and I believe that I have found a good use for reflection within ...
3
votes
1answer
35 views

Comparing two implementations of smoosh()

In this question, the suggested solution for smoosh() is as shown below, ...
14
votes
5answers
1k views

Vector (physics) implementation

I recently started learning Java, and I decided to implement a basic vector system for another particle system I was building. ...
-4
votes
0answers
18 views

frequency distribution and histogram [on hold]

can someone please write down a sample java program for frequency distribution? also include a java program for a histogram...pls give me a solution asap! if you have a given data for, say, cyclists ...
-2
votes
0answers
33 views

Roman numeral converter code not working [on hold]

I am currently working on a project that converts a number between 0 to 3999 to its correct roman numeral. It shows no errors, however, when I type anything but 0 it goes into an infinite loop. I am ...
5
votes
1answer
45 views

General Batched Job Runner

This question is inspired by: Generic Task Scheduler where the problem is to run tasks on a scheduled basis, in parallel, and have individual timeouts for each job. For example, consider this ...
2
votes
1answer
212 views

Optimizing twin() method

Part III of this question says: Fill in the twin() method in the SList class so that it performs as indicated in the ...
0
votes
0answers
21 views

newGame() loop doesnt work. Application exits without notifying [on hold]

I got a couple issues with my code. I know it is not the best looking design/coding but I don't claim to be a good programmer. I want my game to ask to player if he/she wants to play again after the ...
5
votes
2answers
231 views

Tremaux Algorithm

I am trying to implement Tremaux Algorithm for a 2D maze. So far the robot works well however I have some problems with retraceStep(). I'm not asking how to ...
3
votes
1answer
33 views

Swing application: Working with GridBagLayout and Mediator pattern

SCENARIO: As a follow-up of this question on Stackoverflow asked few days back, I am working on a swing application(article tagging tool) where the user(on an initial jpanel) would fill up some ...
4
votes
2answers
73 views

Optimizing squish() method further

Part II of this question says: Fill in the squish() method in the SList class so that it performs as indicated in the ...
2
votes
1answer
31 views

Saving search history with many checks and validations inside

I am absolutely confused by saveSearchHistory function. It seems dirty and unobvious. Should I refactor it, and how? SearchHistory.java ...
6
votes
4answers
228 views

Optimizing smoosh() method further

Part I of this question says: Fill in the smoosh() method in the Homework3 class so that it performs as indicated in the ...
2
votes
1answer
36 views

Graph Implementation in Java 8

Here is my code which implements a simple directed graph in Java 8. Here are some of the things I am unsure about: I am fairly new to Java 8 concepts. Have I used the new API correctly (and not ...
2
votes
1answer
59 views

Project Euler #3 - checking only up to sqrt(input)

I know it's possible for the largest factor of a number to be greater than the sqrt (e.g., for 14, 7 is the largest). Why then does almost every solution for the problem check only up to the square ...
10
votes
2answers
131 views

Validating a Binary Search Tree

This is an implementation of a function to check the property of a Binary Search Tree, that is: the key in any node is larger than the keys in all nodes in that node's left subtree and smaller ...
8
votes
1answer
165 views

Solar System model: Moving Space Balls

I have a model of the solar system that I'm working on at the moment. Now is the time to start cleaning my code up a little. Here's what I have so far: A main 'driver' method: ...
5
votes
2answers
184 views

How can I refactor onClickListener applied to different buttons?

I have several buttons and I want to toggle between them like radio buttons. The way I have it set up now is that each button have this same code but the buttonValue varies depending on which button ...
1
vote
1answer
19 views

Method to Return a Hibernate Session

Can this method be improved?: ...
0
votes
0answers
6 views

Getter within loop returning null after assigning values [migrated]

I've got a slight problem with my program. Simply put, what I do is this: Choose the option to "Add a new Student record". When I try to display the newly added values (First Name, Last Name, ...
0
votes
0answers
20 views

Java - I have a partially working pacman game but would like tips for improving [closed]

I am creating pac man for a project, but i've ran into trouble moving around my character. Specifically implementing wall collision, I can move the character fine just not when I try to put in wall ...
2
votes
1answer
39 views

Precognitive waiting - waiting for something to finish, before it starts

I have implemented a class that has a method to wait until "something else" has happened. When this has happened, the current thread stops waiting and returns from the method. This is my current code: ...
4
votes
1answer
91 views

Generate Cartesian product of List in Java

My code, which generates Cartesian product of all lists given as arguments: ...
4
votes
3answers
429 views

Refactoring a method for estimation

I have to refactor this method: it seems to duplicate two code blocks with some slight variation. Any suggestions? It is a bit of a mess :) ...
-3
votes
0answers
37 views

How do I finish this up? Sorting a list of arbitrarily generated integers [closed]

Write a program that will sort a list of arbitrarily generated integers in descending order. Let the user determine how many arbitrary and unique numbers to sort from 1 to 10000. Use the random ...
2
votes
1answer
21 views

Filtering JSONArray by Branding & Modelling

I have a small function that takes in a list of JSON objects that has the format below. The function below that wants to see if the brand and model of car passed to it can be matched against the List ...
8
votes
2answers
82 views

Optimizing String combinations in Java

I need to obtain all combinations of a String of length k from the given elements. For example, for ...
13
votes
2answers
90 views

It's Friday! - Zeller's Congruence Revisited

A couple of date-related questions have come up recently, and on both occasions I have been taken back to my 'early' days where one of my first forays in to programming involved implementing Zeller's ...
0
votes
2answers
56 views

Optimizing Dijkstra implementation using PriorityQueue in Java

I am trying to make Dijkstra implementation more efficient. Below is the code for class Node which implements Comparable so it ...
5
votes
1answer
161 views

Logging with date in Java

I write my log messages in JTextArea. Each message should have a time added. I created a following method: ...
1
vote
0answers
38 views

Generic Java Task Scheduler (Followup) [closed]

As a followup to my previous question, and after receiving a great answer, here is the updated Scheduler class. I would also like to state some goals & ...
0
votes
0answers
26 views

Potholes in a multiplayer snake where players can use their own algorithms [closed]

Topic originating from stackoverflow. I'm developing a snake-like multiplayer where players can use their own algorithms to determine the next move of their snake. A little background: My game ...
3
votes
1answer
50 views

Improving efficiency of Prim's Algorithm

I have implemented Prim's Algorithm in Java. I am wondering how it can be made more efficient. Below is the class Node for vertices. ...
7
votes
1answer
78 views

Generic Java Task Scheduler

I wrote this generic task scheduler for executing tasks in fixed-delay intervals, can you find anything wrong with it, or issues that may arise from using it for sending something like queued mails in ...
0
votes
0answers
24 views

Best approach to a defined datascructure [closed]

I've here a TXT file with some data that I can't change. So I have to create a datastructure to read this file and with that datastructure do some thousands of iteractions. The file follows a ...
4
votes
0answers
71 views

Transformation of abstract models

In one of my recent projects I faced the problem of transforming an abstract class into another abstract class. The classes were structured like this and are part of an api for questionnaires: ...