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
3answers
220 views

Why would a type be coupled with its builder?

I've recently deleted a java answer of mine on Code Review, that started like this: private Person(PersonBuilder builder) { Stop. Red flag. A PersonBuilder would build a Person; it knows about ...
11
votes
5answers
2k views

When should I extend a Java core class

My current understanding of Inheritance implementation is that one should only extend a class if an IS-A relation is present. If the parent class can further have more specific child types with ...
-4
votes
2answers
37 views

Cache repository violating the SRP

interface IRepository { Data getData(); } class BaseRepository implements IRepository { public Data getData() { ... } } class CacheRepository implements IRepository { private final ...
0
votes
0answers
46 views

Algorithm to fit all items in a bag choosing most optimal cost?

Is there any algorithm to do this? I have objects that have attributes, maybe some weight, type, etc. I need to place the best configurations possibles where all my objects no matter the type fit, ...
-4
votes
0answers
83 views

Why is JSF very complicated?

I'm just trying to create a simple web application that can retrieve information from a database and display them, but to populate a drop down list with complex objects is just a full-time job itself. ...
2
votes
1answer
590 views

Emulation of MMU accessing the contents of the registers

I'm having a play around with emulating a simple old CPU. I've set the structure up, so far anyway, as follows: The device is the main and creates an instance of the CPU. The CPU then creates ...
-1
votes
2answers
72 views

How to mount a virtual drive?

I wondered if it is possible to mount a virtual drive (file) with Java. I saw that before in Truecrypt. So is it possible with Java? And how can I achieve that?
7
votes
5answers
339 views

Inheritance vs additional property with null value

For classes with optional fields, is it better to use inheritance or a nullable property? Consider this example: class Book { private String name; } class BookWithColor extends Book { private ...
2
votes
2answers
79 views

Java EE exceptions for validation and APMs

In my current work, we have some Java EE applications and we use exceptions and exception mappers to deal with user errors, i.e. that can't be dealt with in the frontend. We usually reply with a 400, ...
1
vote
1answer
163 views
+50

Logging RestTemplate's responses

I want to log responses using Spring's RestTemplate. At first I thought I should do it using a ClientHttpRequestInterceptor, but since every set of requests should be logged to a different file, I ...
1
vote
1answer
53 views

Better way to organize query methods in Android?

In my Android app I have a SQLiteHelper class that extends SQLIteOpenHelper, and takes care of things like table-creation and upgrades. SQLiteDatasource class that performs CRUD operations on the ...
-3
votes
0answers
40 views

Java Certification exam materials and objectives [on hold]

Iam preparing for java certification exam using this tutorial site http://www.javaprepare.com/java-questions/ please suggest me some books regarding java certification..
0
votes
1answer
52 views

What is the proper or recommended way to save String[]'s, Array's, ArrayList's and int[]'s to Android?

I've looked up this question many many times but keep seeing different answers, what is the BEST way to save array's? It seems ludicrously infantile that there is no standard or easy way to save ...
10
votes
10answers
1k views

Any tools/suggestions on how to refute code coverage quality argument

Now I know people could consider this question duplicate or asked many times, in which case I would appreciate a link to relevant questions with answer to my question. I have been recently in ...
-7
votes
0answers
62 views

how the command line arguments are efficient? and why we compile java program in cmd? [on hold]

how the command line arguments/operations are faster than GUI, and why we need to compile and run the java program on command prompt, how it is going to be effective/faster? why not compile like c/c++ ...
1
vote
0answers
69 views

Sharing POJO between different handlers

I am trying to automate Business Process which can be characterized as a pipeline with distinct stages. Pipeline can be perceived as A->B->C, where A,B,C are distinct Business Steps that ...
3
votes
1answer
54 views

Is there use case for implementing a callback if a future is returned?

If I have function which returns a future, is there any reason to also include a callback where the callback is simply called right before the future completes? The only advantage I can think of ...
-3
votes
0answers
9 views

need to find the index at p percent of the array length, and return all the values before that index point [migrated]

given an int[] x and a perentage p (0 - 100), find the smallest valued element y of x so that at least percentage p elements of x are less than or equal to y. I have code that sorts the array ...
2
votes
1answer
234 views

Working with a large, messy object [duplicate]

I have been handed a very cluttered, "One Ring" object (one object to rule them all). The OR class has 40 fields. These fields map to 16 different objects (the OR has all the fields from the 16 ...
-6
votes
0answers
59 views

Help me in this java programs [on hold]

Write a program: Must start if user says hello Has to repeat until the user says bye Ask user to enter his or her name, let him or her know if the entered name contains space or dot. Each time print ...
0
votes
1answer
50 views

Taskrunner - with multi threading design [on hold]

I am looking for advice on how to implement a multi threaded task runner. My background is Java and Spring. It would look like the following. BatchTask Each BatchTask shall run in parallel and ...
-2
votes
1answer
126 views

Shouldn't Java method parameters always be final [on hold]

Say I have a method that writes a string to a file: public void write(String content, File out) { // writes content to out } If I want to protect the parameters and ensure that they are not ...
1
vote
1answer
258 views

How should one model an ExchangeService object (in ews-java-api) for sharing MS Exchange connections?

I am creating an application which uses ews-java-api to connect to an MS Exchange server. Once the connection is authenticated, the api dictates use of ExchangeService object for searching mailboxes, ...
-5
votes
1answer
54 views

Proper use of break; [closed]

I am trying to establish my POINT value when the sum is equal to 4, 5, 6, 8, 9, 10, but terminal continues to execute my code even after the break;. Can someone please explain why this is happening? ...
0
votes
2answers
71 views

Creating a Vector (physics) Class in Java

I'm trying to create a vector (like in physics) class in Java. I want to support vector addition, dot product, scalar multiplication, etc. So, my question is, is it possible to do this with generics? ...
75
votes
6answers
12k views

Why are floats still part of the Java language when doubles are mostly recommended instead?

In every place I've looked, it says that double is superior to float in almost every way. float has been made obsolete by double in Java, so why is it still used? I program a lot with Libgdx, and ...
2
votes
2answers
59 views

How can I find out network latency in rest service

I have two Java applications deployed on tomcat. For inter application communication I provide jar file of application (Java API) to other application and it becomes a method call which is fast. Now ...
1
vote
1answer
39 views

How to use fields from an object after an exception is thrown and the object can't be fully created

The issue that I have is that I need information from an object that a method returns when it throws an exception. It is a little hard to describe so I have this java pseudo code example. I have a ...
-4
votes
0answers
24 views

Registration servlet issue (BLOB and DAO) in mysql [on hold]

I was trying to implement a registration page where I had profile image as a blob in the form. I tried to use a DAO to insert the form inputs to a mysql table 'users'. However this is not inserting ...
4
votes
1answer
93 views

What is the point of calculating these variables this way?

I'm skimming through a very popular game's source code at the moment and I came across these variables inside of this class. public static final BlockPos ORIGIN = new BlockPos(0, 0, 0); private ...
0
votes
1answer
43 views

What kind of data structure should be used to store components in an electrical schematic program?

Is there a specific data structure, object oriented programming methodology, and/or approach for achieving what programs like LT Spice, Altium Designer, and Cadence Virtuoso use to manage ...
-2
votes
0answers
25 views

How would I implement the following formula as a function in java? [on hold]

Where you are trying to find the smallest number for n with inputs p and y. I tried to implement this as: int index = 0; for (int i = 0; index == 0; i++) { if (bFormula(i, perHit, hitsNeeded) ...
2
votes
1answer
51 views

Observer Design Pattern with complicated objects

I am trying to currently get a good grasp on the Observer design pattern, but I am stuck wondering about one specific issue. In the examples I have been able to find of implementation, they are all ...
3
votes
4answers
12k views

When to use functions vs methods?

So I know that methods are more OOP than functions. I was wondering if someone could show me an example of a function and a method and explain the differences between methods and functions to me? ...
-1
votes
0answers
31 views

How to extract edges using the standard deviation

I am currently creating a Content Based Image Retrieval system in Java. My algorithm currently computes the standard deviation (Based on RGB values). I am trying to build on that algorithm and make ...
25
votes
3answers
5k views

If I implement an Interface, is it called an Inheritance?

If my class implements an interface then can I say that I'm following inheritance? I know that when a class extends another class then it's inheritance.
0
votes
1answer
38 views

UML- Aggregation or Association

Below is the problem for which I have created a UML diagram with Staff as superclass and waiter, manager and hosts as subclasses, I understood other parts, except for the relation between table and ...
1
vote
2answers
51 views

Set data in multi-level objects (may be using Java Reflection)

I want to possibly use Java Reflection to set some data at RunTime. My problem is I can't figure out how do I get sub-classes information and use as a part of reflection. I want to use Reflection to ...
-1
votes
2answers
89 views

How to validate Exception messages? [on hold]

My superior asked me to validate each and every input field in the project that includes the Exception messages. So, am I correct in using Exceptional Handler for validating Exception message. ...
1
vote
2answers
129 views

Expressing interface inheritance in natural language [duplicate]

In object-oriented programming, when you extend a class you establish an is-a relationship between a new subtype and its parent(s), i.e. B is an A (aka code inheritance). When you compose a class with ...
0
votes
1answer
62 views

NoSQL in Java Enterprise Application

I'm planning a large scale enterprise application that requires reliability and standardization comfort that Java EE provides. At the same time, I'm wondering if I go for Java EE, will I be able to ...
0
votes
1answer
83 views

Are new empty Java marker interfaces created to satisfy an existing method contract a code smell?

Suppose I have a POJO A and some client code that serves it. I have created POJO B, which doesn't have anything in common with A, but I want to use it in the methods that use A, so I decided to create ...
2
votes
3answers
89 views

Logging an audit trail (Java application)

I'm creating a Java (Spring Boot) application for creating Entities. I've got my @Controller for getting the data from a web front end, I've got my @Service for processing the data, and I've got my ...
169
votes
13answers
49k views

Should we avoid object creation in Java?

I was told by a colleague that in Java object creation is the most expensive operation you could perform. So I can only conclude to create as few objects as possible. This seems somewhat to defeat ...
1
vote
1answer
226 views

Is it OK to do IO inside java 8 streams?

Example to question in title: List<UUID> ids = dao1.getContactsOfUser(userId); List<String> contact_names = ids.stream .map(uid -> dao2.getContactByUid(uid)) //is it ok? ...
2
votes
1answer
141 views

Checking preconditions the proper way

I have a class with around 1300 lines and it has many CRUD-like methods that need parameters to be checked, for some of them it's more than just a few rules. For clarity purposes, I am going to use ...
20
votes
8answers
5k views

What Style is Better (Instance Variable vs. Return Value) in Java

I often find myself struggling to decide which of these two ways to use when I require to use common data across some methods in my classes. What would be a better choice? In this option, I can ...
0
votes
1answer
62 views

Why is a Spring's HttpClientErrorException an unchecked exception?

Oracle summarises the purpose of unchecked exceptions as: The next question might be: "If it's so good to document a method's API, including the exceptions it can throw, why not specify runtime ...
1
vote
0answers
16 views

How do I properly manage EntityManagerFactory and EntityManagers for long running tasks?

We're building a JavaFX application that connects to a remote Oracle database using EclipseLink on one end and a SOAP service on the other end. We're writing long running transactions that will pull ...
5
votes
2answers
125 views

Composable concurrency in Java or any other programming language

While I was reading a research paper on concurrency named Software and the Concurrency Revolution (html version). I came across following lines: Unfortunately, although locks work, they pose ...