Java is a high-level, platform-independent, object-oriented programming language originally developed by Sun Microsystems. Java is currently owned by Oracle, which purchased Sun in 2010.

learn more… | top users | synonyms

4
votes
1answer
241 views

is switch(this) antipattern or bad practice in Java for Enums?

At work I bumped into a problem to see how enums are growing and storing business logics. As they grew, the constructors grew a lot. At one point I found out instead of putting in let's say the tenth ...
0
votes
2answers
205 views

my software model has some kind of cyclic dependency

I need a recommendation about my software model. I think it is not that good, since there is some kind of cyclic dependency. I have an OSGI bundle under Kura application framework, here are the ...
0
votes
0answers
101 views

How do I create a script interface to my Java application? [duplicate]

I have a Java project, and want to send commands to that application from Bash. Can I directly invoke Java methods from Bash? Is there any common solution for this problem? For example, my ...
2
votes
1answer
123 views

implementing an extended interface on a concrete class

I don't know if this is a best practices or not. If I have a interface that extends another interface such as : public interface A extends B{ public void something(); }; and a concrete class ...
1
vote
1answer
165 views

Java code design for a Geocoder Webservice client

Please bear with me, if this type of question has been asked before. I am having a dilemma with object design and seeking experts' help here to come up with the correct/better design for a webservice ...
8
votes
2answers
111 views

How can I best manage Android Intent filter Strings across multiple projects?

In my project IntentExamples, I have this filter, corresponding to a service. <intent-filter> <action android:name="biz.rpcodes.apps.intentexamples.START_SERVICE" /> ...
1
vote
2answers
152 views

Ambiguity in method overloading

The book I am reading on Java states something confusing and unacceptable. Learning About Ambiguity When you overload methods, you risk creating an ambiguous situation - one which the ...
1
vote
2answers
117 views

Liskov principle with different constructor parameters

My first question is, is the Liskov principle applied even on constructor declaration? I mean there, am I forced to have exactly the same number / types of parameter in my constructor for each ...
6
votes
2answers
2k views

Is using for loop syntax for a “with(variable)” block an anti-pattern?

I fooled around with for-loops, remembered the with keyword from delphi and came up with following pattern (defined as a live template in IntelliJ IDEA): for ($TYPE$ $VAR$ = $VALUE$; $VAR$ != null; ...
0
votes
1answer
131 views

Do 'OR' conditional statement continue if already true? [duplicate]

I have a question in regards to Java conditional if statements. If I have a statement such as this: if(true || false){ //output } Will Java go inside of the the if statement as soon as it sees the ...
-3
votes
1answer
77 views

Manage lock of a software feature [closed]

I've wrote a standalone java SE software which executes, for example, the features A, B and C. Now, i want to that, if a lock is enabled (and this lock is a command sent remotely by my backend), the ...
2
votes
3answers
322 views

Why do most language's definition of substring allow substring(“abc”, 3) => “”

I've seen most languages have it be the case for their substring method that using the length of a given string in the method as the start index will give you an empty string. It is most definitely ...
1
vote
0answers
87 views

Best datastructure to use

I am using Amazon's dynamodb nosql database and as a result I need to think of some ways to do certain operations to fit into their limits (e.g 4k item limit, can't combine small items into the same ...
1
vote
0answers
84 views

CQRS “private” command

In CQRS, if a saga (or more precisely a process manager according to the CQRS Journey book) sends out a new command to change aggregates how can I ensure that this command is not possible to send from ...
3
votes
5answers
316 views

Is it bad practice to throw multiple custom exceptions in Java? [duplicate]

I'm developing a Java web application. It is a three layered architecture: web > service > repository. I'm thinking of creating many exceptions - each specific to each individual error and in the ...
0
votes
0answers
50 views

How to associate images in SQLite

I'm a newbie and couldn't find anywhere concise information about whether approach should I take when working with images. The thing is I'm developing an app whose main purpose is to keep track of ...
8
votes
4answers
666 views

Is this code structure beneficial in any way?

I was recently thrown into a Java web application project, and I’ve come across a number of classes that follow this type of format: public class MyThingy { private final int p1; private final ...
-1
votes
3answers
125 views

Python — Class and Object [closed]

I got a question that quite disturbs me a lot and I think it might help a lot if I had an answer to it. So I got this: class Klasse1: variable1 = "haha" class Klasse2: variable2 = "hoho" ...
3
votes
2answers
210 views

Should the main method be separate in a separate class? [closed]

In Java main methods often do little more than parsing the command line arguments and initializing an object that then takes over, for example: public class FooServer { // ... public static ...
1
vote
1answer
48 views

Should listener interfaces be nested?

In Java the observer pattern is implemented with at least one interface (often ending in Listener or Observer). Such interfaces can be placed nested inside the class or be separate, for example: ...
4
votes
4answers
175 views

Purpose of assertion messages

Some languages and libraries can associate assertion messages with assertions. Such assertion messages are included in error messages when the assertion does not hold. Examples are Java, ...
-2
votes
1answer
124 views

The eponymous class of java [duplicate]

Any Java code will always have a class which has the same name as that of the file. The whole designed program resides inside this class. However, in C++ we don't have this provision. What is the ...
4
votes
2answers
90 views

Should a generic vector class allow non-finite doubles as values?

I am currently writing an immutable multipurpose vector class in Java that essentially wraps a double[]. The class will be part of a game library, used to calculate entity positions, physics, pixel ...
-1
votes
2answers
114 views

java — multiple classes [closed]

So for my course programming with Java I want to exercise a bit. I made a project about planets. I got 4 planets with each of them containing information. I made a class Planet: public class Planet { ...
1
vote
1answer
155 views

Understanding Enums in Java

I am reading Effective Java there its told that: The basic idea behind Java’s enum types is simple: they are classes that export one instance for each enumeration constant via a public static ...
1
vote
1answer
80 views

Are there any arguments for using a local logger variable

PMD Rule LoggerIsNotStaticFinal: In most cases, the Logger reference can be declared as static and final. I seem to remember some arguments for using local variables for logging, but cannot ...
3
votes
1answer
139 views

Java concurrency

I am working to solve interesting concurrent problem! Not sure if I understand it correctly since I am little bit confused. The system needs to process the prices, and typically they cannot be ...
0
votes
1answer
76 views

Should http requests be in the constructor or in a static function? [closed]

Which is conventional? For example, this is in the constructor: public class Foo { ... public Foo(...) { // http requests } ... } and this is in the static method: public class Foo ...
0
votes
3answers
162 views

Difference of efficiency [duplicate]

I'm doing a compiler, and I'm using the System.out.println(); to print assembly; And the code get bigger, and more complicate to understand. I want to know whats is the difference of efficiency ...
2
votes
2answers
530 views

Cache Json on disk with fast read back in java/android

summary: I need a way to cache a large JSONArray on disk, and be able to quickly read AND CONVERT it back to JSONArray at a later time. NOTE: my output MUST be a >>JASONarray<<, and not a ...
25
votes
5answers
2k views

Could an instance be equal to some other instance of a more specific type?

I've read this article: How to Write an Equality Method in Java. Basically, it provides a solution for an equals() method that supports inheritance: Point2D twoD = new Point2D(10, 20); Point3D ...
1
vote
2answers
244 views

Should I unit test my subclasses or my abstract parent class?

I have a skeletal implementation, as in Item 18 from Effective Java (extended discussion here). It is an abstract class that provides 2 public methods methodA() and methodB() that call subclasses ...
1
vote
2answers
69 views

Objects with boolean data type

I have a collection of objects, and for each of them I need to know if a specific condition has been met. That is a ternary condition, it could be not yet tested, tested and failed, or tested and ...
0
votes
2answers
149 views

Relationship of Package names and file structure

I'm currently refreshing my Java knowledge and came across a question I couldn't answer yet: How does the Java compiler know where the (possibly custom) packages are located on disk? I'd assume that ...
3
votes
2answers
136 views

Better To Call In Dive Into Submethods Or Pass Around a result

I have a service that does fairly complicated business logic when it receives a request. I have most the functionality isolated into private methods which dive a couple levels down from the method ...
7
votes
2answers
251 views

Can I check the existence of an annotation in an unit test?

I have a java class hierarchy that are formed by an Abstract class and N extensions of it. In the abstract class I have a method that is annotated with a @Remove annotation. While we won't get any ...
0
votes
2answers
314 views

Why doesn't Java implement a better way of handling getters and setters? [closed]

Getters and setters are everywhere in Java, but they are managed in a horribly outdated way. Simply put: Why doesn't a newer version of Java enable a simpler syntax for managing it? Even if this ...
0
votes
2answers
160 views

How to use DAO effectively in my MMO server

I am working on a small multi player game for my final year project and currently working on the server. It's a Tank Battle game and have two main entities which I will use on the server side which ...
17
votes
4answers
946 views

Dependency Injection: Field Injection vs Constructor Injection?

I know this is a hot debate and the opinions tend to change over time as to the best approach practice. I used to use exclusively field injection for my classes, until I started reading up on ...
0
votes
1answer
190 views

Rich Model vs God Class [duplicate]

I have a legacy code containing some behaviour classes, like services and controllers. My model is pretty anemic. It's just a repository of getters and setters, and I wanna refactor it. There is a ...
0
votes
1answer
147 views

Should I use a mock or create a new instance of an object in unit tests? [closed]

I have to write a unit test for a method like: void doSomethingWith(Country country) {...} There are the following classes: Interface: public interface Country { String getName(); ... // and ...
1
vote
2answers
123 views

Don't quite understand check and set in concurrency

I don't entirely understand check and set behaviour.. here is an example: public static void main(String[] args) { List<String> list = Collections.synchronizedList(new ...
1
vote
1answer
73 views

What pattern should one use for multiple interpretations of the same data?

I have a set information that I am able to read in as raw data which corresponds to different physical quantities depending on which device provided that information. Every device contains the same ...
0
votes
0answers
53 views

How to organize common application state?

I'm creating a Java application with JavaFX, using the MVVM pattern to structure the presentation layer (don't get too hung up on the MVVM part, I think this applies to other MV-X patterns as well). ...
1
vote
2answers
139 views

Ways of creating expected object for assert

Recently, I started to use TDD. It's really cool and fun but creating expected object for assertEquals is very boring and tedious. At the moment I see only two way for that: Straightforward Creating ...
1
vote
0answers
64 views

Better choice of Queue then a ConcurrentLinkedQueue if I have low number of threads in Java

I have two threads, one that is reading messages from the web and putting them into some sort of a queue. The other is suppose to read it. I looked into a ConcurrentLinkedQueue and it looks good for ...
-2
votes
0answers
260 views

Reasons to want false-negatives when comparing strings (or string references)? [duplicate]

Java programmers know that new String("some-text") == new String("some-text") evaluates to false because two different objects/references are being compared [and that String.equals should be used to ...
1
vote
2answers
399 views

Class design for writing multiple versions of multiple files

I am writing a web service in Java which reads some information from a DB and generates multiple JSON files which are written to S3. For each type of file, I have a POJO which is serialized to JSON ...
1
vote
1answer
201 views

Best way to deal with Hibernate 1->Many relationship over REST/JSON service

Problem: A Hibernate bi-directional One-to-Many relationship does not map easily to JSON. If default (Jackson) mapping is used there is an infinite recursion issue as the parent contains the children ...
0
votes
1answer
56 views

Dynamic query from view layer

In my current job they are defining a new corporate architecture for java development. It is something like this: ProjectView: JSF view layer. Uses delegates on the ProjectClient layer. ...