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
1answer
13 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 ...
5
votes
4answers
204 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 ...
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
50 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
62 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
51 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 ...
2
votes
2answers
59 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, ...
-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
49 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
48 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
114 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, ...
1
vote
0answers
113 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 ...
-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
67 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
57 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
37 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
21 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
91 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
40 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
50 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
30 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
4k 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
37 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
50 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
88 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
126 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
60 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
80 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
86 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
48k 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
61 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
124 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 ...
3
votes
1answer
155 views

Forward Slash vs Back Slash vs File.separator in Java

I've seen some programmers doing the following : File file = new File("folder\\subfolder\\subsubfolder"); And I find it totally wrong because of compatibility issues with a different OS than ...
0
votes
1answer
62 views

Controller calling multiple services

I have a few layers in my WebApplication: Presentation, Service, DAO, Domain. Services call DAO objects which reads data from a Database/File whatever. I have a Controller that needs to fetch data ...
2
votes
2answers
161 views

What is a good approach to get a detailed system design from an existing system?

I will be working on a system which will be ported over from Java to .Net. It is a pretty big system. I don't have any specifics about how the system is designed, no documentation, nothing. You know ...
1
vote
0answers
31 views

Why Does JavaFX's GridPane Attach Properties of the Layout to the Components?

I am currently learning JavaFX and I came across a very strange API for laying out GUI components. It is perhaps best explained by it's javadoc: To use the GridPane, an application needs to set ...
17
votes
6answers
11k views

Should a string constant be defined if it's only going to be used once?

We're implementing an adapter for Jaxen (an XPath library for Java) that allows us to use XPath to access the data model of our application. This is done by implementing classes which map strings ...
1
vote
1answer
67 views

Designing validation classes

This is a follow-up of this question. I decided to implement what the accepted answer suggests, however, I realized I also needed individual public methods for each member the entity to be validated ...
1
vote
4answers
196 views

Readability & Performance: Is it better to allow the Java garbage collector to clear a datastructure?

I work with large HashMap's and ArrayLists. When not needing them to be in memory any longer, I use myArray.clear(); to free up the memory. When my colleague saw that line, he changed it to myArray ...
3
votes
4answers
154 views

How to name an exception where condition is not exceptional

NOTE: This question is about finding a proper name for an exception where the condition for throwing the exception has not actually happened (eg. preventing a StackOverflow by throwing a ...
9
votes
3answers
245 views

OOP design problem. Two kinds of empty Optional

I'm writing a quite simple application that deals with hotel rooms reservation. I've got a problem at one stage. I'm processing a queue of orders. For every order one of the receptionists should ...