Tagged Questions
7
votes
4answers
521 views
An enum that has situationally invalid entries
Is it considered bad style to have that BOTH value in the Direction enum? Problems can arise from ...
0
votes
3answers
56 views
Call method from another method and into the cycle [on hold]
Is this normal or do you have more best practices?
...
8
votes
2answers
357 views
Swing calculator - first GUI program
I've recently made a calculator using Java and Swing. I'm okay with the results but I'm curious what are the major flaws I've made (assuming there are, because it is my first program making GUI). I ...
1
vote
0answers
16 views
Intern AuditSystem in DB and getting users from it
Mine project has a change on the database, so that every INSERT-UPDATE-DELETE action is logged with triggers on the DB.
For that they have an extra table created :
Table ...
0
votes
2answers
51 views
Simple GUI using tabs to separate application windows
I'm designing a simple GUI using tabs to separate each 'window' of the application. There are 3 main tabs, each with 2 sub-tabs.
In one class I create the entire hierarchy of panes and panels:
...
5
votes
3answers
259 views
Multiple background tasks
This is taken from my post at Stack Overflow here.
I need your help to review my code for improvement and best practice.
...
10
votes
2answers
102 views
“Event Binding” in Java employing Lambda
As I am relativistically new to programming and lack any sort of formal experience in the matter, I was wondering if any of you with a bit more knowledge in the subject would be willing to tell me if ...
4
votes
3answers
322 views
How do I avoid over-using the garbage collector?
I'm wondering what the best way of initializing variables so that I don't over use the garbage collector with a for-loop. Assuming the variable is only used inside ...
11
votes
4answers
454 views
File editing program
I have written a Java class to replace text in file. The file contains database configurations and is as follows:
...
6
votes
4answers
272 views
8
votes
5answers
430 views
9
votes
2answers
110 views
Optimizing “simplifier”
Basically, I'm trying to make a Simplifier that can take inputs in the form of a String and print out the solution step-by-step. Now that I've got it working, I ...
5
votes
2answers
46 views
Proper action when a Java program fails
I have a program that has to initialize a few big things (connect to a few databases, parse some XML) and without the initialization being successful the program would not be able to continue.
Right ...
4
votes
1answer
84 views
How to make business logic code maintainable when working with multiple states?
I am developing a UI Application for a very simple phone app, the UI is based entirely on the state of Call in a container provided to me by a third party library.
Below is a sample Call object that ...
6
votes
2answers
902 views
How can I make this brute force faster?
Code no longer relevant but I want to know how I can make it faster. It use only about 10% of my CPU. Any advice about best practices, better algorithms, or how to make the existing one faster are ...
7
votes
2answers
281 views
Optimization of file scanner
Program must to find duplicate files (by content) in a given directory(and subdirectories).
I collect all data in Map<Long, ArrayList<String>> map ...
3
votes
1answer
83 views
Class naming conventions
I have the following scenario:
The (web-) application is built with Java/Spring. I have several REST-endpoints which deliver data prepared to be consumed by a frontend by ...
6
votes
2answers
960 views
Ghost4J PDF to image conversion
The primary goal of this code is to convert a PDF file to images. I also create a directory under C:/Media based on a combination of the PDF name and current date ...
0
votes
6answers
484 views
Which Java string value is preferred to return: blank or null?
I came across this snippet and am wondering if I should return blank in this case.
Which is more practical to return: blank or ...
9
votes
2answers
719 views
Math expression solver
Recently I've stumbled upon an interesting challenge for me.
You should develop C application, that solves math expressions. Operations such as (+,-,*,/) should be supported, as well as (cos, sin, ...
4
votes
2answers
92 views
Long Thread & EDT
I’m trying to make a simple gui app that starts a “long” process that can be started and stopped. The process generates random numbers and displays them in a JList. As numbers are being displayed ...
3
votes
1answer
51 views
Is it ok to pull out specific arguments from a Java dynamic proxy invocation?
I have a Java dynamic proxy with an invoke method that looks like this:
...
6
votes
1answer
377 views
Tower of Hanoi solver
Requesting code review, best practices, optimizations for this solution to the Tower of Hanoi problem.
...
41
votes
11answers
9k views
Nesting versus GOTO: which is better to avoid?
In Java they're not really known as GOTO statements and are rather referred to as Branching Statements, but I find that the former term is a bit more indicative of ...
7
votes
4answers
458 views
6
votes
2answers
111 views
Flow control with try catch to reduce redundancy
I've seen a similar question to this but mine's a little more specific. I have the below
...
2
votes
1answer
62 views
Filter fragments manager
How could I simplify the onCreate() method? Maybe via compact and properly-named methods?
...
6
votes
2answers
124 views
Class that represents searchable and sortable elements
In my application, I have a small hierarchy of related classes (partner categories - partners - partner points).
The application has two representations of its content:
in the form of partners ...
7
votes
2answers
278 views
Alternative algorithm to solve maxMirror problem of Codingbat
I request you to provide insightful suggestions to improve the following code as well as an alternative algorithm to solve it.
Problem Specification:
We'll say that a "mirror" section in an array is ...
22
votes
6answers
6k views
“Guess a number” game
I began the journey to be a self-taught programmer about a month ago and my biggest fear about teaching myself is developing bad habits and not realizing it.
I'm looking for criticism on this "Guess ...
4
votes
2answers
67 views
3
votes
1answer
97 views
Naming of predicate methods
Sorry for my English.
I want to discuss this question. I don't agree with @200_success. He says:
I would also rename evenNumber(int number) to isEven(int number). There
is a convention in Java ...
21
votes
9answers
4k views
Generating Even Random Numbers
I have this class which is used as part of a game. It needs to generate Random Even values, which is done by generating random numbers until the result is even.
Is there a better way to do this?
...
5
votes
2answers
613 views
Efficient way of having synchronous and asynchronous behavior in an application
I am working on a project in which I am supposed to make synchronous and asynchronous behavior of my client. In general, how our client will work as below -
Customer will call our client with a ...
4
votes
1answer
121 views
Activity using multiple layouts
I have been slowly getting more and more "at home" with Android development and I would like some guidance. I have made an app that uses a ListActivity, that ...
3
votes
3answers
82 views
Forcing type-safe IDs for use with Collections and Maps
Introduction
I have a hierarchically nested tree class (like SampleFolder, s.b.) that I want to serialize.
The problem arises with the collection of sub items ...
2
votes
2answers
371 views
How to pass the input parameters correctly to a method?
Below is my Interface -
public interface IDBClient {
public String read(ClientInput input);
}
This is my Implementation of the Interface -
...
12
votes
2answers
466 views
Simpler boolean truth table?
I'm doing a CodingBat exercise and would like to learn to write code in the most efficient way. On this exercise, I was just wondering if there's a shorter way to write this code.
...
3
votes
1answer
43 views
Passing around Connection
I have a myCon=getUnusedConnection() method that gets a connection from Connection pool. I also have a ...
3
votes
2answers
312 views
How bad is duplicating a code block? [closed]
Is it preferred to do:
if(a) {
if(b) {
//some statement(s)
}
} else if(c) {
//some statement(s) (the same ones as in the other block)
}
or
...
7
votes
4answers
183 views
Looping Strategy: Change behaviour after first iteration
I have often encountered the following situation. I want to call a method in a Loop, but want to skip the call at the first run. It do not have to be a method, it also can be some lines of code that I ...
5
votes
3answers
203 views
Simplifying and optimizing the structure of this code
I'm developing a Java EE project which uses Redis through the Jedis library. I'm retrieving the chat history of a particular channel from the servlet context and if absent, from Redis. The PMD plugin ...
10
votes
2answers
153 views
toString() in a model or view layer?
I would like to ask those of you, who are a little bit more expirienced in development. I would like to ask about toString() method usage. In what situations do you ...
5
votes
1answer
162 views
Rethrowing exception just as an information
I have something like that:
My custom exception class:
...
2
votes
3answers
310 views
Clear ArrayList
I create class level static ArrayList by the following line.
static ArrayList<Student> studentList = null;
Then I create and fill ArrayList with some ...
1
vote
1answer
349 views
Background image loader AsyncTask
Usually, AsyncTasks are meant to be one-shot, i.e. you start it, it fetches some data, displays the result and dies. However, I'm now using a long-running ...
4
votes
3answers
136 views
Execute method on ternary operator result?
I have two List<T>s of the same T and a T object. Based on a condition, I want to add ...
1
vote
2answers
93 views
How's my and my father's java ODE Solving and Graphing Program?
At the request of my father, I've adapted some C# code he wrote which uses a timer to display the true and approximate solutions of the ODE y' = -lambda*y in real time to do the same in java and then ...
2
votes
1answer
157 views
Review of String to Long bijection class - focus on readability/maintainabiliy
I wrote the following interface and class to bijectively map a string to a long. I would like feedback on how to make the code more readable and maintainable.
Interface:
...
1
vote
1answer
431 views
Best way to deserialize a Byte Array from Java in C++?
I am writing Byte Array value into a file using Java with Big Endian Byte Order format.. Now I need to read that file from C++ program...
That Byte Array which I am writing into a file is made up of ...