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
16 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? ...
71
votes
6answers
11k 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 ...
1
vote
2answers
27 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
17 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 ...
-3
votes
1answer
20 views

The following random generator returns null value any solutions please… [on hold]

public static void main(String[] args) { Random r = new Random(); String temp=null; String SecKey; int i = r.nextInt(999); if(i<100) { ...
-2
votes
0answers
11 views

Registration servlet issue (BLOB and DAO) in mysql

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 ...
-1
votes
0answers
17 views

Taskrunner - with multi threading design

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 ...
-4
votes
0answers
19 views

can u write this java programming question on 2 D array? [on hold]

Design a 2D array that helps keep a track of BUS RESERVATION SYSTEM. A user is requested to input a SEAT NUMBER (row & column) for booking a seat. If the seat is available, it prints a ...
3
votes
2answers
50 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 ...
-2
votes
1answer
9 views

java.lang.NoSuchMethodError: org.hibernate.Session.close()V

Background: I'm working on a RESTful API in NetBeans with Jersey, MySQL, and Hibernate. I downloaded the most recent stable version of Hibernate (5.1.0), and added all the jars in the required folder ...
0
votes
1answer
34 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 ...
-1
votes
0answers
18 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) ...
1
vote
1answer
40 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
27 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 ...
-3
votes
0answers
29 views

cannot find web-inf folder in netbeans when creating a new maven web application [on hold]

I am not able to see the WEB-INF folder under web-pages when i create any new maven based j2ee web application. Please let me know why this is happning and how I may fix this. see screenshot ...
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.
1
vote
0answers
87 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 ...
0
votes
1answer
36 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
49 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
86 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
125 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
58 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
73 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
84 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
136 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
60 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 ...
0
votes
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
146 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
58 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
29 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
66 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
195 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 ...
2
votes
4answers
150 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
237 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 ...
2
votes
2answers
71 views

Is it possible to capture java objects to save them as test resources?

I'm wanting to write unit tests to check that for given database responses, certain objects are create/things are done. The problem I have, is that when mocking the database response, I have to ...
1
vote
1answer
319 views

JEE MVC, controller calls the interface instead of the interface implementation

I'm following this tutorial: http://wiki4.caucho.com/Building_a_simple_listing_in_JSP It creates a basic web application in Eclipse using the MVC pattern with Resin as the web container. Here's the ...
3
votes
0answers
75 views

Finger Paint path gets huge over time and slows the app

So I am writing a Finger paint app. I have multiple color which user can select. I save the path and paint information inside an array. ArrayList<PaintPath> arrayPaintPath = new ...
-3
votes
0answers
68 views

Javafx show a views with different numbers of columns and rows, with the same class and method [closed]

I can use Javafx with or CSS or both, no problem. I work in Eclipse. But I want show in an AnchorPane or something else a SQL view, what is not fix. I could have 20 or 30 colums, with different names. ...
1
vote
2answers
157 views

Should i implement same interface in derived class?

Is there a difference between public class B implements C public class A extends B implements C and public class B implements C public class A extends B Is it just redundant implementation? ...
8
votes
2answers
160 views

How to resolve LSP violation based on minimum precondition

I have a class Party that has a constructor that takes a Collection<Foo>. I plan to have two subclasses NpcParty and PlayerParty. All Party instances have an upper limit on the size of the input ...
-4
votes
0answers
45 views

How to continue with script even if NoSuchElement exception is thrown?

Below By.id("ww") is a wrong locator. I want the code to throw NoSuchElementException for 'ww' but the script should continue and print 'fff' in 'lst-ib'. My execution is getting stopped at 'ww' only. ...
-3
votes
0answers
54 views

Client/Server RMI modeling blackjack Java game [closed]

At this time, I have build a BlackJack Java games runnable through the Java console. But my problem is that I have to developed an Client/Server RMI interface, and I don't know how I have to modelize ...
1
vote
1answer
46 views

Redesigning a builder to make it reusable

Let's say I have a builder class (which by the way is not techinically a builder, but it's not a factory either) to generate different rules for a game: public class RuleBuilder { private Game ...