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

learn more… | top users | synonyms (1)

1
vote
4answers
36 views

How to get rid of semantic duplication

I am breaking my head with how to get rid of semantic duplication(Code that is syntactically the same but does different things). I can't find anywhere a post or something that mentions a bit how to ...
0
votes
2answers
27 views

Try, catch, exceptions with java

Is this code good for checking if the variable texto is empty or not? How would it be done with try and catch? public class RedProfesionalException extends Exception { public ...
1
vote
1answer
14 views

Java Theory: Classes Design for Currency, Futures and Metals Analysis 1

This is a continuation from here: http://stackoverflow.com/questions/16761207/java-theory-classes-design-for-currency-futures-and-metals-analysis I have created 2 classes for now. 1) Historical Data ...
2
votes
3answers
58 views

Game Of Life 3 in Java

I have this version of John Conway's Game Of Life in Java: Frame class: import java.awt.BorderLayout; import java.awt.FlowLayout; import java.awt.Image; import java.awt.event.ActionEvent; import ...
0
votes
0answers
28 views

Calculate work progress in percentage of batches that contain tasks and task contain sub tasks

I was being referred to here from stackoverflow. I am trying to calculate work progress in percentage. I have multiple batches, and each batch contains a set of tasks and each task also contains a ...
3
votes
2answers
80 views

Looking for a better solution to my OO code

I would like if this could be kept to a post providing concrete examples of how I could solve my problem better, and not about which one would be "best" as such :) I would simply love some insight to ...
2
votes
1answer
35 views

Better code for converting a char to its UTF-8 percent encoding representation?

This is working code for a URI template (RFC 6570) implementation; when the character to render is not within a specific character set, it is needed to grab the UTF-8 representation of that character ...
-1
votes
0answers
24 views

How is it called when what goes first in &&-condition(java) matters a lot? [closed]

I have discovered that if accessing some index from array/string happens first in IF clause, it can crash (out of bounds exception) However, if i check index first and then try to access it, if index ...
2
votes
1answer
40 views

Best way to call future.get()

The following is a small part of some code I am working on Which is better/faster/nicer? 1. for (Future<Subscription> future : futures) { try { executorService.submit(new ...
2
votes
1answer
34 views

JSON AsyncTask refactoring to improve quality?

I'm new to Android. I was wondering if anyone had any suggestions. It's basically an AsyncTask to get a remote JSON array and put it into a native array. Would be very grateful for suggestions. ...
2
votes
1answer
47 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
2answers
74 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
36 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
36 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
80 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
1answer
47 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
88 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
65 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
78 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
50 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
90 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
62 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
23 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
41 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
44 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
41 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
56 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
353 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
76 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
50 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
69 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
125 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
81 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
201 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
69 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
80 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
94 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
62 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
393 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
74 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
38 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
78 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
66 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
58 views

Secure storgage of API key + secret, salted AES 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. A ...
2
votes
2answers
84 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 ...

1 2 3 4 5 20