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

6
votes
4answers
406 views

Applying DRY to an inheritance hierarchy

I'm working on refactoring a legacy application where I implemented the State pattern successfully as shown in the following diagram: As you see there is a common behavior between the 3 states, so ...
1
vote
1answer
210 views

ORM: Keep entities coherent in a cache or retrieve entities each time?

We have a tricky question in a project using Java & Hibernate, with a model containing bi-directional relationships. As it's a small project with few users, few entities, and few rows involved in ...
2
votes
2answers
683 views

Should my login logic be part of the controller or a service in MVC webapp

I'm using Shiro as my security manager for a Spring MVC web application. The login basically happens in these lines: Subject user = SecurityUtils.getSubject(); user.login(new ...
2
votes
2answers
231 views

need advice for building evaluation system in Java for the web [closed]

I have made a java program that allows to mark an exam made by one student. In the interface the student chooses between a set of options for each question, and by an array (that holds the correct ...
4
votes
3answers
1k views

var args constructors/methods vs lists

In the long debate of using arrays vs lists in the public API of Java classes, I tend to prefer lists in most situations. However, I also found convenient to use var arguments in many constructors and ...
5
votes
5answers
2k views

In Java, should private helpers go above or below public methods? [closed]

I've noticed that a coworker and I have opposite practices regarding the ordering of methods in our Java classes. One of us begins a class with its major public methods, and then put all of the ...
2
votes
1answer
1k views

OCR API (in Java) with Word (NOT MS-WORD) extraction [closed]

My Situation I need to develop an application which does crowd-sourced Image-To-Text service (just like google's reCaptcha). So I need an OCR API which can find words in an image with some text. ...
4
votes
4answers
430 views

Should we validate a state transition before attempting it in the State Pattern?

When applying the State Pattern illegal transitions should result in an exception being thrown (or at least that's what I understood from the pattern) I know exceptions are for "unexpected behavior" ...
0
votes
2answers
467 views

Design Pattern For Util Classes and General Static Variables

I am developing a Mojo(think it as just a usual class) for my custom Maven Plugin. There is an Abstract Mojo at top. I have some other custom Mojos in example which makes server side includes. I have ...
1
vote
2answers
130 views

@Deprecated as of version x.y in JavaDoc

This question & its answers are useful but not sufficient for my problem. My Question is if I want to add a javadoc as @Deprecated As of version x.y, replaced by {@link SomeClass} in my current ...
2
votes
2answers
405 views

Web application (Spring, JSF) forks, how to reuse existing code for subprojects?

my question is going to be somewhat philosophical and "architectural oriented" so bear with me. Right now we have existing Java web application built on top of Spring and JSF(facelets) with maven. ...
2
votes
1answer
377 views

How can I break my vendor lock-in situation?

I'm developing software for about 10 years. I began on QBasic and now I'm developing .NET using C# language. I'm always trying to follow the best design patterns and principals like SOLID. In short ...
5
votes
2answers
212 views

Is it fine to use logs in the Helper Methods?

I have been doubting for a long time whether or not to have a logger in methods (usually helper methods) like the one below. Whether we can print it in the method or print the response where the ...
7
votes
4answers
2k views

Java labels. To be or not to be [closed]

Before I start this question I know the java 'goto' is a big no go. So I've been writing a program and I have some indented Loops and statements and I need to BREAK multiple on command. Rather than ...
5
votes
4answers
763 views

Differences in If… Else… statement

When I first started to learn programming I remember having an argument with my teacher about If Else statements. I was arguing that: if { ... } else if { ... } ... is basically the ...
3
votes
6answers
1k views

Would md5 hashes allow detection of synced files?

We have to develop our own file management system in Java web application. We need to sync files between our main server and client severs and find out whether all the client server has all the latest ...
5
votes
1answer
712 views

How to include licenses for third-party Maven dependencies?

I'm producing a binary distributable for my Java project. I'm releasing it in two ways: Maven Central Zipped distributable on Google code My project is licensed under the Apache 2.0 license. I use ...
7
votes
7answers
3k views

Should I create interfaces for data transfer objects?

Is it a good idea or a bad idea to create an interface for data transfer objects? Presuming that the object is usually mutable. Though my example is in Java, it should be applicable to any other ...
5
votes
1answer
517 views

Copyright notice in CSS or XML files

I'm currently working on an open-source project. Currently, we put our copyright notice at the top of every Java source file. I was wondering whether it was advisable or common practice to put ...
13
votes
2answers
595 views

Should my small software library avoid using other libraries?

I've just released a small Java library that offers only a few classes and methods. Since I built the project with Maven, I immediately used several third-party libraries to achieve my goals, ...
-1
votes
2answers
950 views

Should I use simple socket programming to communicate between 2 threads? [closed]

Is it a good idea to communicate between 2 threads using sockets in Java? What I am trying to achieve is Inter-process communication using socket programming/RPC mechanism.
9
votes
1answer
9k views

Design pattern for object conversion (java)

I don't use design patterns very often, besides an occasional factory and MVC, and I want to start using them more. I have a concrete case at hand that I would like your opinion on the use of design ...
4
votes
2answers
272 views

MVC - Isolating view and model logic

I understand that the model should generally consist of data manipulation and the view for data display from the model, but how do I keep my model and view layers decoupled? My simple view has a few ...
-1
votes
1answer
618 views

Appropriate selection of security framework [closed]

I have a web application to be developed using RESTeasy API and for this I have to implement security (Form based authentication). So i am not sure about the most appropriate fit for this. As I ...
5
votes
2answers
1k views

Visitor stability vs instanceof flexibility

I am working on a GUI application which generates a configuration file. I have a class hierarchy for the configuration model and I use an object tree of that hierarchy in several different contexts. ...
2
votes
1answer
568 views

MVC - sharing multiple models

I am building a java desktop application where I am attempting to implement MVC. The GUI interface has multiple views (think pop-up windows) from the main view. Each view has its associated model that ...
8
votes
8answers
4k views

Why Java does not allow function definitions to be present outside of the class?

Unlike C++, in Java, we cannot have just function declarations in the class and definitions outside of the class. Why is it so? Is it to emphasize that a single file in Java should contain only one ...
-1
votes
4answers
556 views

Importing java.awt.* does not automattically imports java.awt.event.*?

In the Java programming language, why does importing of java.awt.* does not automatically import java.awt.event.* too? Now, you guys may say that it's because it's java.awt.* and not something like ...
3
votes
2answers
805 views

How to remove duplicate exception block code

I have good number of Service and DAO classes which has the same set of 30 line exception code block which gets repeated and it shows up in Code Duplication report. The approach which i can think of ...
2
votes
6answers
999 views

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

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 ?
9
votes
5answers
8k views

throwing runtime exception in Java application

I am working as a contractor designing enterprise Java application for my client in the role of a technical lead. The application will be used by end users and there will be a support team who will ...
11
votes
5answers
1k views

How to code in a more functional style in Java?

I code Java for at least 5 years now and I really appreciate how the language works. When looking at new JVM languages (e.g. Scala, Clojure) there is a trend to more functional ways to code and this ...
1
vote
1answer
220 views

Designing a list class with filtering and sorting

The app I'm developing needs to display lists of items. Simple enough, but there are a number of things which can change based on user input: Items can be added to/removed from the list. The items ...
54
votes
11answers
5k views

I've been told that Exceptions should only be used in exceptional cases. How do I know if my case is exceptional?

My specific case here is that the user can pass in a string into the application, the application parses it and assigns it to structured objects. Sometimes the user may type in something invalid. ...
15
votes
3answers
911 views

Does decoupling trump DRY in REST?

I am building a REST API to expose most of functionality of an existing Java API. Both APIs are for internal use within my organization; I do not have to design for external use. I have influence ...
0
votes
1answer
119 views

Running pieces of code distributed through out the system, automatically

I have pieces of code, written in java, which I can convert in jar and run from the terminal. I also have some node.js script, which I would like to run before running these jar files. So the ...
2
votes
1answer
317 views

Does it make sense to create a Ruby wrapper to reference a Java object that does exactly the same thing?

I am using JRuby. In my Java code, I have a class called Texture, capable of doing some graphic manipulation stuff. In my Ruby code, I will usually need to draw things, so though I should simply ...
4
votes
5answers
796 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 ...
1
vote
2answers
630 views

Parsing a Log File - Java

Im reading a log file in Java on a Linux box on a continual schedule of 2 minutes looking for certain messages. I store the last offset (RandomAccessFile getFilePointer) and read from it onwards when ...
1
vote
1answer
910 views

Understanding open and listening ports

I developed an app in Java (which is working perfectly; with this app you can scan TCP/UDP ports -for testing purposes only-), but meanwhile when I was writing the code I read several documentation ...
3
votes
1answer
248 views

Best Traversing Strategy / Logic Help Needed

Background: Here is the scenario, imagine I have a little Robot. I give this robot a Map, and I want him to traverse the map, after doing so, I want the Robot to tell me the shortest possible path on ...
19
votes
4answers
4k views

Why does Java not do type inference?

I have always wondered why Java does not do type inference given that the language is what it is, and its VM is very mature. Google's Go is an example of a language with excellent type inference and ...
2
votes
6answers
4k views

Frustration with Java Swing layout managers

I have been trying for years to master Swing layout managers with no success. Every time I need to do something with Swing, it is like pulling nails to get the visual components to line up the way I ...
6
votes
4answers
5k views

Replacement for instanceof Java?

So I'm fairly new to programming in the real world (outside of academic projects) and have come across lots of posts saying that using instanceof is a bad thing to use to determine what class a ...
3
votes
1answer
480 views

Java Logfile Parsing Assistance

I'm writing a log parser that continuously looks for specific patterns and then fires off events to another system when it finds these matches. The firing of the event is time critical to catch errors ...
14
votes
1answer
919 views

Considerations on which Java version to run in Production

Some people run the bleeding edge of technologies - updating the day that something is updated. In production, this isn't as appropriate. Researching about if the current (Java 7) version is ready ...
2
votes
2answers
2k views

Realtime (almost) bidrectional communication in Java

I will explain the context of the problem first. For a University project I'm going to implement an Android application. The Android application (and others) will be able to send data to a remote ...
2
votes
2answers
6k views

How to increase the efficiency of an Immutable Queue in java?

I have been developing an Immutable queue in java, but the version I have developed is supposedly slow and I have been suggested to create a faster version of the same and I have no idea as to how to ...
5
votes
1answer
505 views

Is this an example of recursion?

I am implementing inheritance of something called Contexts. Each Context holds a link to its parent context. If that Context is the root Context, its parent is null. In order to walk up the ...
4
votes
2answers
1k views

Why shouldn't you use JDBC in Java applets?

I've heard people saying usage of JDBC (Java Database Connectivity) isn't recommended in Java applets. All I they say is: 'because of the security reasons'. What 'security reasons' do they mean? What ...