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

2
votes
1answer
64 views

Does declaring a field as final force redundancy in the constructors?

I have the following abbreviated class: public class Player { final private DoubleDuple position; final private DoubleDuple momentum; public Player() { position = new ...
0
votes
1answer
74 views

Performance of sharing single object with multiple threads in Java

In Java, if I create an object that has a method to do something, and I pass that object to multiple threads which call the method, is there a performance difference from creating an individual ...
2
votes
1answer
239 views

Testing private methods as protected

I was reading this answer about testing private methods and it mentioned several possibilities: extract methods as public to another class make them public separate the env of test and production ...
-5
votes
0answers
24 views

java.net.BindException: Address already in use: JVM_Bind [migrated]

Server Program: import java.io.*; import java.net.*; class Server{ public static void main(String args[]){ try{ ServerSocket ss = new ServerSocket(8080); Socket s = ...
1
vote
0answers
54 views

Threading strategies for a webservice implementation

If I am building a webservice/Web API for servicing requests, there are 2 threading strategies I can think of. I will explain this in terms of Java (though the question may be relevant for any other ...
7
votes
1answer
327 views

When was Java's 'qualified this' introduced?

I've only recently learned about the qualified this, and was curious as to when was it introduced in the language, as I've been using Java here and there for around 18 years. Oracle keeps only the ...
-4
votes
3answers
343 views

How can the containsKey() method of a Java Hash Table be O(1)? [duplicate]

I had a very large ArrayList in Java, and I often need to check if it contains a particular value. This has proven very slow. Then I discovered that you can use a data structure based on a Hash. ...
0
votes
0answers
18 views

Application settings/configuration storage-Preferences over Configuration file? [duplicate]

Is there any advantage over any of these? I have application that reads its initial configuration from Preferences rather then creating and writing into configuration file somewhere in users ...
21
votes
6answers
3k views

Should a method be forgiving with the arguments that are passed in? [closed]

Suppose we have a method foo(String bar) that only operates on strings that meet certain criteria; for example, it must be lowercase, must not be empty or have only whitespace, and must match the ...
1
vote
2answers
199 views

Why Java does not have a framework like Rails? [closed]

I am a Ruby on Rails developer and I like its simplicity and rapidness. On the other hand we need to use Java for some projects that we develop for our clients. My question is why (pure) Java does ...
-2
votes
0answers
21 views

RESTful web service in Jersey [migrated]

Im creating a RESTful web service through Jersey. I followed the guide http://javapapers.com/java/restful-web-services-with-java-jax-rs-using-jersey I created the web service as mentioned in the ...
0
votes
1answer
71 views

Why are Strings in StringPool considered insecure?

Passwords are recommended to be stored in char[] instead of String, as Strings are stored in StringPool. Read more here As per this question Strings in StringPool are not available directly. To ...
2
votes
2answers
64 views

Database + Java Design for a scenario

Overview A central web application to supports other web applications(A) for user and its role/permission management. Applications (A) call the central application via API to get the user ...
0
votes
1answer
183 views

Immutable class with behavior

I've just finished Effective Java and I loved it. I'm trying to refactor one of my programs to take advantage of what I've learned, and I have a lot of questions regarding immutability. My program is ...
0
votes
0answers
51 views

Better Approach for retrieving multiple RESTful calls

I have an Android application that associates bluetooth beacons with data that is retrieved from a server via RESTful calls. Once the app is launched, we have a page with a table that is being filled ...
1
vote
1answer
91 views

Separate GUI for clients

I am writing a game in which I have a Java server/client system set up. Everything is working great, but I reached a slight problem. I have set up a basic health system, and a GUI to go with it (for ...
1
vote
1answer
47 views

Is it appropriate to pass in a derivative to calculate the error of a Neural Net?

I'm reading a guide for back-propagation of a neural net, and it gives the error function as: Next work out the error for neuron B. The error is What you want – What you actually get, in other ...
1
vote
0answers
76 views

The same objects are staying in memory across multiple executions

I was testing a neural net I created, and noticed something odd. The net uses a hashed adjacency list (roughly) to maintain its links. The vertices of the list are the nodes of the net. I chose to ...
2
votes
2answers
91 views

When should I instantiate a variable rather than grabbing it through a method?

This may be tedious, but I would love to know which is a more efficient way of programming. The result may only be slightly better or slightly worse, but I am still interested in which is 'better'. ...
4
votes
1answer
139 views

Why does Java define BigInteger / BigDecimal values of 10?

Question perhaps slightly left of field - but I'm curious as to the logic behind why Java's BigInteger/BigDecimal classes feel the need to define a constant of TEN? Example taken from ...
1
vote
2answers
122 views

Could changing the return type from void to string introduce breaking changes?

This SDK have an interface like this: public interface Contract { void update(..); void action(..); void delete(..); } Now, we need to change it to something like this: public ...
1
vote
3answers
100 views

Implementing a Generic List in Java

In an effort to understand Generics in Java (and how to use them), I am trying to implement a list structure using them but have hit a wall. Scenario: Suppose there is some classes (we'll call them ...
0
votes
2answers
152 views

Design Patterns: What design pattern should I use for the following? [duplicate]

I am trying to write an utility which traverses through a list of files and searches for a string in each file. On finding the string in a file, I will add it to a list and display the list. Which ...
2
votes
1answer
138 views

Good Coding practice with respect to interface versus class versus super class

I am currently reading the following tutorial and have gotten up through here http://docs.oracle.com/javase/tutorial/java/concepts/interface.html Maybe I should not be thinking about this question ...
3
votes
4answers
139 views

Design strategy for wrapping exceptions

I'm implementing a type of Repository for a framework/library that has (roughly) the following: public interface FooRepository { boolean contains(String id); Foo fetch(String id); void ...
0
votes
2answers
408 views

Java difference between String a = null and String a = new String()

It a pretty naive question to ask but I got this doubt while programming for android. I use to initialize my new strings like String a=null, so in my code there remains a probability to get ...
31
votes
6answers
4k views

Is throwing new RuntimeExceptions in unreachable code a bad style?

I was assigned to maintain an application written some time ago by more skilled developers. I came across this piece of code: public Configuration retrieveUserMailConfiguration(Long id) throws ...
4
votes
3answers
243 views

Is enum order sensitivity an antipattern?

Is it an anti-pattern to depend on a particular order of an enum's instance declarations? For example, consider: public enum CompassPoint { North, East, South, West; } These points ...
1
vote
0answers
56 views

How to design an interface for two similar but distinct objects

I'm designing an API for a JavaFX control to be submitted to the ControlsFX library. This control is called the ViewManager, and its purpose is to hold a collection of View instances, all of which ...
2
votes
1answer
82 views

Define an object with the interface as a type instead of class name [duplicate]

I try to practice with the design patterns and explore one of the possible implementations of the Observer Design Pattern in Java. I paid attention, that in this example the object is defined with the ...
0
votes
0answers
20 views

Database search results by deviation from query in Java

When every i try something new, I always 'throw myself in the deep end'. I'm in the initial stages of an android app build (my first android app, and first attempt at anything java) I want to know ...
1
vote
0answers
57 views

Simulating fluid transfer in a pipe [closed]

I know this is a fairly large/broad category, but I've been racking my brain over the last few weeks on how to simulate fluid flowing through pipes. In the environment I'm working, I can have a single ...
7
votes
2answers
134 views

Optional features: default method or separated interface

Dedicated interfaces seems to be a good way to expose the optional features in a domain-specific type hierarchy. However, they impede the use of decorator and composite patterns, which is also common ...
0
votes
1answer
110 views

If everything is supposed to be an object in Java (barring primative types), isn't this contradicting the point of static? [duplicate]

I often write code which makes an object and then use static methods in static classes to manipulate said object. Am I missing the point of OOP? How do I know whether I'm thinking in the OOP mind ...
1
vote
3answers
146 views

Should class with only static data need to be instantiated?

I have two classes. 1. Node 2. MixedStateManager Node class: Node class maintains the state of nodes in the system. One such data is state. public class Node { private int state; ...
1
vote
1answer
44 views

Distributing a proprietary app together with an ASLv2'ed derived work

My proprietary Java app includes a modified version of a 3rd party library distributed under Apache Software License, version 2.0. The 3rd party library doesn't come from the Apache Software ...
2
votes
1answer
67 views

Distributing a modified OpenJDK class with a proprietary app

I want to distribute a Java class I borrowed from the GPLv2'ed OpenJDK and modified for my own needs as a part of my proprietary application. The header at the top of the source file states (and I've ...
1
vote
0answers
98 views

Approach for polyglot logging

I'm building a desktop app with a Java front-end and very performance critical Fortran libraries. We've recently started pushing more of our code out of Java and into Fortran (see below) Soon we will ...
2
votes
2answers
209 views

private method that uses no instance members - better static? [duplicate]

I have a private helper method that uses no instance variables or methods, I feel it would be less confusing if it was static (this way, it's given fewer points it can access). I am a bit unsure if ...
-2
votes
1answer
122 views

Does 'Iterable' interface look redundant in java? [closed]

By this below definition(pre 1.8) of Iterable, package java.lang; import java.util.Iterator; public interface Iterable<T> { Iterator<T> iterator(); } I would say that, Iterable ...
1
vote
0answers
50 views

Best JavaFX Pane of Structure for a Graph?

I will preface this question by saying that I am studying math and computer science at a university, but I have never been very good with graphics. I want to create a window that generates a square ...
-1
votes
2answers
91 views

Using nulls as Android application logic [closed]

I'm developing some Android applications. I am using null objects as the application logic. Is this approach okay or should I take another one and which one? Example: I use null objects logic when ...
0
votes
3answers
110 views

Surface Area calculations

For my program, I implemented AABB collision which works fine. When AABB collision detects a collision between 2 boxes, I want to find the surface area of portion where the 2 boxes are overlapping. Is ...
0
votes
1answer
65 views

How to better isolate JOGL or LWJGL3 dependency from game clients?

I'm currently working on a project to develop a relatively small framework with the goal of supporting game development efforts for students in a course. The scope of this project is an OpenGL-based ...
4
votes
3answers
221 views

Creating a Java project without using any objects and just calling static methods on input?

I'm creating a program which takes a document, extracts it, and then moves this into a database. I've done most of this now and I've realised that I haven't made any instances of classes I've made (I ...
0
votes
1answer
77 views

Promise Akka Play Java Sequence

I have an actor which is having three asynchronous web service calls. Lets say A,B and C. All return promise objects which has their respective response. I added loggers processA,processB,processC ...
-1
votes
2answers
78 views

Will statically typed, compiled programming languages be affected by Microservices Architecture? [closed]

Judging based on my experience, as systems grow bigger, statically typed languages like Java or C# tend to be more reliable and easier to manage. But do we need all the advantages of such languages ...
2
votes
1answer
102 views

What is the best way to store a formula in a database for a table driven formula? [closed]

So I am changing my code over to a table driven formula system to make it sustainable in the long term. So basically I have 5 foreign keys that will get me to a single formula to use. However I'm ...
0
votes
1answer
93 views

Moving methods to a MasterClass so it can be overridden, is there a better way?

I'm looking at a very large object within the application I'm working on, which is there to basically hold all the data together at a large level. Recently, we have started moving some methods out of ...
-3
votes
1answer
124 views

Good practice to hold Constants in their own file? [duplicate]

I've noticed some projects like to store constants in their own file, i.e constants used globally and in the main program loop might clutter the main file so perhaps they look to place them elsewhere ...