Tagged Questions
5
votes
3answers
303 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 ...
2
votes
2answers
72 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
vote
2answers
66 views
Encapsulating logging and throwing exceptions into a method. Bad practice?
original code example
if (var1 == null) {
String msg = "var 1 is null";
logger.log(msg);
throw new CustomException(msg);
}
if (var2 == null) {
String msg = "var 2 is null";
...
2
votes
1answer
112 views
Collision detection implementation
I'm working on a clone of Hunter Story. You shoot monsters with your bow. Recently I implemented collision detection, this is all working correctly, and I don't think the code needs any dramatic ...
3
votes
5answers
4k views
How can I make this brute force algorithm faster?
Ever since I was a kid I wanted to understand how brute force programs work. I have not been able to make sense of any of the examples throughout the internet, so it became a personal challenge to ...
0
votes
1answer
43 views
2D Array: Retrieve the “Left” Item
I am creating a game that contains a Board and Pieces. The Board is basically a 2D array of Pieces. [Think smaller chess board]
One of the things that I want to accomplish is to be able to retrieve ...
1
vote
2answers
153 views
How to Format Clean Accumulation Code?
I often find myself writing methods in languages such as Java or C++ that are only meant to loop over an array or something similar, accumulate the values, and then return the total. The problem is, ...
0
votes
1answer
58 views
What is the better way to retrieve value from this cache implementaion?
I have the following methods in CacheUtil class
public void addCacheEntry(String key, Serializable entry) {
//add to cache
}
public void removeCacheEntry(String key) {
//remove from cache
}
...
2
votes
3answers
140 views
Is it good practice in Java to pass a StringBuffer to a method to get error messages
I have a class that has a method which takes a user as an argument and performs several validation checks on the user and returns a boolean to indicate if theyare valid.
I want to be able to get ...
3
votes
1answer
155 views
Is this the best approch to combine 2 Interfaces?
I have a use case where I want to use both HttpRequestInterceptor and HttpResponseInterceptor in one class.
I'm asking if the following would be a good solution and what are the potential problems?
...
11
votes
3answers
933 views
Java TicTacToe (logic)
I'm currently studying java by myself,
the book I'm using (while very good)
lacks feedback (obviously), while trying to write this program I found myself solving most of the problems I've encountered ...
2
votes
1answer
4k views
Java Slick 2D Collision Detection Methodology
I have a collision detection for terrain setup (non-terrain is handled with a quadtree I implemented apart from this) and I was wondering how others have done it compared to mine and what I could ...
1
vote
2answers
176 views
Code fragment where I am repeating myself
I have two methods here that does the same thing. get the user input and validate them.
if they are enter a letter program will prompt him again to enter a number after that if its a number it will ...
6
votes
4answers
320 views
Does this code follow standard conventions?
I’m trying to learn as much as I can on my own by reading lots of examples, documentations, and asking here. I would like to improve my style to write efficient code and adhere to Java standards.
In ...
2
votes
2answers
184 views
What's wrong with static utility classes, versus beans?
My inclination is to make these methods static:
package net.bounceme.dur.usenet.driver;
import java.util.List;
import java.util.logging.Logger;
import javax.mail.Folder;
import javax.mail.Message;
...