Questions tagged [java]

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.

Filter by
Sorted by
Tagged with
-2 votes
1 answer
245 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 ...
30 votes
2 answers
17k views

What are the different meanings of 'fixture'?

I have some difficulty understanding the concept of "fixture". I know what a test suite is, a test case, a test run, but what exactly is a "fixture"? A parameterized test case? It seems to me that ...
0 votes
3 answers
401 views

enum for Java reference types

I need a simple enum declaring the Java reference types, as: public enum ReferenceType { STRONG, SOFT, WEAK, PHANTOM; } Does such enum exist somewhere in the Java API or a general utility ...
1 vote
1 answer
389 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
1 answer
202 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 ...
-2 votes
0 answers
285 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 ...
20 votes
2 answers
27k views

what is the difference between callbacks and listeners?

In blackberry we can override keyChar() method and capture the keypress event or we can register onKeyPressListener. i know, onKeyListener is observer pattern. In android also there is a KeyEvent....
0 votes
1 answer
1k 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 {...
4 votes
1 answer
403 views

Conventions for revision control with Maven/Jenkins

For a software project I am working on, we have a 'dev => QA => production' methodology. That is, we create a release candidate (deployed to Artifactory), give it to QA (deploy to QA systems and a QA ...
26 votes
5 answers
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 ...
0 votes
3 answers
210 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 ...
5 votes
5 answers
2k views

Java memory management (thunks/lazyness)

If I want to create an infinite list of integers in Java like so: ArrayList<Integer> list = new ArrayList<Integer>(); for(int i = 0;;i++){ list.add(i); } I run out of memory. My ...
0 votes
2 answers
3k 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 ...
17 votes
2 answers
25k 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
2 answers
165 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 ArrayList<>...
6 votes
3 answers
4k views

How to avoid halting of the JVM due to a deadlock in java?

I have read many websites talking about how to avoid and how to design etc. I completely understand those strategies. My question is based on the following preconditions: You have a company with ...
3 votes
2 answers
388 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 ...
1 vote
2 answers
122 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 ...
10 votes
2 answers
2k 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 ...
2 votes
2 answers
436 views

Design pattern for ensuring the "signature" of generic lists is equal

I have an interface, Attribute, that is going to be implemented in various ways, class AttributeA implements Attribute{\\..} class AttributeB implements Attribute{\\..} Then I'm planning to have a ...
3 votes
2 answers
4k 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 ...
5 votes
5 answers
6k views

Why is an interface in Java not allowed to have state?

There must be a good reason why Java designers didn't allow any state to be defined in interfaces . Can you please throw some light on this aspect of design decision ?
3 votes
5 answers
14k views

Java desktop app with mysql database

I'm currently in the process of learning Java and swing and in doing so am trying to create a desktop app. As part of this app I have set up a mysql database which the app is connected to, however I'...
3 votes
1 answer
12k 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 a ...
2 votes
2 answers
3k 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
1 answer
142 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 ...
1 vote
0 answers
402 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 ...
0 votes
1 answer
911 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. ...
6 votes
1 answer
2k views

Which patterns/architecture to apply for "Import Data, Process Data, Export Result"

I was wondering which architecture/patterns to choose for the following problem divided into three steps: Import TestScript Description from File (e.g. .xls, .txt) Process Described TestScript Export ...
5 votes
0 answers
866 views

How to monitor & record build (compile/test) time? [closed]

I work on a large-ish Java project. We are using maven as our build tool, and I use Intellij (14) as my IDE. Currently, if I build the whole project (c. 15 modules) it takes about 3 minutes. Due to ...
2 votes
1 answer
374 views

Finding methods that return null instead of a collection (in Java)

I'm looking for a good tool or technique to search a Java code base and find every method that says it returns a collection (List, Set, Map, etc.) but sometimes returns null. This would be a cool ...
0 votes
4 answers
3k views

Why can you have statefulness inside a static class in java?

I was playing around with Java today and I read about static inner classes. Why can you have 'statefulness' inside of a static inner class. For instance: class outerClass { static class ...
5 votes
3 answers
9k views

Heavy use of static methods in a Java EE web application?

Generally I am asking if this is a norm. The application architecture includes spring and the zk framework. I personally can't help but think this introduces a number of problems. I mean...this is a ...
-3 votes
1 answer
5k views

Why can't I return an implementation of an interface for a method that requests the interface? [closed]

I am implementing an interface I on a class A. Class A implements I. I have an Iterator T that is supposed to return an object which implements I everytime I call next. My iterator goes as follows (...
12 votes
10 answers
5k views

How to flag a class as under development in Java

I'm working on a internship project, but I have to leave before I can finish up everything. I have 1 class that is not stable enough for production use. I want to mark/flag this class so that other ...
2 votes
3 answers
191 views

Single responsibility policy problem

I'm a bit stuck using the single responsibility policy. I have a class named Parser, which can be configured to parse input a certain way. For the sake of convenience I will limit the configuration ...
4 votes
2 answers
12k views

Why does this evaluation function work in a connect four game in java

I am exploring how a Minimax algorithm can be used in a connect four game. I was looking through a program and found this evaluation function. private static int[][] evaluationTable = {{3, 4, 5, 7, ...
2 votes
2 answers
2k views

What are the justifications for annotations in a programming language? [closed]

After spending a great deal of time writing C# and looking at Java, it seems to me that annotations are just an ugly code smell that introduce another conceptual layer that could easily be replaced by ...
8 votes
4 answers
44k views

OOD: Java inheritance and access to child methods via casting

I have several classes Parent and Child1 ... Child9 implemented in Java. Parent is an abstract class, containing all the common variables of the child classes (a lot, which is the main reason why I ...
2 votes
2 answers
567 views

Create a globally visible method for an API

I'm trying to create a Java API that I will use in other projects. I understand that if I create new classes I can make objects in the other projects that have those classes. But what I want right ...
0 votes
2 answers
1k views

Meaning of using getters and setters and Uses of parameterized Constructor. [duplicate]

I am using getters and setters to for the purpose of encapsulation. public class Student { private String studentID; private String studentName; private String address; public ...
3 votes
1 answer
340 views

What to do when properties of a HashMap and ArrrayList are neccessary?

I have a data structure that stores various permission groups for a multiplayer game server. There is an instance of a "Rank" class for each permission group. Each rank also has a name. I need to be ...
1 vote
1 answer
1k views

How to avoid LazyInitializationException using Hibernate and Jersey

I am working with Spring Boot + Jersey + JPA/Hibernate to build a RESTful API. The issue I am encountering right now is when I have a relationship in my JPA Entity that is lazy loaded I get a lazy ...
2 votes
1 answer
1k views

Best way to separate public API from internal implementation [closed]

I'm developing a little framework (in Scala) where I want to define clean and simple interface for the users of the framework. Some of theses interfaces have to be implemented by the framework itself, ...
0 votes
1 answer
89 views

Subclassing vs Using properties to discriminate types

Often when writing code I wonder what the best way is to discriminate between types (by which I don't necessarily mean types used in typesystems). That brings up 3 questions: What is better? When is ...
0 votes
0 answers
124 views

If null is bad, what other approaches exist that could be implemented? [duplicate]

Null is considered bad, because of nullcheck. My question is, what other way there is, that would have replaced this null problem? How could that have been avoided?
15 votes
3 answers
11k views

Should I implement an interface directly or have the superclass do it?

Is there a difference between public class A extends AbstractB implements C {...} versus... public class A extends AbstractB {...} abstract class AbstractB implements C {...} I understand that in ...
8 votes
2 answers
921 views

How do I store multiple views of data in memory?

I have a bunch of modules. I can break these modules into different categories that are complete and do not overlap. For example, three categories, with ids that can be expressed as Animal, Vegetable, ...
1 vote
1 answer
98 views

Threads Inside Full Duplex Device Library

This is the second project I'm working on which will use a design that I'm not 100% confident about. I'd like some feedback, maybe recommendations for a better design, or verification that this would ...
6 votes
3 answers
323 views

How can I license networked applications?

I have five applications residing on server(s). Some of these applications are socket (C/C++) based, others are web based (Java, PHP). I need to give licenses to these applications on the basis of the ...

1
53 54
55
56 57
99