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
4answers
518 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
167 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
270 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
2k 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
109 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
223 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....
42
votes
3answers
15k 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
605 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
82 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
2answers
1k 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
66 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
289 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
65 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
26 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 ...
52
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
80 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
48 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 ...
3
votes
5answers
256 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
114 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
271 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
95 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
126 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
105 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
84 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
61 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
564 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
245 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 ...
2
votes
1answer
87 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
280 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 ...
1
vote
1answer
75 views

Avoiding “instanceof” and explicit casts when selecting applicable handlers for inheriting object

In my current project, I am trying to implement an environment to perform simulations of different workflows in a range of programs, websites, and mobile applications. These simulation subjects can ...
3
votes
2answers
278 views

What is the best way for transferring large datasets between an old java app and a python app on the network?

I am working on a machine learning project at the moment which requires me to transfer the data from an old Java app(which is also the custodian of the data in current paradigm) to a python service ...
0
votes
1answer
391 views

Do shared ViewModels contradict MVVM?

I want to follow the MVVM app architecture. I also need to have some communication between some fragments. But the official approach is pretty confusing. Taken from the docs (https://developer....
1
vote
1answer
122 views

One API used by multiple clients with small variation in the flow

I am working on refactoring codebase for a JAVA API thats used by multiple clients. Though the api provides the same overall functionality for all clients, actual flow changes a little bit between ...
0
votes
0answers
81 views

How to pass data from Java to display in SSRS?

I have a Java application that uses an 3rd party Java library to get data remotely. Specifically, a start date, end date and a few other search parameters can be passed to a library call and it will ...
7
votes
3answers
464 views

Avoiding side effects in immutable class constructor

I rewrote a very long method in which some data is queried from a database, based on info about a particular account, which is queried first. I split out the account info into an immutable inner ...
1
vote
2answers
187 views

Declaring an object that extends a class and implements more than one interface

I'm confused about how should I declare an object that implements more than one interface, or derives from a class that implements one interface, and implements another interface itself. Let's ...
1
vote
2answers
123 views

Chain of responsibility or simple dependency injection for Querying API

I am working on refactoring a project code that is wired up in a tangled way. It was started with decent dependency injection and over time with all custom requirements it looks it got tangled up. ...
2
votes
0answers
57 views

Send push notifications from ActiveMQ

I am trying to figure out how to send push notifications back to the client in the following ActiveMQ scenario: I have a spring boot web application #1 deployed on tomcat on RHEL server. From the ...
1
vote
2answers
98 views

How to manage item locations in an inventory

I have to manage item locations and life cycle as a new requirement. I'm not familiar in warehousing/inventory/storage systems, so maybe my question is trivial. The task: We have original items that ...
0
votes
1answer
216 views

How to check if user is logged in after logging using http post?

I'm developing a Scrap app to extract some information from a sit. To get that information I have to be logged in to that site. So I use Http post and pass the data needed for login using FormData ...
1
vote
7answers
314 views

Dealing with large code base quickly in agile

At my current company, the project I work on is coded in Java, at least for the systems / backend part. Whenever I get assigned a task dealing with the Java code, it take me hours or even days to ...
6
votes
3answers
1k views

Write a method with same logic but deals with different objects

Assume I have the following method that does the same logic but deals with different objects (It's more a pseudocode): private <E> List<E> updateOrInsert(List<E> list) { if ...
0
votes
1answer
115 views

Handling Currency getInstance throwing IllegalArgumentException

I have a class with a (simplified) method which returns a string like this : private String doStuff(String currencyCode, BigDecimal amount){ StringBuilder sb= new StringBuilder(); ...
1
vote
2answers
137 views

Microservice Decomposition and Inter-service communication

I read theory but I need practical architectural advice on the actual implementation in java language for microservices. In the context of the attached screenshot. Here is my setup. Order Project ...
0
votes
0answers
30 views

Sequence Diagram Assistance with external database

I have 5 Java/android classes which are in sequential order. The user inputs data into the text box and clicks next. Two things happen, 1 the data the user inputs is passed to the next activity and it ...
-2
votes
2answers
40 views

How to handle mapping of generated classes with identical fields? [closed]

We have a large number of classes that is generated by JAXB. There are a couple that have identical fields and I want to see if there is a clean way to map class A to class B. Example: public ...
0
votes
1answer
115 views

How far to go with semantic versioning?

Say you have an interface with a function List<A> doSomething(Collection<B> bs). Looking at Java's List interface and its JavaDoc I could return an immutable List which doesn't support ...
1
vote
2answers
128 views

Should I do a runtime type check inside generic constructors?

Given this generic class and constructor, class A<E extends Number> { A(E number, Comparable<E> comparable) { //... } } it is ensured that a call to the generic ...
0
votes
0answers
67 views

How to avoid circular dependency from abstracting navigation in desktop application?

I am trying to abstract some functionality from my desktop application (JavaFX) for changing views. So, what I am thinking is: Navigator interface with methods like goToAccountsOverview(), ...

1
3 4
5
6 7
92