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

0
votes
1answer
48 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; ...
-1
votes
0answers
65 views

Understanding Piece of Java code [migrated]

While working with some code base, I am trying to understand piece of code so as can work and customize it , I am able to understand almost 90% of the code flow. Here is the overall flow Code is ...
0
votes
1answer
63 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
135 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
70 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
67 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
376 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 ...
0
votes
0answers
6 views

Generating values and keys to fill a map, and which type of map should I use [migrated]

My idea is to generate keys and values inside of a map, but I'm unsure as to what type of map I should use. This would be my very first time ever using a map, and I've heard that HashMaps aren't too ...
2
votes
3answers
112 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
53 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
62 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
116 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
134 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
449 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
84 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
102 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
372 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 ...
6
votes
2answers
326 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
94 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 ...
3
votes
1answer
301 views

Accuracy of “calculator algorithms”

I am building a library class that provides functionality for mathematical operations on BigDecimals (and a few on BigIntegers). Now, BigIntegers are quite easy to master and pleasant to use. ...
1
vote
1answer
68 views

Is JBPM the right tool for this? [closed]

We have a utility for monitoring directories and taking actions when files appear in those directories. It's in java and takes the form of a standalone jar which launches several threads when started: ...
0
votes
3answers
162 views

Java Serialization for long-ish-term storage

I have an application that uses a database of about 15,000 Java objects, which I have to read every time the application starts. Originally I've been using JSON to store the data, but that has a few ...
0
votes
0answers
98 views

Is this an spurious wakeup or just a funky (non-spurious) race condition? [migrated]

According to wikipedia: "The race conditions that cause spurious wakeups should be considered rare". But when I run this code, it is showing me that spurious wakeup happens quite often. Is this ...
5
votes
2answers
403 views

Why does java collections not supply a function for the index of max value?

I have been using Collections.max(list) for many projects, but I occasionally want to find the index of that maximum element. I feel silly writing a function to do this for myself in every program I ...
4
votes
2answers
183 views

@SuppressWarnings in coding test submission

I am working on a coding test for an employer. It is not a particularly hard question but I am trying to do it as well and technically correctly as possible for obvious reasons. I ran into a problem ...
3
votes
2answers
244 views

How does the JVM handle an exception thrown by the main method?

I understand exceptions, throwing them, handling them, and propagating them to a method lower in the call stack (i.e. throws). What I don't understand is this: public static void main(String[] args) ...
0
votes
2answers
123 views

Is there a way for Object 1 to call Object 2's enums in a function call?

For example, if I have two classes "Director" and "Follower". I want the Director to tell the follower where to go (ex: follower1.go(direction.LEFT)), and I want the Director to know what directions ...
1
vote
1answer
147 views

Divide and Conquer Algorithm clarification needed

I have a homework assignment for a data structure/algorithm class. The task is to take an unsorted array of size n (example: [-8, 3, 2, -3, 3, 1, -3, -5]), and we have to use a divide and conquer ...
0
votes
1answer
116 views

Act as MySQL server in Java/Android [closed]

Is it possible to act as a MySQL server in a Java or Android application, such that applications like HeidiSQL can connect to it? What I want to do is to write an application for Android which ...
2
votes
1answer
147 views

Converting cron schedule to time intervals

I have, on the server, many jobs defined by users and some of those jobs are scheduled using cron expressions. I need to check (I can execute Groovy/Java on the server) if those jobs take longer than ...
0
votes
1answer
112 views

When should I refactor a private class into a package-private class?

When I began implementing a class in my system (let's call it A), I realized I needed some kind of object that does something. So I needed a new class (let's call it B), but I made it a private static ...
-1
votes
1answer
129 views

Is it common to have a constructor with 7 elements for example? [duplicate]

Is it common to have a constructor with 7 elements for example? or is it better to use many setters instead?
1
vote
1answer
102 views

Java Modal Object Design

This question is not about a specific program. This is about design - the UML phase of the project. I am supervising a Java project. It will contain a lot of modal popup dialogs. From a C/C++ ...
-1
votes
0answers
27 views

MVC Application Extension reusing the service / dao layers

I am about to start my own project spun off a greater Opensource project. I am trying to get my head around best practice, both in terms of application portability and stability. To explain: ...
1
vote
1answer
255 views

When creating a library, is there a way to make certain classes entirely internal to the library, and not exposed to the user of the library? [duplicate]

Suppose you were designing a Java library for other people to use. You compile the library into a JAR that they can import into their projects and use. Needless to say, you intend for the library to ...
1
vote
4answers
393 views

How to work around Java's lack of pointers to pointers when working with linked data structures? [closed]

I've learned from a textbook how to implement binary search trees recursively in Java, and am working on implementing them nonrecursively. I've found a simple and elegant way to implement an insert ...
-2
votes
0answers
35 views

JOGL2 command line [migrated]

I have the latest version of Java and JOGL2 installed. After experimenting, I want to compile and run the most basic JOGL2 program possible. I have: import javax.media.opengl.awt.GLCanvas; public ...
-3
votes
0answers
65 views

Unable to declare Java Constants as static [migrated]

I am getting error-"Illegal modifier for parameter DEFAULT_CATALOG, only final is permitted" in below (Bold part), Why I am not able to declare constant as static. Instead of directly using variable ...
0
votes
1answer
212 views

When should a class be final? [duplicate]

I've only really seen this on Java's wrapper classes (String, Integer, etc.), but never in open-source projects, and I was never taught about it in any books or classes. I know it means the class ...
3
votes
2answers
277 views

Best approach for multilingual Java Enum

I'm running into issues with an approach I am taking and am now wondering if I just started down the wrong path and should rethink my approach. Here is what I attempting. I would like to use an Enum ...
1
vote
2answers
153 views

When I create an object, is fresh memory allocated to both instance fields and methods or only to instance fields

I have a following class class Student{ int rollNumber; int marks; public void setResult(int rollNumber, int marks){ this.rollNumber=rollNumber; this.marks=marks; } public void ...
-2
votes
1answer
104 views

JAX-RS and application wide business logic/resources. My brick wall has be found [closed]

I think I'm definitely hitting a brick-wall in understanding how to implement this. I would very much appreciate any assistance in this. All my JAX-RS links, Oracle, IBM and Stack overflow links ...
11
votes
4answers
677 views

Is it an overkill to wrap a collection in a simple class only for the sake of better readability?

I have the following map: Map<Double, List<SoundEvent>> soundEventCells = new HashMap<Double, List<SoundEvent>>(); This HashMap maps double values (which are points in time) ...
0
votes
0answers
113 views

Do thin fluent builder method chains have any need to be “extensible”?

In an environment where refactoring is difficult extensibility can be a life saver. However, this is no excuse to over engineer code. Given that a thin fluent builder method chain is backed by well ...
0
votes
2answers
158 views

How to connect Android App to MongoDB deployed on Google Cloud

Currently I am working on a simple app which will be able to connect to MongoDB which is deployed in Google Cloud. I have set it up MongoDB ocaly on my computer and I have made a little JAVA console ...
2
votes
3answers
128 views

Proper interface for calculator library?

As practice, I'm planning to implement a multivariable calculator library. The idea is that you can define a function, such as f(x, y) = sin(x)^2 + 3*y^3, and then you can evaluate it with specific ...
0
votes
2answers
236 views

Organizing code in a 2 man team

I've been working with a buddy of mine on a school project. We forecast it'll take ~2 months, so it isn't a small scale project at all. Communication and splitting the work effectively has been a ...
0
votes
0answers
44 views

Mixing newable and injectable in a Callable

I recently read http://misko.hevery.com/2008/09/30/to-new-or-not-to-new/ which discussed newable vs injectable objects. What would you do if you needed to make a Callable that talks to some service ...
1
vote
2answers
180 views

Java Desktop Application Requirement - Is sockets the preferred choice ?

I'm currently working on a requirement for a desktop application - using Java If for some reason the GUI crashes, it shouldn't affect the background process. Once the GUI is restarted - the ...
0
votes
0answers
101 views

How far to go when future proofing fluent-method-chained-DSL test code?

Is it worth implementing interfaces, or using the getThis() trick, or even static factory methods to future proof against the need to extend this DSL? The current design is a pair of thin ...