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

1
vote
1answer
92 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 ...
0
votes
1answer
193 views

How to spawn multiple “monsters” from a single class [closed]

How to spawn multiple "monsters" from a single class? Can store it in an array, ok, but later on, how can I paint it? Because if I do: enemy = new Enemy(); enemy2 = new Enemy(); I create two ...
17
votes
7answers
2k views

What can one do to improve readability of math-oriented code in C#, Java, and similar? [closed]

As both a C programmer and a C# programmer, one of the things I don't like about C# is how verbose math functions are. Every time you would have to use a Sin, cosine, or power function for example, ...
1
vote
3answers
384 views

Pluggable UI Components in Java Web Applications

I will try to explain my question with an example. Let us say that we are writing a hotel reservation system which is web based using Java. We will have different payment methods, say Paypal, Master ...
1
vote
3answers
229 views

Implements > extends, but what about variables?

It's preferable to write programs that depend on interfaces rather than on superclasses, but what when you want a class to have certain variables? Sometimes you want a class to implement a certain ...
0
votes
2answers
135 views

Should I have an object as attribute or primitive id? [duplicate]

I am wondering which principle should I use. Here is my situation. I have a class named TravelOffer. This class looks like this: public class TravelOffer { private final long id; private ...
1
vote
1answer
93 views

Best approach to a defined datastructure

I have a plain text file with some data that I can't change, so I have to create a datastructure to use in reading the file and with that datastructure do some thousands of interactions. The file ...
0
votes
2answers
247 views

What type of structure is this in java?

I was reading the following code listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) ...
2
votes
1answer
156 views

CopyOnWriteArrayList: Why do we have to make a full copy of source data?

I have a lot of confusion about Java's CopyOnWriteArrayist. I know, when we have a modification on it like update, insert of set, it will lock the whole list, copy out a total copy of the source list, ...
1
vote
4answers
389 views

Should all programmers know how to solve algorithms, etc [closed]

I'm 15 and have been programming for about 3-4 years. I mostly program in Java as it was my first language. I would like to be a programmer when I'm older, but I'm not sure about the differences. ...
-3
votes
1answer
55 views

Java Licenses, GPL, GNU Questions

I would like to ask a few questions about software licenses, with regards to a (Java) program I am making. I am very very new to licenses, so please bear with me. 1. If I produce a Java program using ...
0
votes
0answers
34 views

Java API initialization step

I am developing an Android Library which involves both Network and Bluetooth communication. In order to start using the library it must be configured. In other words a request to the backend must be ...
0
votes
1answer
228 views

Separating UI from logic

I'm trying to develop a little game and for this I'd like to separate the UI from the game logic. So I'm thinking of using an "Animator" class that will be responsible for rendering the objects, but ...
1
vote
2answers
152 views

Ensure scheduled event only runs once a day?

In a hobby project of mine, a "smart home" for controlling lights, I'm planning to create a feature which turns off all lights at a given time of day. There are also several other features which runs ...
2
votes
1answer
82 views

Is there a limitation when using the Bloch's Builder Pattern with mandatory fields?

Background I have a class TextDrawable which draws text on top of a shape. There are a number of properties that can be set while creating a TextDrawable object. Mandatory Properties: Text Shape ...
1
vote
1answer
179 views

Best OOP pattern to use for creating a commandline SQL API for a proprietary json based company datastore

We need to create a SQL commandline tool for querying a proprietary json based datastore. I'll be using java. Any suggestions on the primary OOP design pattern I should use for building this API? ...
0
votes
1answer
87 views

when would you wrap a service object with an interface? [duplicate]

I'm new to UT and some of the best practices and anti-patterns when writing testable code, made me think. I used to wrap any service object with interface. but I see many mocking frameworks can ...
0
votes
0answers
54 views

when would you write static method as it avoid a “seam” for testing [duplicate]

when would you write static method. I used to write it in utils classes where all the methods are static and work state-lessly on arguments only. But now I know it blocks from creating a seam in ...
0
votes
2answers
164 views

Java Multithreading and CPU cores [closed]

I have a simple question this time. If I write an java application with 4 Threads ( each thread does different work ), what will be the difference between single-core, dual core and quad core cpu ( ...
3
votes
3answers
315 views

Immutable objects [closed]

Looking at questions such as these If immutable objects are good, why do people keep creating mutable objects? What are the drawbacks of immutable types? At what point do immutable classes become a ...
0
votes
1answer
150 views

Ensure that a method of a class is called after every method call of the same class, how? [duplicate]

I have twenty small methods (m1, m2, m3, etc..) in a class quite different between each other, and after every method i would like to do some common actions, like increasing some counters and in the ...
2
votes
2answers
188 views

Design - Parser.hasInfo(MyClass) vs MyClass.hasInfo()

I'm working on a document processing system. I feel confident with a Document class which represents each document being processed. The issue: Each Document can have a CoverSheet, and if it does, ...
0
votes
1answer
48 views

Custom mobile app and custom server app [duplicate]

I have this little bit simple and general question. Let's say I build an android app which requires an online server to communicate with. The thing is that I want to make the communication on my own ( ...
0
votes
3answers
131 views

At what level of abstraction are data structured created?

I am learning about Linked List and Arrays in my data structures class. We are make them in Java. Are actual data structures designed in Java/C? Or are they made in lower level languages like ...
0
votes
3answers
148 views

How can DB and UI agree on default values?

I created a table in a Postgres database. I would like to create a form in a Java application to insert rows into that table. Certain fields have default values. What is the best way for the database ...
8
votes
3answers
682 views

Clean Code and Hybrid Objects and Feature Envy

So I recently made some major refactorings to my code. One of the main things I tried to do was split out my classes into data objects and worker objects. This was inspired, among other things, by ...
1
vote
1answer
90 views

Check word density within a document

Here is the situation: I have a Document(d) and a set of keywords (Set<String> keywords). I like to check the density of each words from set keywords with d. I have few solution but not really ...
0
votes
0answers
26 views

Designing Document class for Doc Imaging - optional fields

I'm working on a project that processes many Documents. A Document CAN have a Cover Sheet (if the first page is one) A Document CAN have a Stub (if Document is large) It matters whether or not a ...
2
votes
3answers
346 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 ...
1
vote
1answer
160 views

Should I declare the most specific type as return type of method?

Sorry for my English In Android I can put only ArrayList of Parcelable objects in Intent: Intent putParcelableArrayListExtra(String name, ArrayList<? extends Parcelable> value); I can't put ...
0
votes
0answers
50 views

Standard for expression of relative dates [duplicate]

I'm looking for some kind of standard way of representing dates or dates ranges (for reporting parameter purposes) using expressions. This expression can represent both absolute and relative dates. ...
2
votes
1answer
233 views

What are the main differences between C++ templates and Java generics? [closed]

I'm a beginning C++ programmer coming from Java. It feels to me that C++ templates and Java generics are actually pretty similar. You use them in pretty much the same occasions and in the same way. ...
0
votes
1answer
83 views

Where to put JPA annotations? Field, or getter?

version in field: @Column(name = "SAMPLE_STRING") private String sampleString; public String getSampleString(){ return sampleString; } version in getter: private String sampleString; ...
0
votes
1answer
172 views

Logic based on modified fields of a Hibernate entity

I have a Hibernate entity object MyObject with several attributes and a service MyObjectService containing business logic dealing with MyObject. I also have a view model dealing with user input/output ...
-1
votes
1answer
271 views

How to compare two different hashset objects with more than 100,000 records

I have two classes class A{ int id; String name; public boolean equals(Object o) { if(o instanceof A) { A a=(A)o; if(a.getId().equals(this.getId())) ...
0
votes
1answer
80 views

Project configs for Java projects

How to store configs for project in Java. In normally case i stored it in 'src/main/resources/' with *.properties. How best approach for storing projects config for development, local, production ...
0
votes
1answer
154 views

Spring web application deployment infrastructure

I'm interested in hearing out what's out there in terms of tips and tricks on deploying and maintaining a Java web application whilst keeping agile. I'm running solo on a startup project I'd like to ...
3
votes
4answers
408 views

Java - Is it possible/good idea to reduce chance of crashing by catching Error?

I have a class the implements A which will run a certain method of class B. There is a requirement that this A should never crash when running this operation (which is not possible, right?). To ...
2
votes
3answers
128 views

Why return back or assign to a supertype rather than the implementation type?

I have been doing a lot of reading about polymorphism, inheritance and typing (specifically how it applies to Java). I have seen some interesting examples, but not much explanation as to why. I.e.: ...
0
votes
1answer
98 views

String sentence consistency when sent over sockets

I am learning socket programming. I have a Java application as my server, and C# for the client. Just sending string lines from one to another. Below I have code snippets showing how I am currently ...
0
votes
1answer
78 views

Coordinating a complicated data migration process

A project I'm involved in has suffered a change in scope, and before I set about trying to cook up some homegrown solution, I'm wondering if there is something out there -- some framework, for example ...
0
votes
1answer
191 views

Why overriding a static method does not result in polymorphism in java

Many say that we can not override a static methods. But we can override a static method. The question is, when we override a static method why it does not result in polymorphism ?
-1
votes
2answers
149 views

Is enum not a class? [closed]

I was just exploring enums. One thought came in my mind- what if a class can extend enum. I understand this is not practical, but what surprises me, is the compiler error given- "The type MyEnum ...
3
votes
4answers
615 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: keep clients (using code) from being able to tell that a class is not a java interface. If ...
-1
votes
1answer
107 views

Heap vs Stack Memory in java [closed]

I have some doubt on Heap and stack memory in java.. whether those are memory space or algorithm(procedure) of storing data at run time. Here is the class class HeapStack { String str = ...
0
votes
1answer
119 views

Static methods vs Interface implementation

Here is my problem: I stared to create a e-commerce web sites info collector. So i created a parser for each site. The parser class is state less. got methods like: getItemPrice(WebElement page) ...
0
votes
4answers
768 views

Why is no default constructor generated if you define an explicit constructor?

class Employee{ String name; int id; //No explicit constructors } Now i can invoke the following statement Employee e1=new Employee(); Now the compiler( i'am not sure about who ...
1
vote
2answers
63 views

Class template specialization for implementing Automata

I'm implementing classes for simulating and generating different kind of automata. I'd prefer to use the same State and Transition classes for all the automata: NFA, DFA, PDA, etc. For a PDA a ...
6
votes
2answers
468 views

What is the difference between uninitialized object variable and object variable initialized to null in Java

I have the following two object variables Date a; Date b=null; Definitely both 'a' and 'b' are not referring to any objects. Now if I invoke following statement System.out.println(a.toString()); ...
-3
votes
1answer
96 views

How can I test a method which aggregates data from a database? [closed]

I'm developing the web Java application and come across the following issue: I'm using jUnit 4.5. Suppose that I have a method which aggregates data from a database for the rendering their to a ...