Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [java]

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.

0
votes
0answers
9 views

Proper Connection Pool Use

I'm confused as to how to properly interact with my Postgres database throughout the typical user experience on my web app. I'm seeking clarification on the most efficient method of communicating with ...
1
vote
0answers
24 views

Functionality design: Multiple sources, multiple consumers with configuration

It is a Design Problem which I am listing out here. I have multiple event sources in my app, each one produces events with the different set of data (but each source is producing only one type of ...
-1
votes
0answers
40 views

Token-based registration

I'm trying to create a system where only users with a valid token can register. You may think of the token as a String which allows the user to register in my system. The token should cover: Status: ...
6
votes
1answer
120 views

Is it a good practice to create new variable to see the output of a function?

Consider these 2 types of implementation: public int add(int x, int y) { return mysteriousAdd(x, y); } public int add(int x, int y) { int output = mysteriousAdd(x, y); return output; } ...
-2
votes
0answers
39 views

NullPointerException using the ternary operator with null values [SOLVED] [on hold]

I'm having issues using the ternary operator with null issues. Here are some simplified exemples : Double d1; Double d2 = null; boolean condition = true; if (condition) { // Is fine d1 = d2; } ...
1
vote
0answers
63 views

Does it make sense to implement a Class Factory design in an RPG Character Creation module

I'm a self-taught Engineer, a beginner in Java and I am trying to create a Dungeons and Dragons character creation module for a bigger game to solidify my understanding of core concepts while learning ...
2
votes
3answers
73 views

Is a setter with the composed object as a parameter better or separate setters for each parameter within the composed object?

I have two ideas on how to proceed with an availability class but I'm not sure which one is better. public class TimeRange { private Timestamp startTime; private Timestamp endTime; public TimeRange()...
0
votes
1answer
119 views

Is Java-like restrictiveness OK Python style?

Good Pythonic style is much looser than Java's uptight restrictiveness: In Java, good style means private on methods wherever possible, all fields encapsulated, type declarations, defined ...
-2
votes
1answer
96 views

How to organize the build system of a project as it starts including multiple languages across multiple operating systems and compilers?

I wrote a Music Player and Library in Java for GNU/Linux and Windows. My build process is currently in ANT, but I intend to migrate away from that to something more modern after the next release. I'...
-4
votes
1answer
37 views

LL(K) grammer generation for postfix expressions [closed]

I have a problem in formulating LL(K) grammar for this postfix expression problem, given (4 3 / 2 * 4 5 / +) as an input must output 52/12
1
vote
2answers
125 views

What is recommanded way to create test data for unit test cases?

I am new to TDD/unit testing. I am going to write one complex scheduling algorithm in Java. As this module is core part of our application and there are number of scenarios in it, I want to write ...
1
vote
1answer
70 views

Improvements in a “data - manager - wrapper” architecture

I have programmed using the architecture below, where "client, order, piece" are just data classes, have no methods, and "managers" are the manipulators of that data, the "ClothingStore" is a wrapper ...
-3
votes
2answers
78 views

How to have zero or one of and object in a class? [closed]

I want a class A, and I want the relation that A can have zero or one X. So I wrote this class: public class A { private X x = null; public A() {} public A(X x) { this.x = x; } ...
2
votes
2answers
83 views

A good way to represent an object with multiple interconnected states?

I want to program a simple budget application. In my application, the budget is divided into budget periods (months by default, but it can be bi-weekly or weekly periods). In each period there is a ...
1
vote
1answer
82 views

Best Way to Store List as Constant

Let's say I want to parse some JSON and I store the path in a Java constants class the path that I want to follow. For example: public static final List<String> path = Arrays.asList("a", "b",...
2
votes
1answer
133 views

Is it efficient and a normal practice to have one class with thousands of lines of code? [duplicate]

I am currently in a continuous software product development project on base of legacy Java code. The source code is very complicated, which is good and bad. But I am surprised to see that in the core ...
-1
votes
1answer
55 views

Synchronization method vs private final object for locking in java

Can anyone tell me which one is better approach between synchronization method and private final object in java and why ?? public class kclass { private final Object myObject = new Object(); ...
-2
votes
0answers
45 views

Java library to flatten all properties of a class hierarchy [closed]

For an internal project, I need to write a library to extract all fields or JavaBean properties (still to be decided) of a graph of objects. Fields/properties will be either "scalar" types that I'll ...
0
votes
0answers
41 views

Approach to work with large XML - Oracle - Java - File

We have got a client that wants a large amount of data in XML format. The Xml is roughly like so : Employee |- Emp Criminal History |- Emp Address |- Address history |- Emp Partner |- ...
38
votes
8answers
6k views

How long to wait before deleting a deprecated method? [closed]

I am maintaining a public API and have to deprecate a method. Is there a general rule on how many months/years/versions before the deletion I should deprecate a method?
1
vote
1answer
69 views

Using generics on interfaces when implementation is not generic

Is it acceptable practice to put generics on an interface when the implementation will not be generic? Lets say that my project will have many classes that read data from the database. I may make a ...
-2
votes
1answer
50 views

Understanding property based testing

I'm reading about property based testing and I'm wondering how can I test this my code using that paradigm. class Invoice { private final String id; private final String companyName; ...
2
votes
0answers
43 views

java hashtable extending to support duplicates

I have to maintain an old application and have to extend some modules. There is an hashtable that is used for maintaining/holding some objects as representation of running (real) processes (don't see ...
0
votes
1answer
37 views

Reuse JSE checked exceptions as unchecked

Actually what i'm doing in my code base is duplicating already existing java checked exceptions like MalformedURLException.class by keeping the same exception name while inheriting from ...
2
votes
1answer
171 views

Is it a good idea to have type safe equals

To me, equals() between objects of inconvertible types is one of the most useful IntelliJ inspection. It's almost never intended to have objects with different types equal to each other. I ...
-3
votes
0answers
33 views

Linked List update priority

So i have created a linkedlist from scratch which inserts and sorts via priority. The last method i need to add is an update priority method. I have a findNodeByID method which finds a node based on ...
1
vote
1answer
103 views

Where and how to connect to external API in my service class?

In my service class I would like to connect to external API. Where and how should I do it? 1) Inject in constructor ExternalClass and assign to private property. Next in other property in constructor ...
4
votes
1answer
187 views

Wrapping utility classes and injecting them for unit testing purposes

I found that it is so hard to test classes that depend on other utility classes as java.nio.file.Files. It is also impossible to mock them using the classic unit testing stack (junit,mockito,..) ...
3
votes
3answers
170 views

Are there any drawbacks to using a nested class instead of declaring a new one?

I'm doing code review on a change my co-worker made to our Java application, and I've found something I'm not very familiar with - a nested class. From reviewing the code, it seems like the nested ...
3
votes
1answer
107 views

Java inheritance error handling scenario

I looked multiple places for some advice on how to solve this before asking this question, but I couldn't find something similar to this. So I have the following scenario in Java Spring Integration ...
2
votes
4answers
192 views

Creating new constructors to overwrite the existing instance variables for testing purpose

Is it good/bad practice to add more constructors just for test purposes (to mock the DOCs used in my SUT) like this : public class A { private B b = new B(); private C c = new C(); ...
-2
votes
0answers
42 views

Java.com is completely oblivious to Java 9+

The website java.com publicly holds Oracle's logo. I presume it is a trustworthy site. Why doesn't it then mention any newer version that Java 8? Actually, they act as if there are only two versions, ...
0
votes
1answer
30 views

Should I postfix application.yml?

My project structure (Spring / maven): src / main / resources / application.yml src / test / resources / application.yml This is working well (when I launch test, it takes the test application.yml). ...
1
vote
0answers
21 views

Periodically update files from s3 in a Java maven library used as Packaged JAR

I have an application say x which uses another Java library(say Y) as a JAR file . So y basically needs to download a file and load it into memory before any of it's methods are called at runtime by X....
0
votes
2answers
213 views

OOP design problem with Java

I have part of the system that looks like this: Basically, the client decides which API call to invoke on the server based on the flag that is previously provided. It knows in advance which type of ...
0
votes
2answers
113 views

Is it beneficial to throw a caught IOException as an UncheckedIOException in order to prevent NullPointerException?

Not using UncheckedIOException, NullPointerException possible public void callerMethod() { Object result = ioMethod(); // call instance method of result } public Object ioMethod() { ...
-1
votes
1answer
99 views

What options are for a GUI for a Java application? [closed]

This might be a bit of a wide question. I have a couple of classes in Java that take input a String which is a mathematical expression and evaluates it. I want to implement a desktop GUI for this. ...
-1
votes
2answers
122 views

Dealing with data download which could take days to download

I have a situation on the front end where a user clicks on “Download” button and the query behind the scenes is going to take over a day. I have a Spring boot web app running as far as web services ...
-1
votes
3answers
79 views

Multiple classes working on an object

This might be a bit of a wide question but I want to understand if it's the correct way to do it. Assume I have a couple of classes all doing operations on an object. First class takes the object, ...
0
votes
3answers
142 views

Java, pattern to restrict field usage in subclasses to after calling specific method

I want to extend class Base which is defined in specific API and the extend the extended again. As you can see below, draw method of intermediate class calculates variable top and I need to use it in ...
1
vote
1answer
145 views

Can (Java) Interfaces be referred to as APIs? [duplicate]

I am trying to understand what exactly an API is. From my current understanding, an API (Application Programming Interface) is a contract provided by a software instance, that guarantees a defined ...
0
votes
1answer
24 views

Optimising network data usage in vehicle tracker

I'm currently working on an Android application that broadcasts the location of the device every 5 seconds. Pseudo showing current app process: deviceLocation = getLocation() if (hasChanged(...
28
votes
10answers
6k views

Why do we need a Builder class when implementing a Builder pattern?

I have seen many implementations of the Builder pattern (mainly in Java). All of them have an entity class (let's say a Person class), and a builder class PersonBuilder. The builder "stacks" a variety ...
0
votes
2answers
231 views

Language of an interpreter

I am trying to make my own programming language by making an interpreter for it in Java, but lately people have been telling me that an interpreter needs to be in the same language as the one it is ...
0
votes
1answer
41 views

Some Questions on PHP execution?

I am new to PHP . I have primarily worked on java. I want to run the helloworld program for PHP. I got it how to do it through blog But I have got some basic questions :- Do I need to install both ...
-1
votes
1answer
95 views

Is there a difference between older versions of the JDK and newer versions that might make learning an older version bad? [closed]

Are there significant differences between, say, JDK 7 and JDK 11 (which latter I believe is the newest version of the JDK), where significance is defined by a change which might make someone who has ...
1
vote
0answers
144 views

How to simplify design and remove duplication in java layered architecture?

I've the following project structure (simplified): domain dto view In domain model is kept. dto classes are used to pass data from domain to view. And in view I've a controller and a handful of *req,...
0
votes
2answers
60 views

Preferred method signature for API method involving DB interactions

I recently got into discussion about how the method signature should look like for an API method which doesn't expose internal objects used by application to caller. Here is how situation looks: Our ...
0
votes
1answer
103 views

Java Design Pattern to Use for switching between 2 different endpoints

I have a legacy service that is running on-prem and have built a new service that runs on cloud which provides the same functionality. I have another java (spring) service which consumes the on-prem ...
2
votes
0answers
106 views

Division by zero Java [closed]

The behavior of Java is explained in this topic. But, is Infinity useful for something? Float: public class DivisionByZeroFloat{ public static void main(String[] args) { System.out....