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.

Filter by
Sorted by
Tagged with
2
votes
1answer
78 views

Form validation code shared in the frontend and backend API?

I have a legacy Java monolithic web application. My goal is to use React on the frontend, keep Java on the backend and add an API for the frontend to use. My question is how can I write the data ...
0
votes
0answers
48 views

Distributing a Java application on macOS

I have developed a Java application for both Windows and MacOS. The application requires 2 separate jar files, 1 for the main application and then another is used to download and apply updates. This ...
0
votes
1answer
37 views

How to handle the getting of information from Model

I'm doing a Java software engineering team project in school and my team has decided on a Finance Tracker application, which contains the main components of Expense, Budget, Statistics, Suggestions ...
2
votes
1answer
62 views

best way to create @PUT upon multiple entities and compatible with RFC

I am trying to build the best PUT possible that allows modifying multiple entities upon single requests using java jersey. The idea is to send a request with multiple entity ids as @PathParam values ...
39
votes
8answers
3k views

Do access modifiers matter? [closed]

The theory is that access modifiers improve code safety because they support encapsulation of internal state. When doing OOP, every language I've used implements some kind of access restriction. I ...
2
votes
2answers
127 views

Is it clean to place method for comparing 2 objects of same class into that class?

Let's say I have class Car (just for illustration) class Car { ... boolean isRed(); ... } where to place methods which acts with objects of same class, in my example Car, but not just on ...
2
votes
2answers
135 views

Design pattern for static fields of a subclass

I'm creating a library, and I want there to be an abstract class called Optimizer. The user should be able to choose from a set of predefined Optimizers and if desired, use fluent methods to change ...
-5
votes
1answer
73 views

What do you think about DTOs in Spring Data JPA project?

First of all, I am not a junior programmer. I'm just looking for best-practice. How do you use entities and DTOs into your Spring Data JPA projects? Assume there is our layers: Repositories (as ...
-3
votes
1answer
78 views

How to make code runnable on open source code editors like Ace Editor?

For my computer science uni project I'm required to build a web application with an integrated code editor. I believe I can just integrate open source editors like Ace Editor. However, I feel ...
1
vote
1answer
133 views

Java - private static vs. public static

A wrapper class for storing primitive parameters which are initialized with values. Is it better to use public static or private static with bunch of getters and setters, for these constants? public ...
2
votes
1answer
94 views

Should I wrap a 3rd party library?

I'm developing an application that manages many different components, including various objects in a Kubernetes cluster. There's a nice Java library to manage K8S objects, I use it to examine objects ...
8
votes
3answers
458 views

Does it violate the Single Responsibility Principle if an object knows how to change itself?

I have worked with examples like a Player object which knows how to change its own state. Another example, is an Invoice object which knew how to calculate its invoice charges using an algorithm. ...
1
vote
5answers
280 views

When should i use an abstract class vs an interface? [duplicate]

I'm fairly new to programming. At school I am currently learning to program with Java. I want to build an application where i can store my collection of books, records, boardgames and such. Started ...
1
vote
3answers
230 views

Which option is best, when you have an attribute that is a list?

I have a class containing a list, for example: class User{ .... List<String> cards ... } What's the best way to provide access to this member? List<String> getCards() or ...
2
votes
1answer
154 views

Better practice of workaround for implementing a type field in Java

We have a class in our company's main library as follows: public class User { private long id; private UserType type; // Getters, setters, constructors, etc. } and have several options ...
1
vote
1answer
58 views

RMI vs APIs vs Akka Cluster

We have a Java Play Framework Application which we want to scale out into a cluster. The only issue is that there are services ran by the Akka Scheduler once per day, and we don't want these services ...
-3
votes
1answer
38 views

read text file with extended ascii from Google Cloud Storage (Java)

We have a text file with extended ascii (words like 'Systèmes' and 'Café'). It is in Google Cloud Storage. Its Content-Type is text/csv. If I download it via the browser UI (https://console.cloud....
3
votes
2answers
165 views

Is recommendable set as final as classes by default in a SDK?

I am working on the development of an SDK in Android with Java, In general the user doesn't need to inherit any class of the SDK, so the question is if it is a good practice put by default all classes ...
0
votes
0answers
51 views

Mapping properties to lambdas instead of using factory method/pattern

I'm receiving a JSON object which has many properties and the properties change (properties are added/removed) according to the type of the data in the JSON object. I'm expecting to receive many ...
4
votes
1answer
214 views

Delegate vs Forwarding in Java OOP

I'm reading some article about "prefer composition over inheritance", and heard about Forwarding and Delegation. After search for the different I found some source: https://en.wikipedia.org/wiki/...
2
votes
2answers
274 views

Why doesn't C++ support covariance in STL containers like C# or Java?

The Covariance and Contravariance feature is well supported in C# and Java collections. However C++ doesn't support them in their STL containers. Why is it so? For example the below code will ...
3
votes
2answers
166 views

When covariance becomes an issue, how can I restructure my code and still be clean?

Suppose I have the following interfaces, GameObject and Enhance. GameObject: public interface GameObject { void prepare(); void use(); void cleanup(); } Enhance: public interface ...
1
vote
4answers
237 views

Do we always need to override equals/hashcode when crreating a new class?

When creating a new class, should we always override the equals and hashCode even if we don’t intent at that point to use the class with any Collection classes? Or is it better to wait till such a ...
5
votes
3answers
873 views

Is it anti-pattern to have inheritence in a dto?

Are data transfer objects or POJOs meant to be final or can they be extended and create hierarchies for them? It is not clear to me if such a value class is properly designed only as a final class and ...
-1
votes
1answer
108 views

Making code more readable, iterating over inner map [closed]

So currently I looking for some hints from more experienced programmers. I am in the point where, when looking into my code it seems not readable, what is probably big flaw. So lets go to the code ...
2
votes
2answers
137 views

Field variable VS method variable

hey i have a difficult question. class DatabaseHelper { Database db; String defaultShema; public DatabaseHelper(Database db, String defaultSheme) { this.db = db; this....
40
votes
3answers
14k views

Why is the logical NOT operator in C-style languages “!” and not “~~”?

For binary operators we have both bitwise and logical operators: & bitwise AND | bitwise OR && logical AND || logical OR NOT (a unary operator) behaves differently though. There is ~ ...
1
vote
1answer
131 views

Java package naming conventions (in maven modular project)

Until now I have been using simple strategy for packages naming in my maven-modular projects. Each package name contains name of the module in which it is placed. For example, simple project would ...
0
votes
2answers
57 views

Design Java Testing class for hierarchical objects

Consider the following POJO structure in my main code. I want to create some testing framework for this kind of hierarchical classes, where the calling test method can specify if they want to modify a ...
0
votes
1answer
245 views

How to maintain and configure properties files for different environments in Java maven project?

A Java project with maven as build tool needs to be deployed to different environments, such as ci, dev, test, prod etc. Each environment has a properties file with the same set of properties such as: ...
1
vote
1answer
64 views

Modeling objects that behave in different ways so that they can be stored in a collection?

Suppose I have a Player class with an Inventory: public abstract class Player { private final List<GameObject> gameObjects; public Player(){ this.gameObjects = new ArrayList&...
2
votes
3answers
190 views

What is the proper logging level for tests?

I raised an issue at my employer concerning our gigantic heaps of testing logs. I raised the issue because I was spending well over a minute to find the relevant logs and stack-trace. I stated we ...
1
vote
1answer
57 views

Abstracting common functionality for REST and CLI

I have made an application that deals with collections of images. Currently it has a REST api to add/remove images, create/clear/delete collections and a worker that can automatically fetch images ...
-1
votes
1answer
24 views

User list and roles integration

I work for a brand new start-up who wants to roll out a product. One of the task for me is to integrate the existing user and role details of the client company and integrate it with our company ...
3
votes
3answers
112 views

Should new fields and operation of logical entity be in one single class even the existing class has thousands of existing lines

In a legacy Java project, when adding a new feature - an existing email field can be editable or not editable on base of its parent system, a developer added a new feature by adding a new class, which ...
50
votes
11answers
11k views

Why does C++ have 'undefined behaviour' (UB) and other languages like C# or Java don't?

This Stack Overflow post lists a fairly comprehensive list of situations where the C/C++ language specification declares as to be 'undefined behaviour'. However, I want to understand why other modern ...
0
votes
1answer
73 views

Turning complex XML (or content tree) into HTML - How to do it (in Java)?

I have a deep object content tree that I transform into a XML using JAXB and a small self written API on top. But now I want to create a static HTML site that has basically the same content (and ...
-2
votes
1answer
45 views

How to safe Consistency in DDD project in single aplication?

I want to design my project in DDD spirit. This is single aplication (not microservices) but with separate BC (as modules). Each BC have separate mongoDB collection. I have problem with communication ...
2
votes
5answers
200 views

Design pattern for objects in invalid states

General design pattern for object error state Consider a simple class Wallet that models a wallet. A Wallet contains a certain amount of Wallet.Cash and it is possible to take money out / put money ...
1
vote
1answer
109 views

declare 2 classes for nullable / not nullable objects?

Let's say I have an which is loosely can be represented as: public class AnObject{ public AnObject(String name, String value, UUID id) { this.name = Objects.requireNonNull(...
3
votes
3answers
264 views

Why are test frameworks like JUnit or TestNG not more “object-oriented”?

By "more object-oriented", I mean, it appears to me testing frameworks like TestNG and JUnit could encourage testers to write implementations of Test and TestSuite interfaces. The current approach ...
3
votes
0answers
89 views

Are session with cookie for authentication are dead? [closed]

I have an unpleasant discussion with a colleague who said using session in Java Web Application to validate authenticated users with cookies from Web browser after users logged in is problematic (...
0
votes
3answers
116 views

Can a thread acquire another sychronized block if it already has a lock of synchronized block

So my question is if my thread A has acquired access to a synchronized method S1() can it acquire access to another synchronized method S2() or a normal method.
0
votes
2answers
86 views

Correct place to store semi dynamic data

What I mean by semi dynamic data are data that are expected to be changed only with product versions. Now imagine this scenario, In version 1 of the product, I have item status : SUCCESS , FAIL In ...
1
vote
2answers
78 views

Creational design pattern that allows configuration of objects

With the factory pattern we abstract the creation of objects. But what if we need a specific configuration of an object that depends on the calling context? Example: So I have a Builder pattern for ...
2
votes
1answer
57 views

Design of dropdown lists to handle optional selection

Consider the following example in a CRUD application. A user can select their favourite food from a dropdown list ("Burgers", "Pies", "Chips"). This is an optional field i.e. not mandatory. Thus a ...
-2
votes
1answer
541 views

How to avoid code duplication in this situation?

Case: Several methods with same params validation inside, like: public Response method1(...params...) { if (someCondition) { //do some stuff with side effects ... ...
2
votes
4answers
216 views

Reduce number of digits by converting to alphanumeric data

We have an app that receives a web service request, processes it and sends it back to our client by another web service call. There is a unique field in the request, a tracking Id, which currently ...
1
vote
1answer
79 views

Is it good approach to create new viewModel class for every new Ui(Fragment/Activity)?

I am working on a project in which I am following clean Architecture from Google ... and for making code testable I am following an approach in which,I am creating a new ViewModel Class ViewModel ...
2
votes
2answers
217 views

How to gradually refactor a Map with string keys to use enum keys?

I'm considering refactoring some Java code that passes around objects that implement the interface Map<String, Object>. The strings are all (as far as I know) from some fixed list of string ...