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
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
136 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
312 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
143 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
187 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
44 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
128 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
146 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
669 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
85 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
23 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
221 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
149 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
191 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
65 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
113 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
176 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
79 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
110 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
399 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
123 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
75 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
71 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
142 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
141 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
517 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
99 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
115 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
464 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
54 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
386 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 ...
3
votes
1answer
330 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
82 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
187 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 ...
5
votes
2answers
448 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
208 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
306 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
126 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
159 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
142 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
222 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 ...
1
vote
2answers
224 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
133 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
106 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
vote
1answer
259 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
407 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 ...
0
votes
1answer
220 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
322 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 ...