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.

1
vote
0answers
47 views

Passing a list of base class objects to a method and using instanceof to filter them

I'm working on a Java reverse engineering project, where I am analyzing bytecode and trying to identify classes, methods and fields using the ASM framework. After identifying these I transform some ...
2
votes
4answers
112 views

Check if resource exists before inserting to the database or wait until the DAO throw the Exception?

I have two paths: /students /students/{id}/addresses ...with the following behavior: POST to /students - 201 Created (if successfully created the Student) POST to /students/{id}/addresses - 201 ...
-2
votes
0answers
18 views

Understanding the significance of JMS in this scenario

I've a springboot webapp. It's WAR is deployed on the RHEL server. Client side is HTML,CSS and JavaScript. I've been suggested to use Java Messaging Service in the following scenario and I am ...
-2
votes
1answer
15 views

Filtering the Data and summing on one field Should I do in JAVA or write query with aggregate query with filter clause?

I have one table in which there would be millions of records. The requirement is to the records based on the condition and then total on one of the fields. Selectivity would be around approx 50. ...
-1
votes
0answers
30 views

Failure handling and response code mapping in a (HTTP/REST) service architecture in Java

TLDR: I am looking for established standards to deal with translating error codes from a downstream remote call to an error code handed out upstream at a service interface, that allows to easily know ...
-2
votes
0answers
20 views

Why does Eclipse generate two javadocs for module-info? [on hold]

When creating a new module in a java project in Eclipse using Java SE 10, Eclipse autogenerates amodule-info.java file. Here's the format it provides: /** * */ /** * @author [my name] * */ ...
0
votes
1answer
45 views

Java convention - Implementing two similar functions for two different objects

I have two classes, let's call them Foo and Bar. They both extend different classes (Foo extends X, Bar extends Y), which have some common ancestor "way up" the inheritance tree, something like this: ...
1
vote
3answers
42 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
37 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
46 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
210 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; } ...
1
vote
0answers
69 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
77 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
123 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
97 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
38 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
2
votes
2answers
151 views

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

I am new to TDD/unit testing. I am going to write a complex scheduling algorithm in Java. As this module is a 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
79 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
85 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
135 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(); ...
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
70 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
38 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
172 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 ...
1
vote
1answer
112 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
197 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
179 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
108 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
193 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(); ...
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
214 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
115 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
123 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
9answers
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
145 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,...