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

53
votes
8answers
8k views
+50

How do you avoid getters and setters?

I'm having something of a hard time with designing classes in an oo way. I've read that objects expose their behavior, not their data; therefore, rather than using getter/setters to modify data, the ...
-1
votes
2answers
54 views

Comparing an object with a String using equals() method

I hope this example clarifies everything. public class flower { String flower; public flower (String flower) { this.flower = flower; } public static void main(String[] args) ...
1
vote
1answer
240 views

Avoiding long list of interfaces

Motivation Let a project where... ... exists a lot different behaviors. For each behavior, there is an interface which has its possible actions. One object could perform a lot different behaviors. ...
0
votes
2answers
523 views

Is factory pattern a right pattern for the situation described here?

Is factory pattern a right pattern when we want to consolidate the related objects? Problem - In the Set-top box, I have a user-io, basically the interface to control the settop box - The user-io can ...
0
votes
1answer
107 views

What would be the best way to implement priority based programming without adding too much of if-else processing logic

We need to add priority based programming in our application using java programming language. For example, there are three priorities that a phone can have: A1, A2 and A3. Also there can be three ...
0
votes
1answer
61 views

What are the time and space complexities of this recursive method that reverses a singly linked list?

What are the Time and Space complexities of this Java method that reverses a singly linked list (of length n)? I'm more interested in knowing the reasoning behind the space complexity. Let me know if ...
-4
votes
0answers
44 views

What Do These Java Scanner error mean? any solutions? [on hold]

I'm a beginner so please bear with me. I'm getting the following error upon running: Exception in thread "main" java.util.NoSuchElementException at java.util.Scanner.throwFor(Unknown Source) ...
0
votes
1answer
85 views

Design: Bridge Game

I'm making revisions to a Console version of contract bridge I made in Java. The source can be found here: Bridge So most of the code is terrible and I've been trying make improvements wherever ...
1
vote
4answers
1k views

Why 'List<E>' is an 'interface' but not 'abstract class'?

Amidst defining the hierarchy, firstly, one can think to embed the abstract method(behavior) in abstract class only because the derive concrete class possess that behavior as core behavior with it's ...
-1
votes
2answers
102 views

Non-null alternative to Void (Java unit type)

I have a map-like type SmurfMap<K, V> which in certain contexts I use as a set-like SmurfMap<K, Void>. Implementation details forbid the values of the map from being null, so I cannot ...
3
votes
4answers
1k views

How to force “program to an interface” without using a java Interface in java 1.6

In java 1.8 they have wonderful new "default interface methods". In 1.6 how close can we come? The goal: use code to keep clients from being able to tell that a class is not a java interface. If we ...
4
votes
4answers
189 views

Single method with many parameters vs many methods that must be called in order

I have some raw data I need to do many things to (shift it, rotate it, scale it along certain axis, rotate it to a final position) and I am not sure what the best way to do this to maintain code ...
0
votes
0answers
72 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 ...
2
votes
1answer
182 views

Debugging xml and annotations

By now, most web containers have an annotation variant of their xml configurations for Java EE. I'm guessing this is because it's better to keep things in Java where they can be managed, coded with ...
1
vote
1answer
87 views

Is a class representing a JSON response a DTO, a domain object, or something else?

Consider a restful service in Spring MVC. I am wondering how to package my response classes, i.e. how to name the containing package. First I thought of them as being domain objects. But they are ...
0
votes
1answer
105 views

Converting from List<Object> to Array with threads

I have a large (>500.000) list of Objects and I want to convert it a multidimensional array. Until now I am doing this using a for loop, but after some measurements I identified that this is a ...
9
votes
6answers
393 views

Does it always make sense to “program to an interface” in Java?

I've seen the discussion at this question regarding how a class that implements from an interface would be instantiated. In my case, I'm writing a very small program in Java that uses an instance of ...
1
vote
1answer
286 views

Is this database design good? What JPA Entities should I create for this design?

I am trying my hands on JPA. For this I am thinking of using the example of a student admission process as shown in the diagram below. Is this design good ? Any suggestions for improvement are ...
1
vote
1answer
108 views

Java partial enum backed by the database

I have following problem: need to use enum in my java code, since I'll have to ask in my business logic things like if(someting == enumname.VALUE_ENUM){... but I don't have all the enum types at the ...
1
vote
2answers
44 views

Expressing interface inheritance in natural language [duplicate]

In object-oriented programming, when you extend a class you establish an is-a relationship between a new subtype and its parent(s), i.e. B is an A (aka code inheritance). When you compose a class with ...
-2
votes
1answer
30 views

What is Multipart Image upload? [on hold]

Can someone please explain what does Multi part image upload means and it's advantages. When should i use multipart image upload?
1
vote
2answers
118 views

Designing Message class in Java

I'm writing a class for Message. Message comes with Header and Payload. Header has following fields: Version Type For Type "XYZ", the following Payloads are allowed. Configuration Metafile ...
-2
votes
2answers
86 views

How would you structure your code for a Neural Network? [on hold]

I understand how Artificial Neural Networks work. However, implementing one in code is quite another thing. How would you go about designing the classes and data structures? I found one great ...
-6
votes
0answers
21 views

How to align a nucleotide sequence against a set of them in a database? [on hold]

How to align a nucleotide sequence against a set of them in a database? Need a sample Python , Java or Ruby code showing the alignment of an input 1000 bp sequence against a set of them. I could find ...
0
votes
1answer
41 views

Getters with data conversion in Java VOs

I am working on a standard Spring application where DAO layer returns entities to service layer and service layer returns VOs to other services and controllers. In a certain scenario, we have a VO ...
5
votes
2answers
125 views

How do I deal with the following technical issue?

I am a Java Programmer and I am relatively new to Java(1 Year). I am working for a small startup company. My problem is a bit strange and I am facing it a bit difficult to deal with and explain also. ...
3
votes
3answers
97 views

Would implementing a “Throwable Event System” be abusive?

I have been thinking for a couple years now about using Throwable events and implementing a sort of event system that uses throw to dispatch an event, or let a different method handle it with throws. ...
4
votes
1answer
207 views

Is Collection.stream().filter().forEach() inefficient compared to a standard for each loop?

IntelliJ IDEA recommended to me just now to replace the following for-each loop with a Java 8 "forEach" call: for (Object o : objects) { if (o instanceof SomeObject) { ...
3
votes
2answers
103 views

Domain object model: query by id vs object

Let assume I have two simple model classes: Product and Brand It is obvious I have a query method in Product class like this Product product = Product.findById(123); What if, I want to query ...
-4
votes
0answers
24 views

How do I solve this java problem? [on hold]

I cant solve this problem which is given by AIDE ANDROID APP Please tell me the answer(because i am a beginner) I know it is simple but i am confused with that "mean" error please help me! Q- Now use ...
-4
votes
0answers
33 views

Shadowing vs Inner class's access only to final variables [on hold]

In Java : Shadowing allows us to modify any variable with same name in an inner block but how is it possible when we have access only to final variables in an inner class?
0
votes
0answers
21 views

How to illustrate the difference between forward and backward compatibility [duplicate]

Please correct me if I'm wrong, but a new version that can run old code is backwards-compatible and an old version that can run new code is forward-compatible (like an old B/W television can receive a ...
1
vote
3answers
164 views

Using prefix/postfix increment operator for simple incremental array access rather than actual index numbers

I cannot decide which method is better with consideration of both readability and fault-tolerance. Method #1: Object[] objects = getArrayOfKnownLength(); int i = -1; someMethod(objects[++i], ...
-1
votes
0answers
35 views

Which patterns to apply for “User Manager” [on hold]

I developing a social application and I neeed to create a User Manager that is responsible for managing certain types of user. A user who enters in to the system will be a new user or an existing ...
43
votes
7answers
7k views

How to deal with static utility classes when designing for testability

We are trying to design our system to be testable and in most parts developed using TDD. Currently we are trying to solve the following problem: In various places it is necessary for us to use static ...
4
votes
1answer
378 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 ...
-1
votes
0answers
19 views

Weird Override and implementation [migrated]

I am currently programming an android app, but I have a problem. I want to use GreenDroid for my project but while compiling the compliler give me an error : The return type is incompatible with ...
5
votes
2answers
351 views

Is it possible to use the Android layout system in a desktop java application?

I am lazy, thus, if possible, I would like to only have to design and program a UI once. If I want to create an App for Android and as a basic Java desktop application, is there a way to reuse the UI ...
1
vote
1answer
113 views

Differences in design/thought process for OO in Java and JavaScript [duplicate]

Despite sharing a similar name and syntax, Java and JavaScript are quite different. However, they both have Object Oriented features. As a JavaScript novice, the main differences that I can see ...
-3
votes
0answers
24 views

How to launch browser from Java WS and log on page by SSO?

I have an Java Web Start application which communicate with J2EE server application (JBoss). User is logging in (login & password) and after that doing some operations. Now I would like to add a ...
0
votes
0answers
26 views

Handling server failure using serialization

In my program, there is a central server, and I want to store its state. I'm using serialization for this, I am serializing the data after every 2,3 seconds. So that whenever server fails, it can come ...
4
votes
5answers
440 views

Is it okay to go against all-caps naming for enums to make their String representation simpler?

Several times I've seen people use title-case or even all lower-case naming for enum constants, for example: enum Color { red, yellow, green; } This makes working with their string form ...
-2
votes
1answer
80 views

Java - Concept question: LinkedHashMaps vs POJOs?

EDIT: I'm just going to ask a single question instead of presenting a problem and asking for advice on a specific design decision in the solution. Given a batch of data from a database, collected ...
2
votes
3answers
130 views

How do I show 'creates' in a UML class diagram?

Let's say my code is going to look like this: public class MyController { private Foo foo; private FooGenerator fooGen; //setters public void work() { this.foo = ...
-1
votes
0answers
33 views

Spring-Quartz scheduler throw NoSuchMethodException [closed]

I'm using Spring MVC to develop my project and I want to use quartz-schedule to set time for an method in controller. But there is java.lang.NoSuchMethodException occurred. This is my declared code: ...
2
votes
2answers
165 views

return a object without returning the reference

i'm having some trouble with returning objects and lists of objects. To problem is I want to return a object in my example an developer but I don't want to give the reference. What's the best ...
0
votes
1answer
57 views

how can the presenter or view interact with the model in the MVP pattern?

I'm learning the MV* patterns. MVP in this case. I'm trying to refactor an old android application into the MVP pattern to make things less tightly coupled, but I'm struggling one one concept. I know ...
0
votes
1answer
53 views

Using Websocket for a multiple-page website

Is using Websocket (in particular, in a Java, SpringMVC webapp, with the Spring Websocket support libs, but the question probably applies to any language) for a multiple-page website a bad idea ? ...
2
votes
2answers
191 views

Problems with OO design for application with pluggable components

I'm trying to refactor an ugly code and make it easly extendable in the future. The application should be nothing else but a series of components that have input(s) and output(s). The components ...
5
votes
2answers
189 views

Does sun.misc.Unsafe give access to the system or just the JVM?

Please note: Although this question involves microcontrollers, it is at its core, a Java question, and so I believe it can be answered by any battle-weary Java guru. I stumbled accross this blog ...