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
3answers
73 views

Pattern for syncing databases with undo option

I work on a large and old application consisting of a server and a fat client. Part of what the application does is handle a large-ish (a few 100MBs) database of frequently changing data (~a dozen ...
1
vote
1answer
88 views

Event Sourcing - More complex example

Usually when I read Event Sourcing examples - they are pretty simple. When trying to implement something even more complex - it seems to get pretty ugly pretty quickly. Let me explain this on one ...
-3
votes
1answer
62 views

Will this time duration measurement in two threads give correct result?

A program I'm developing has two threads running similar but different task: thread1: timer1.start() writeToExternalDB1(consumedData) timer1.end() thread2: timer2.start() writeToExternalDB2(...
2
votes
2answers
316 views

Does OOP overemphasize the importance of noun and thus put action/verb in the less importance position ? [closed]

Steve yegge wrote an article called "Execution in the Kingdom of Nouns" back in 2006, 14 years later I still find the points he made valid. For example, "Action is what gives life its ...
0
votes
4answers
126 views

Where should transform method to convert from one class object to another class object should live in Java?

I have 2 POJO classes, DatabaseRecord and MyCustomRecord. In my service logic, I wanted to convert the object of type DatabaseRecord to object of type MyCustomRecord. The code for converting should be ...
0
votes
0answers
53 views

How do I store secret keys in a Java Web Application?

I'm developing a small website with a React frontend and a REST API built in Java as the backend. The REST API will be compiled packaged into a .war file and uploaded to a payara server, which is run ...
2
votes
0answers
79 views

Is it correct to use Lombok in a domain object?

I'm starting the refactoring of a legacy app in favor of having a more organized structure, I chose to go with hexagonal architecture since I have lots of well-defined ports and adapters, my use cases ...
-3
votes
1answer
104 views

Is it good practice to use try/catch like Python in Java?

I mainly use Python and just started learning Java. For now, I've tried using try/catch for basic file read/write as follows public String[] readFile(String fileName){ try{ // read file } ...
-3
votes
0answers
59 views

Global data structure in java program

I have an engineer question. How I can better realize global data structures like Property class or database connection pool. I can do it with a static class with a static instance on that class or ...
-1
votes
0answers
65 views

DDD - Dynamic Specifications using Reflection or Domain Logic duplication?

I was looking into the Specification pattern and its uses in DDD. Specifically, about the ability to both validate a candidate object and filter a collection of candidate objects that satisfy the ...
5
votes
1answer
335 views

Why were default methods introduced to Java?

Was introducing default methods to java inevitable? As far as I know multiple class inheritance was not introduced to avoid difficulties with the method signature clash in base classes. So we avoided ...
0
votes
2answers
134 views

How should a “global” resource be handled in Java?

It's a pretty simple question really, how should one properly declare and use a global resource without violating Java's OOP principles? When I'm writing in C, I would declare a struct in global space....
1
vote
1answer
49 views

Handling multiple REST API versions in one codebase

I have a REST API (v1) which routes through to a Java springboot component for which I now need to introduce a number of breaking changes to add new and changed functionality (v2). I understand how I ...
-1
votes
1answer
101 views

Loose coupling with inner classes

I just have a quick question as I couldn't find any concrete answers on the web. Does having a private static inner class promote loose or tight coupling between it and the outer class in Java? Thanks ...
-2
votes
0answers
62 views

What is the best way to add exceptions in GUI Application

I have a GUI Application developed with Java and JavaFX but I need advice on how to deal with exceptions. I have the next case: I have a global unckecked exception handled (using Thread....
-1
votes
0answers
9 views

Oauth credential authorization in 3rd party scenario

How does the Client credentials flow in oauth authorize a 3rd party client user with just the client credentials of a 3rd party?
-4
votes
1answer
52 views

How to setup $JAVA_HOME, because Maven is 1.6, and you are using Java 1.7 or higher?

I have a configuration problem, from this code, https://github.com/plum-umd/java-sketch. Here, I must set $JAVA_HOME, because: "One possible issue you may encounter while building sketch-frontend ...
0
votes
3answers
91 views

When using a DSL to structure my application, should I favor coupling the code with the DSL, or trying to have majority of my code independent of it?

We're currently using the Apache Camel Java DSL to structure our application, but I guess this question can mostly apply to any DSL in general. Now, amongst our developers, we are divided on two polar ...
2
votes
4answers
193 views

Is it correct to say “send a message to an object” in Java?

In Smalltalk we say "send a message to an object", but is it also correct to say "send a message to an object" in Java, or is it only correct in Java to say "call a method of ...
0
votes
4answers
149 views

When to pass a concrete object, vs a way to obtain the object

Say there is some view that displays user details like name, age, email, etc. That view could maybe be constructed with the following pseudocode: UserView(User user); And that view would be able to ...
0
votes
0answers
49 views

What's a valid use case of JPA annotation @Transient?

I'm new to JPA and Hibernate. I just saw an annotation called @Transient, which can mark a field to be non-persistent in the database. However, for the sake of "separation of concerns" ...
0
votes
0answers
56 views

Single DB - Multitenancy with microservices

We are migrating from a monolith to microservice. Note : We store the tenant details in master tenant db which is seperate from the application database As-is: The app serves multiple tenants and has ...
-1
votes
0answers
46 views

Is calling Session::evict() on Hibernate entities considered bad practice?

I'm using Hibernate in my application. When calling the setters on Hibernate entities that are in "managed" state, it will eventually write the changes back to database when the transaction ...
-1
votes
1answer
107 views

Java: Splitting a large unit test class

The project (Java/Spring) I currently work on has a rather large unit-test class for one of its services : more than 1000 lines, several Nested class (one per big functionality), some tests without a ...
0
votes
2answers
160 views

A desktop app which incorporates a REST API?

I am planning to build an adapter between a PC and devices which have the same function but which have different interfaces. The adapter will probably be based on a Raspberry Pi and will have a touch ...
5
votes
6answers
1k views

Are Car objects and Dog objects used in real life programs?

While learning about OOP, I have noticed that a lot of the tutorials give examples of objects such as Car objects and Dog objects, but I don't know if these kind of objects are used in real life ...
-1
votes
1answer
33 views

Opinions on using standardized J2EE APIs over specific over vendor APIs

I have always advocated the use of standardized api, and currently use it on my code. However i always get very strong resistance when it comes to code review, even on projects i have designed and ...
2
votes
0answers
87 views

Why does the Java CompletableFuture API uses long + TimeUnit instead of Duration?

Java 9 introduced many new methods in the CompletableFuture API that support execution timeouts. For example: public CompletableFuture<T> orTimeout​(long timeout, TimeUnit unit); public ...
3
votes
1answer
151 views

What are the advantages of checking for objects with Objects.nonNull()?

Our project changed the object existence checks from foo == null or foo != null to Objects.isNull(foo) or Objects.nonNull(foo). I never got an explanation why that should be better, that's why I ask. ...
3
votes
2answers
126 views

Composing and Inheriting from the Same Type

To start off with an example: I have a read-only Repository used for getting arbitrary values. This behavior can be implemented multiple ways. I also want to allow opt-in mutation of the repository's ...
-1
votes
3answers
89 views

Should methods with business logic be made private? [duplicate]

So I am writing a project using Spring Boot. All of my logic resides in @Service classes. I have separated each service class based on entity. For example - If I have two independent entities A and B, ...
0
votes
0answers
35 views

Multitenancy - Multischema DB and should we handle by individual microservice basis?

I am looking into the revamping my organization's application by moving from a monolithic into a microservice-architecture. My database is a multi-schema shared in one database. Each of these schemas ...
-1
votes
3answers
66 views

Logically grouped interfaces have circular dependencies in call graph, tight coupling. Leave as is, break up CRUD interfaces, something else?

The problem I have relates to an existing system in a specific business domain. I've simplified it into a very similar 'Library/Book' relationship to articulate the problem. Answers such as 'why would ...
2
votes
1answer
111 views

Is it a good idea to use a Lazy wrapper type to encapsulate lazy initialization in Java?

In our code base, we have several static or instance members that we would like to initialize lazily. If the initialization cannot yield null, It's easy to implement. Otherwise, one could use an ...
82
votes
12answers
24k views

What is the utility and advantage of getters & setters especially when they are merely used to read and assign values to properties of an object? [closed]

I’m still really new to learning to program. Just learning the syntax for a few programming languages at the moment. The courses I viewed for C# and Java touched only very briefly on getters & ...
1
vote
0answers
131 views

Should I mock ObjectMapper in my unit tests?

I have different services in a spring application that have a dependency on Jackson ObjectMapper, the unit tests rely on @InjectMocks to inject all the various dependencies to the class that is under ...
1
vote
4answers
211 views

Pattern / solution for Boolean decision making chains

I need a solution for decision making chain. There are number of criteria that may return true, false or be inconclusive. A non-functional code (Java) would look like this: Boolean res = ...
-3
votes
1answer
92 views

How Uber processes orders?

Lets say you created an order. Since Uber is a very dynamic system, one should constantly check if there are available drivers for you. If orders are saved as a some collection (e.g. in MySQL table ...
20
votes
8answers
5k views

Immutable String and Integer in Java: What is the point if assignment in effect changes the value?

If immutability is "good" and yet you can in effect change the value in an Integer or String variable (never mind that you get a new reference -- the value has changed) what good is it that ...
16
votes
10answers
5k views

Are immutable objects important only in multi-threaded applications and if so, how are shared immutable objects useful?

I think the answer to the first part of my question is, "yes" -- no point in making objects immutable in a single-threaded application (or I guess in a multi-threaded application if that ...
1
vote
1answer
63 views

Correct format to receive datatime data from consumer

I am working on a service in a sprint boot microservice application. The consumer for my service can be another service, as well as a UI component. The are 5 entities in my service, each entity having ...
-4
votes
3answers
135 views

Methods that receive buffer objects AND return another Object - is that bad design?

The Argument Some say that if you write a method that receives a buffer, iT MUST RETURN VOID -> the buffer is your exit point. Do not abuse the methods by receiving buffers AND returning a another ...
2
votes
2answers
167 views

Migrating legacy code with singletons to Dependency injection

I'm working on a larger, older project. Our code is littered with classical singletons, i.e. classes like public class ABCService { private static final instance = new ABCService(); public ...
0
votes
1answer
104 views

Application Horizontal and Vertical Scaling

I'm hoping the experienced Java developers here can share some insight about this problem we have been trying to solve for so many months. We're currently building a Java web application that uses ...
1
vote
1answer
38 views

Java, dealing with XML and JPA Annotated Classes

I use xjc to compile XSD files to Java Classes, and want to edit/extend them to make them persistable through JPA. I cant figure out what the best "Coupling?" would be and how to organize it,...
2
votes
1answer
85 views

Effective thread usage under blocking scenario

I have the following scenario: I am listening file requests and when one arrives, I am starting download task in a new thread. After download task ends, a process task starts but this is important, ...
0
votes
0answers
40 views

Licensing a spring boot application inside an AMI

Say we have a standalone spring boot application which we are going to distribute by creating an AMI and sharing on the AWS marketplace. Since the jar is available inside the AMI, I want to stop a ...
1
vote
1answer
63 views

Are the following project distributions valid SOAs?

Currently we are developing an application for service oriented development which is a college signature, the professor created two applications one for backend and other for front. We are using maven,...
-1
votes
2answers
68 views

Should we create review branch in github to story or subtask of jira?

I have an 8 pointer Story. Let’s call it for example XX1234 I have created 4 subtasks based on the list of actions to follow to complete the whole story implementation: 1. XX1235 2. XX1236 3. ...
-1
votes
5answers
152 views

How to manage exceptions in a long call stack

When throw a exception inside java method, IntelliJ suggest to add exception to method signature. When I have a long call-stack as below how I manage these exceptions. method 1() -> method 2() ->...

1
2 3 4 5
93