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
0
votes
0answers
19 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 ...
-3
votes
1answer
21 views

Assigning task to servers in an Online Judge [on hold]

If I want to implement queue(say ActiveMQ) for an Online judge to queue the submissions by a user to be assigned to server(say quadcore we have lets say 4 machines) to run that user code, then should ...
1
vote
0answers
98 views

What challenges may arise from mixing Kotlin and Java in an old Java project? [on hold]

I work in a team looking to adopt Kotlin in an old Java codebase (500,000 lines of code, some parts are up to 20 years old). Due to the size of the project, we're considering using Kotlin for all new ...
1
vote
1answer
102 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
0answers
65 views

Heavy Calculation on Client Side or Server Side [closed]

I have a moderate web application which is Angular 8 on client side(TypeScript) and Web services(Java 8) on server side. I have a dilemma: 1.On one hand, I want to keep my server side agnostic and ...
3
votes
3answers
229 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
83 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
105 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
1answer
51 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
72 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
48 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
0answers
34 views

Using DTO in service works fine with APIs but it does not get along when using on another service or component

I was thinking about good design to follow when doing service layer and found a lot of talks and recommendation about encapsulating the domain in the service layer and use DTO objects instead for ...
-1
votes
1answer
318 views

How to avoid code duplication in this situation?

Case: Several methods with same params validation inside, like: public Response someFunction1(String param1, int param2) { if (someCondition) return Response1; if (someCondition2) ...
2
votes
4answers
195 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
69 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
193 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
63 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 ...
2
votes
2answers
144 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
73 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....
0
votes
0answers
5 views

How to setup parsing SOAP generated XML files with multi level relation ships to JSON [migrated]

I am dealing with SOAP web service which has Meta Model with multiple/multi-level relationships and adds a complexity of custom XML definition but still based on the Meta Model (to get required ...
1
vote
1answer
89 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
33 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
409 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
150 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 ...
0
votes
1answer
68 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. ...
0
votes
0answers
138 views

Code Structure: Keep classes simple or keep usage simple?

Tl;dr: In terms of the "high cohesion and low coupling" principle, how do I best deal with many simple objects that need to access the strings.xml resource in order to correctly parse an output? I'm ...
1
vote
0answers
30 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
87 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
45 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 ...
2
votes
7answers
288 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 ...
5
votes
3answers
384 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
46 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
96 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
20 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
39 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
109 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
122 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
55 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(), ...
0
votes
1answer
96 views

Is it okay to use a different JDK from what my team use? [closed]

I am a new hire (as a software engineer) in a company and the Linux (Ubuntu 18.04) machine I got has no java installed. I tried to install Java SE 8 kit from Oracle but apparently there is a new ...
-1
votes
1answer
63 views

Which programming paradigm mixes well with reactive in java? [closed]

So I have the feeling that one can forget object oriented programming when reactive streams are in use, due to the lack of the async-await syntax (because with the call chaining, the state has to be ...
0
votes
3answers
81 views

Ensuring Thread Execution Order when Writes Must Occur Before Reads

I'm currently designing a server with the following structure: A TCP thread pool that receives data from the network A queue that holds these requests A worker thread pool of a fixed size that takes ...
0
votes
1answer
44 views

Passing and using properties through annotations in Java

I have a Java EE Application in which I have an Interceptor class like this @Interceptor @Logged public class LogInterceptor { @AroundInvoke public Object logMethod(InvocationContext context) ...
0
votes
2answers
115 views

What are the “scalar fields” and “composite fields” in JAVA?

Need to understand the below definition, from the protobuf tutorial: mergeFrom(Message other): (builder only) merges the contents of other into this message, overwriting singular scalar fields, ...
-1
votes
2answers
116 views

When self-referencing in a table, do you prefer `parent_id = null` or `parent_id = id` for a row referencing to itself?

For the discussion, I will provide my example. But I am interested in the broad guidelines. I save in my postgres DB legislation (law texts) composed of a single header (H), paragraphs (P), sub-...
1
vote
3answers
251 views

Should business logic be in the app or in the backend?

I've recently started applying the Clean Architecture while developing an Android application. And so I divided my application in 4 different parts. Data layer Contains the implementation of ...
0
votes
2answers
105 views

Ensure unicity of a 10 characters alphanumeric String

I have a requirement of developing a service that must generate each day few millions of random and unique alphanumeric String of length 10 (I can't increase this length, this is a customer ...
2
votes
3answers
130 views

Doubt about package-by-feature and circular dependencies

I am implementing a library that: Takes some input data (I put data structures and classes in the parsing package) Stores the data in a structure (I put data structures and classes in the storage ...
0
votes
1answer
191 views

Parsing and validation of a csv file

I am trying to create a library where I need to validate and parse a file in a CSV-like format and then use this data to generate a Tree data structure. At the moment I split the process into two ...
2
votes
1answer
91 views

What to do when you want to apply some common functionality to some specific methods?

I am trying to figure out a design pattern to use (if any exists) to a situation where I would be re-doing some functionality across a bunch of classes. Below is a (simplified) overview of the problem ...
0
votes
1answer
114 views

Dealing with interrupt and sleep

I was thinking that I could calmly Thread.sleep() on an interrupted thread. Sonar doesn't think so, of course. In some circumstates we should waiting for conditions, even if an interrupt occured. Is ...