Java is a popular programming language and runtime environment which allows programs to run unchanged on most platforms.

learn more… | top users | synonyms (1)

2
votes
0answers
17 views

Improve my threading in Java

I made a class to perform tasks concurrently and have implemented it. From appearances and testing, everything seems to work. How can I improve this? I understand this is somewhat a broad question, so ...
2
votes
1answer
49 views

Does this violate the SRP?

I just finished (re)reading Clean Code, and one of the ideas I learned was the SRP. However, I am not quite sure on what defines a "Single Responsibility." In the piece of code below, I have a Note ...
0
votes
0answers
32 views

How to improve Collision Detection in Bricks in BreakOut Game

I've done my first BreakOut Game while completing an assignment for Stanford University CS Online Course for java. However I noticed during play testing that when the ball sometimes hits a brick ...
0
votes
0answers
34 views

How to implement MVC on the application scale?

I'm developing a simple conferencing app with a Swing standalone client which connects to enterprise java beans. Users can create "sessions" (conferences) on the server, and then can join those ...
0
votes
2answers
74 views

Singleton interface in Java

I've created a singleton by means of an interface. I don't want to make a thing with getInstance() etc because I don't care about inheritance, and it's redundant and non-declarative. Are there ...
1
vote
0answers
28 views

Better Design Pattern For Terminal-Like GUI

I am working on a java swing project that looks like a Terminal (but with less functionality). The GUI contains a jTextArea to display output and a jTextField for user input. Here is an application ...
0
votes
0answers
30 views

Name of this algorithm (Create binary image) [migrated]

Some days ago I saw in this site the algorithm below to convert color images to binary images and I used it in my application (with some small changes). However, I need to know what is the name of the ...
0
votes
0answers
84 views

Would appreciate feedback on college project

would appreciate some feedback regarding best practices on the following code which is a college project. What should go in the controller and what in the views? How to attach and remove the views to ...
0
votes
1answer
60 views

Basic java database source code review

I just wrote my first java database program for the purpose of getting feedback on the implementation and coding. It has 1 table and 2 buttons and prompts the user to select a folder, lists the ...
3
votes
1answer
74 views

Game of Life Animation Java

I have this Board class: import java.awt.Color; import java.awt.Graphics; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseEvent; import ...
2
votes
1answer
61 views

Json whitespace formatter

I couldn't quickly find Java code with googling to make serialized Json easier to read (this is a debugging library, obviously implementation code wouldn't use this as it's just more characters). This ...
-1
votes
1answer
46 views

Restructure this Java code to allow for sometime have 4 items in packagePriceList [closed]

Please help me restructure this Java code to allow for sometime have 4 items in packagePriceList. public static HTMLSelectOptionsElement listPremiumPackageTermsWithPrice(String[] packagePriceList, ...
1
vote
2answers
84 views

Email report generation from database

I have written a small batch job which will collect data from db and send mail to user. Can you please do a review of the code with design prinicples in mind and also with best practices for Db and ...
3
votes
2answers
59 views

Connection Pooling

I was curious about trying to write my own simple Database Connection Pool, where all the responsibility for freeing resources belongs to objects which use those connections. There are: 3 classes - ...
-1
votes
0answers
22 views

GUI not working perfectely [closed]

import javax.swing.*; import java.awt.*; import java.awt.event.*; public class tomeddle extends JFrame { private JLabel label; private JTextField textfield; private JButton button; private JCheckBox ...
-1
votes
1answer
54 views

Java Question for An Absolute Beginner [closed]

This is for a beginning Java course that poses the problem: Write a class named Employee that has the following fields: name. The name field references a String object that holds the employee's ...
0
votes
0answers
37 views

Java reflection and static classes

I try to intercept some OpenGL calls for testing my rendering classes. Reflection is used for replacing the OpenGL backend. I feel this class is badly written and I need advices for refactoring it. ...
1
vote
1answer
35 views

Write and read non-serializable object to file android example

I couldn't find a good example, so after some fighting with writing non-serializable object to file in Android, I decided to show you my solution. Could you tell me if it is OK or how could it be ...
0
votes
0answers
40 views

Differentiating String/Int User Input [closed]

I am having issues trying to type code that will make my program distinguish whether the user inputs a string value or an int value. If an int value is typed in, it will be stored into an array (named ...
1
vote
1answer
48 views

Java; Generic Observer/Observable - is this as messy as I think?

I have recently had a whole load of help trying to roll my own loosely-coupled Observable/Observer paradigm, here: Loosely coupled observer pattern To keep things simple and to aid in my ...
2
votes
5answers
293 views

String manipulation in Java

Here is the question followed by my program which works good Given a string, return a version without the first 2 chars. Except keep the first char if it is 'a' and keep the second char if it is 'b'. ...
1
vote
0answers
72 views

Need some advice how to proceed with my project

I have set up a basic MVC project which should be a student administration application based upon a CSV file as datastore. Each user has a specific role (student, lecturer, professor, leader of degree ...
-1
votes
1answer
48 views

Singly Linked List removeLast method implementation [closed]

Hi I am having a little trouble with the implementation for my removeLast method in my singly linked list class. public E removeLast() { E removed = null; if (first != null){ // if list not ...
2
votes
2answers
68 views

Converting string with a lot of if statement

I have code like the following one, which I use to convert string to another string. public String convertString(String string) { String convertedString = string; if( string.contains("something")) ...
2
votes
2answers
114 views

Space Invaders Game (Java/Swing)

Recently I have been working on a project in Java for a class in high school: a Space Invaders game. I was wondering if anyone could review it and point out anything I could change to help improve ...
2
votes
1answer
75 views

Game of Life - Java

I wrote John Conway's Game of Life in Java: class GameOfLife { static int countSurrounding(int[][] board, int a, int b) { int count = 0; int[][] surrounding = {{a - 1, b - 1}, ...
5
votes
2answers
190 views

learning java is this code correct

I am new to java programming and to help me learn I created a simple telephone address book. the code runs as expected but I would be interested to here from more advanced programmers if they think I ...
1
vote
0answers
64 views

Linear search java

I just wrote this code to do a linear search on an array of elements. Can someone please confirm if I got it right? If it is infact a linear search? package arrays; import java.io.BufferedReader; ...
3
votes
1answer
72 views

Dining Philosophers problem Solution with Java Reentrant Lock

I have implemented Dining Philosopher problem using ReentrantLock in java. The goal of this program is Every philosopher should follow the workflow of think,getchopsticks,eat,putchopsticks (No ...
1
vote
3answers
91 views

Basic code review for advice on bad habits/ bad practice

Would it be possible to get some feedback on some code I've just written? I've been working my way through Deitels' 'Java How to Program' for the past few months and thought I'd better ask for some ...
3
votes
1answer
58 views

java recursive method to print a descending then ascending integer sequence

From a programming assignment: Write a method writeSequence that accepts an integer n as a parameter and prints a symmetric sequence of n numbers with descending integers ending in 1 followed by ...
5
votes
3answers
372 views

Is it wrong to write an entire program under one class/method in Java?

I'm new to programming an created a simple rock, paper, scissors game. The entire program is under a single class and the main method, i hear that's probably not the best way to code. How should i ...
-4
votes
0answers
17 views

Netbeans Code problem [closed]

I have done this in Netbeans and the program does not run because the the variable length is not found String numberEntered=JOptionPane.showInputDialog("Please enter a number"); String output = ...
-1
votes
0answers
27 views

my failed solution for sales tax calculator [closed]

Recently I have been on the last stage of an interview process where I was asked to provide a solution to this tax calculator problem ...
2
votes
1answer
66 views

TicTacToe in Java

I created this game in Java: import java.util.Scanner; public class TicTacToe { public static Scanner input = new Scanner(System.in); public static String getName(int noPlayer) { ...
2
votes
1answer
35 views

Applying DocumentListener on multiple JTextField

Say I have 5 JTextField: jTextField1, jTextField2... Now I want them to behave the same on DocumentListener, so I decided to make only one DocumentListener and set it to the 5 components. Meanwhile ...
1
vote
1answer
77 views

Some feedback on first attempt to write Java MVC app

I'm writing my first Java MVC application which should be a desktop student administration application with a swing gui. DAO is already implemented: Need some feedback - student administration ...
1
vote
2answers
63 views

how to refactor this java [Android] code

I have this code to generate some tables in my PDF document for my android app. It works fine, I just think I need to refactor it, as basically is the same structure repeated 3 times. //tables! ...
0
votes
0answers
35 views

API Key storage using AES encryption in Java

This class is responsible for storing an API Key and Secret pair. The secret is encrypted with AES in CFB mode, using a key derived from a passphrase, a random salt and a number of rounds of SHA1. An ...
2
votes
2answers
77 views

Guess my Number in Java

I have just started learning Java, and don't want to start any bad habits, so please can I have a review on my latest game code: import java.util.Random; import java.util.Scanner; class GuessMyNumber ...
0
votes
0answers
47 views

How to make the code more optimal?

Maybe some of you have an idea how to make the code more optimal? This had to be a little faster, because i cant pass few time tests :/ Unfortunately I can not add tests whose over time because they ...
1
vote
1answer
57 views

Binary Search Feedback

I have written a binary search algorithm, but it seems to be a bit different than other peoples that I've seen. I was hoping that the community could give me some feedback as to whether or not I'm ...
1
vote
2answers
88 views

Need some feedback - student administration application

The application is a student administration system using a csv file for persistence as part of our school project. So I first created a basic DAO. I'd like to have some feedback about what could be ...
3
votes
2answers
62 views

Moving from normal threads to ExecutorService thread pools in java

I had my original threading code which worked well, but since my tasks were shortlived, I decided to use thread pools through ExecutorService. This was my original code public class MyRun implements ...
1
vote
1answer
69 views

Thread safe settings

I'd like to design a settings class thread save. The settings have 2 attributes: String x and int y and should provide listener functionality to notify listener about changes. The problem is, how to ...
0
votes
1answer
30 views

JPanel Rendering too Slowly

I am working on an application which first loads a 'settings' panel and then loads the application. It all works fine, loading the settings panel takes a few seconds longer than I would like it to. ...
2
votes
1answer
60 views

Critique Request: Reversing a singly linkedlist in java

I find the tail in the first while loop and store it in the tailEnd node. Then I update the tail to the previous node and change the tail.next to point to previous node. Once head.next.next == ...
5
votes
2answers
186 views

Making this loop less convoluted

private static List<ConstrDirectedEdge> kruskalConstruct(ConstructionDigraph CG) { int current = CG.srcVertexIndex(); boolean visited[] = new boolean[CG.V()]; visited[current] = ...
6
votes
3answers
424 views

Which of these two java class designs is better and why?

Example 1: public interface Adder { public int getSum(); } public class AdderImpl implements Adder { private int v1; private int v2; public AdderImpl(final int v1, final int v2) { ...
1
vote
0answers
66 views

re-arrange letters to produce a palindrome [closed]

I wrote this simple function (in Java) to re-arrange letters in a given String to produce a palindrome, or if it is not possible, just prints -1 and returns. For some reason, I can't figure out why ...

1 2 3 4 5 19