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

-3
votes
1answer
107 views

Why can't I return an implementation of an interface for a method that requests the interface? [closed]

I am implementing an interface I on a class A. Class A implements I. I have an Iterator T that is supposed to return an object which implements I everytime I call next. My iterator goes as follows ...
4
votes
0answers
455 views

How to monitor & record build (compile/test) time? [closed]

I work on a large-ish Java project. We are using maven as our build tool, and I use Intellij (14) as my IDE. Currently, if I build the whole project (c. 15 modules) it takes about 3 minutes. Due to ...
1
vote
2answers
225 views

What are the justifications for annotations in a programming language? [closed]

After spending a great deal of time writing C# and looking at Java, it seems to me that annotations are just an ugly code smell that introduce another conceptual layer that could easily be replaced by ...
8
votes
1answer
230 views

What is the difference between “kk” and “HH”+1 in ISO-8601?

In the ISO-8601 there are multiple hour formats, one of them is "kk" for hours 1-24. What is the purpose of this? Are there countries that offset their time? Is it for military usages? The ...
2
votes
0answers
100 views

How to distribute the number of elements in a bucket so that it is Within a Range - Algorithm

I have been solving a problem where in say I have 50 elements n1, n2, n3, ... , n50 Now I have a limited number of buckets, say 5 buckets and the bucket can hold a range from , say 100 to 150 only ...
0
votes
2answers
142 views

Meaning of using getters and setters and Uses of parameterized Constructor. [duplicate]

I am using getters and setters to for the purpose of encapsulation. public class Student { private String studentID; private String studentName; private String address; public ...
3
votes
1answer
125 views

What to do when properties of a HashMap and ArrrayList are neccessary?

I have a data structure that stores various permission groups for a multiplayer game server. There is an instance of a "Rank" class for each permission group. Each rank also has a name. I need to be ...
0
votes
0answers
73 views

Inclusive vs exclusive end for Java API for HTTP range requests

Java programmers typically expect the end index of a range to be excluded, as discussed in this question. For example string.substring(500, 1000) requests characters 500 through 999 inclusive of the ...
0
votes
0answers
91 views

WAR deployment on its own vs within EAR

Months back I started working on a project using 'jbpm' by Redhat. JBPM is a piece of open source software which maps business processes and allows for user input, in addition to other functions. To ...
0
votes
1answer
210 views

How to avoid LazyInitializationException using Hibernate and Jersey

I am working with Spring Boot + Jersey + JPA/Hibernate to build a RESTful API. The issue I am encountering right now is when I have a relationship in my JPA Entity that is lazy loaded I get a lazy ...
0
votes
1answer
70 views

Subclassing vs Using properties to discriminate types

Often when writing code I wonder what the best way is to discriminate between types (by which I don't necessarily mean types used in typesystems). That brings up 3 questions: What is better? When is ...
0
votes
0answers
79 views

If null is bad, what other approaches exist that could be implemented? [duplicate]

Null is considered bad, because of nullcheck. My question is, what other way there is, that would have replaced this null problem? How could that have been avoided?
2
votes
3answers
146 views

Single responsibility policy problem

I'm a bit stuck using the single responsibility policy. I have a class named Parser, which can be configured to parse input a certain way. For the sake of convenience I will limit the configuration ...
0
votes
1answer
128 views

Best way to separate public API from internal implementation [closed]

I'm developing a little framework (in Scala) where I want to define clean and simple interface for the users of the framework. Some of theses interfaces have to be implemented by the framework itself, ...
8
votes
2answers
249 views

How do I store multiple views of data in memory?

I have a bunch of modules. I can break these modules into different categories that are complete and do not overlap. For example, three categories, with ids that can be expressed as Animal, Vegetable, ...
5
votes
4answers
357 views

Design pattern for wrapping logging around execution

Introduction I am implementing a abstract Java class of a processing framework*. By implementing the function execute, I am able to add business logical functionality. I would like to add logging at ...
3
votes
1answer
151 views

If Java allows immutable classes, then why cannot it be used as a functional language [closed]

I have been struggling with functional programming concepts for a while. I read that in functional programming, variable immutability is a fundamental thing. You don't change the state of a variable. ...
2
votes
2answers
192 views

Justifying programmatically ensuring frontend and backend validations are synchronised

Like many Javascript-based rich web apps these days, I have some complicated validation rules implemented on the front-end. The same rules are supposedly repeated exactly on the Java backend but I ...
1
vote
1answer
55 views

Threads Inside Full Duplex Device Library

This is the second project I'm working on which will use a design that I'm not 100% confident about. I'd like some feedback, maybe recommendations for a better design, or verification that this would ...
5
votes
2answers
208 views

Exception clutter, how necessary is it? [duplicate]

Let's say I have a few methods that access the File System, and I want them to be a bit robust, I want to throw errors so the user can react: If the file doesn't have read / write rights, I want to ...
4
votes
3answers
234 views

What is the best design principle to add behavior in future to your API? [closed]

I'm designing an API. And, this API will be used by client. Currently I've two behaviors in a class definition. To illustrate the scenario, sample implementation looks like the following- public ...
-3
votes
1answer
59 views

How can we access non static protected method in main{as we cannot access protected members by creating objects} for java? [closed]

package foo; public class scj{ protected void disp() { System.out.println("package"); } } ********************* import foo.scj; public class aq extends scj{ public static void main(String ...
16
votes
5answers
598 views

How to make a datatype for something that represents either itself or two other things

Background Here's the actual problem I'm working on: I want a way to represent cards in the card game Magic: The Gathering. Most cards in the game are normal-looking cards, but some of them are ...
8
votes
6answers
1k views

Wrapping third party library is best practice [duplicate]

I came across with following statements while reading the Clean Code book of Robert C. Martin. Chapter : 7 : Error Handling Page No : 109 ..In fact, wrapping third-party APIs is a best ...
4
votes
1answer
268 views

Best practice for parameters in asynchronous APIs in Java

Is there a best practice for using Guava's ListenableFuture in parameters in API calls? Compare these two versions of an interface that internally does a compare-and-set (I'm using Guava's ...
0
votes
1answer
68 views

Non-synchronized method that calls synchronized methods only [closed]

Is it safe to make a non-synchronized method if it only calls synchronized methods? Say we have: public class SomeClass{ public synchronized void A(){ //Some code } public ...
3
votes
1answer
416 views

Why does `length - 2` recursively give you the center of a linked list?

I am reading through an Algorithms book and am working through a recursive solution to the following question: Implement a function to check if a linked list is a palindrome This is an easy ...
2
votes
1answer
190 views

Dependency ordering algorithm of a compiler

Let's say, hypothetically, I'm writing a Java compiler. And we assume that in my case a class can't be fully compiled until all signatures of dependencies (imports and other used classes) are known. ...
0
votes
1answer
222 views

What operating systems will “\n” create a new line in? (Java) [closed]

(Java Version 8 Update 60) Hello. I am currently writing a program for my first Java assignment in college. My question is, in what operating systems will System.out.println("Hello,\n World"); ...
1
vote
1answer
101 views

Prevent circular dependencies without introducing intermediary library

TL;DR Below I'm working on a game server (in Java, but that part is less important), and have decided to split up the server logic from the engine logic; in part because they're in two different ...
3
votes
2answers
251 views

How isolated are static variables?

If I have a public class SomeClass { public static final HashMap hashmap = new HashMap(); } and then I have five different classes with main(String[] args) methods, that I will run. when they ...
0
votes
3answers
220 views

Multi inheritance in Java

Let's say I've got a generic java class Filter<InputType, OutputType> which receives an input object and transforms it to an output object. Now I've got two other classes ...
4
votes
2answers
109 views

Should a Closeable throw an exception if used after being closed, even if it doesn't have to?

Let's say we have this interface: public interface OutputChannel extends Closeable { public void writeOutput(String output); } Then there are several classes which implement this interface and ...
0
votes
0answers
104 views

Gradle workflow with project dependencies

I'm wondering how people develop day-to-day with Gradle and how they manage in-house dependencies. Let's say we have a main project with the following in-house dependencies: proj depends on dep1 ...
2
votes
2answers
322 views

How is encapsulation broken by getters/setters, even when using MVC model [duplicate]

I was thinking about encapsulation in Java and then I thought how getters/setters break encapsulation. After I went through this , I saw many recommendations like to avoid getters/setters on fields ...
8
votes
3answers
725 views

Implementing a complexity hiding layer

As part of the dependencies that the project I'm working on has, we use several core services. These services, to which we can't make big changes, are a big mess. Depending on the method we invoke, we ...
2
votes
0answers
91 views

Creating a better mouse dragger function

I originally posted this to code review, not knowing incomplete code was off-topic and was pointed to post here. I don't believe this question is a good fit for stack overflow because the code I ...
0
votes
3answers
233 views

Forcing Cache Refresh

I'm updating an existing tomcat web application to read certain resources from a REST API. Currently the application reads them from flat files. Since the application is very critical, I added a ...
1
vote
1answer
129 views

Proper propagation / handling of exceptions

I am trying to learn trough example on a proper way to handle exceptions. When should I catch it, when and how should I throw it further down the line ? In this example I have a very simple setup: ...
2
votes
0answers
140 views

What is a “shaded” JVM client?

JVM developer here. Lately I've seen banter on IRC chat rooms and even in my own office about so-called "shaded" Java libs/clients. The context of the use will be something like: "Such and so ...
0
votes
0answers
44 views

OAuthv2 for the JVM

It looks like OAuthv2 identifies several different categories of actors: Client applications, desiring READ and/or WRITE access on remote resource servers Auth servers, used for ...
0
votes
0answers
37 views

How to use composition in Java [duplicate]

So I've been recently trying to use composition in Java having just learnt about it, but I can't quite get my head around what its doing differently to inheritance. So imagine this example. I'm ...
13
votes
3answers
1k views

Why should I use “functional operations” instead of a for loop?

for (Canvas canvas : list) { } NetBeans suggests me to use "functional operations": list.stream().forEach((canvas) -> { }); But why is this preferred? If anything, it is ...
0
votes
1answer
65 views

Under the hood of Java application servers resources

We are used to Node.js / Python / Insert X. Moving to a Java EE stack, it seems to me like all of the resources are 'press this button', 'do that' without any actual architectural explanation. For ...
3
votes
1answer
132 views

Design Patterns when Class Needs External Awareness

When I was first taught Object Oriented principles, it was drilled into me that when using objects in a "hasA" relationship (or any similar situations where a helper object encapsulates a discrete ...
0
votes
0answers
44 views

What are situations to use public variables instead of getter/setter methods? [duplicate]

I was reading a bit about Servlets and JavaBeans and encountered for example this example from http://stackoverflow.com/questions/1727603/places-where-javabeans-are-used: public class User implements ...
0
votes
1answer
83 views

Is this the correct way to think about the client/server socket relationship?

I'm designing a distributed application, very basic for now. The idea is that once the application is active on all machines (about 5 vms), you can initiate a grep on all log files from all machines ...
3
votes
2answers
935 views

Throwing an exception if some property is not present in a properties file

it's not a big programming problem, but I'm curious if it should be done better. So I have a config file which I'm reading via java.util.Properties class. When property is not present in a file ...
2
votes
1answer
1k views

Thread.State BLOCKED vs WAITING

What is difference between the BLOCKED and the WAITING states of a thread. As per JAVA code comments /** * Thread state for a thread blocked waiting for a monitor lock. * A thread in ...
0
votes
0answers
48 views

Spring pass-through authentication mechanism

I want to implement a "pass-through" authentication system using Java and Spring. I want to create a service that will be transferring all incoming http requests to a different host/port where ...