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
20
votes
2answers
33k views

Best way to structure a Git repository for Maven

I need some advice on how to structure our projects in Git. We use Java and Maven is our build tool. Maven kinda assumes all of your projects have a common ancestor eventually. Maven can also be a ...
2
votes
2answers
83 views

White-Box vs Black-Box

I need some clarification on White-Box vs Black-Box testing. Is it correct that: White-box testing is testing your code that you are familiar with? Black-box testing is testing someone else's code you ...
0
votes
1answer
106 views
+150

Offline audio comparison for Android

I have two audio clips: Source of truth Recording of user I want to compare the two, testing if they are similar enough, removing accents, etc. Any idea how I could do this on Android? To add more ...
0
votes
0answers
112 views

Eureka cluster for service registry with only one IP address

I want to use the Eureka cluster with service discovery. As it said in the documentation, Eureka's nodes can share their state with other nodes. If one Eureka node fails, others still have all ...
1
vote
4answers
15k views

How do you deal with NULL values while creating JsonObject?

I am learning Java and JSR-353. My question is quite forward. Having the method below: public JsonObject createJsonObject() { return Json.createObjectBuilder() .add("address", this....
25
votes
5answers
27k views

Function returning true/false vs. void when succeeding and throwing an exception when failing

I'm building an API, a function that uploads a file. This function will return nothing/void if the file was uploaded correctly and throws an exception when there was some problem. Why an exception ...
16
votes
3answers
11k views

How to debug/change Java code while the program is running?

I just saw a video showing how Notch (of Minecraft fame) is debugging and changing Minecraft while it is running. He pauses the game, changes something in the code and then unpauses the game where the ...
4
votes
2answers
91 views

How do I trigger conditional post processing action without violating SRP?

I have a User Model as below, this Model class is in the shared library. class User { private long userId; private String email; private String userType; private long departmentId; ...
1
vote
1answer
50 views

Is it a good design to have separate Hibernate entities for general user info and user password digest?

I'm developing an app with a user management system. There is a database table named user with the following columns: | Column Name | Column Type | |-----------------|-------------| | userId ...
5
votes
2answers
203 views

How do I efficiently read random lines from a TXT or CSV file?

Context of the problem: I have made chess GUI (Java) The GUI is capable of loading chess puzzles/problems to solve Of said puzzles, I have gotten my hands on a database which is just shy of a million ...
19
votes
4answers
13k views

“Use map instead of class to represent data” -Rich Hickey

In this video by Rich Hickey, the Clojure creator, he advises to use map to represent data instead of using a class to represent it, as done in Java. I don't understand how it can be better, since how ...
17
votes
11answers
38k views

Why is using System.out.println() so bad? [closed]

Of course, it is very good use to use a logging framework for the error messages or warnings. But sometimes I use System.out.println() if I want to try something new in a short time. Is it really so ...
0
votes
0answers
41 views

How can I design a secure content verification web application?

In my country, there is a high number of fraudulent doctor's sick letter as they are manually written on paper. I'm designing a web application to combat this issue and have the whole process ...
0
votes
2answers
171 views

Designing a scalable microservice: how to prevent one instance from performing an action if another instance allready did?

As I am moving a part of the monolith app logic to a microservice, I am standing before a problem with scalability. Currently, the main monolith runs on different instances, and has some scheduled ...
1
vote
1answer
112 views

Naming conventions for classes that technically could/should have the same name

Simple summary of a real problem: I'm making a chess game The engine that makes the chess do the magic is its own independent code (by design, for easy implementation) I am now implementing the chess ...
52
votes
8answers
6k views

Why do “checked exceptions”, i.e., “value-or-error return values”, work well in Rust and Go but not in Java?

Java has "checked exceptions", which force the caller of the method to either handle an exception or to rethrow it, e.g. // requires ParseException to be handled or rethrown int i = ...
3
votes
5answers
201 views

Does abstraction have a relationship with the abstract key word in java?

I learnt the concept of abstraction as: Reducing complexity by hiding unnecessary details. Does this have a relationship with the abstract keyword in java? I see that the abstract keyword is being ...
0
votes
0answers
50 views

Spring boot, n-tier layer structure naming conventions

I am currently developing a huge project in my company with N-Tier Layer architecture using spring boot but I can not sure about the package and class namings. In our project, we have a complex ...
0
votes
4answers
4k views

Where to use C++ today? [duplicate]

Possible Duplicate: Is there any reason to use C++ instead of C, Perl, Python, etc.? When to use C over C++, and C++ over C? I am going to enter university next fall in computer sciences, but ...
7
votes
2answers
4k views

How can I plugin new JARs implementing an interface dynamically?

Quick background: I am working on developing an interface that will be implemented by myself and other developers. This interface will allow users to "plugin" new functional code into a system for ...
0
votes
0answers
23 views

Backend service to configure and interact with custom Android app remotely?

I am developing a custom Android application in Java to run on a phone (the target phone). The app controls and collects data from a BLE wearable device connected to the target phone. Ideally, the app ...
1
vote
1answer
67 views

What are the advantages of sending timestamp in the response?

I am working on REST API and it calls another service and fetch the data and return to the UI. So It does not have any direct DB interactions. Recently we added exception handling feature which uses ...
1
vote
3answers
130 views

Is it called “composition” if we are using primitive data types?

The following is an example of "composition": public class Car { Engine engine; // Engine is a class } But is it still called "composition" if we are using primitive data ...
2
votes
1answer
111 views

Best way to handle lazy models with mapstruct and spring transnational scope

In a typical Java Spring Web APP: we have the following layers: Model [DB Models] Repositories [where you have queries to DB] Services [Business service where you have the @Transactional annotation] ...
2
votes
1answer
59 views

What are the best way to publish application event in a spring boot application?

My goal is to collect/publish different types of information from the application. We use Kafka for the event bus. Consider the following sample code. class UserService { public User ...
24
votes
2answers
15k views

Why are packages and modules separate concepts in Java 9?

Java 9 will have modules in addition to packages. Usually languages have one or the other. And most programmers perceive two terms as synonyms. Modules are built on top of packages, treating them as ...
0
votes
2answers
109 views

Object Oriented Design for chess

Recently I came across some article on Chess OOPS design.Following is some snippet from it: public class Chess { ChessBoard chessBoard; Player[] player; Player currentPlayer; List<...
-2
votes
1answer
56 views

Initialize some values from an array, write more elegant or efficient

I have tried this piece of code: String[] latitudesArray = latitudes.split(","); String[] longitudesArray = longitudes.split(","); Double startLat = ...
4
votes
1answer
101 views

Modelling java annotations in an UML class diagram

Goal: I am trying to create a UML class diagram for a java spring application. Spring uses a lot of annotations and I couldn't find any resources online on how to properly model them in UML. I know ...
1
vote
3answers
184 views

Java Inheritance Problem

I have the finance application where we can have different types of transactions, like balance enquiry, funds transfer, and pin change etc. Now the Transaction is a base class, and there are specific ...
6
votes
3answers
9k views

Using streams as method parameters and/or return types

So let's say I have a 'Transformer' interface that can transform one file-type to another. Let's say I also wish to use streams to provide the data to the Transformer. Which is the approach that is ...
15
votes
5answers
33k views

Does it make a difference if I declare variables inside or outside a loop in Java?

Does it make a difference if I declare variables inside or outside a loop in Java? Is this for(int i = 0; i < 1000; i++) { int temp = doSomething(); someMethod(temp); } equal to this (with ...
15
votes
5answers
12k views

Sharing DTO objects between microservices

TL;DR - Is it ok to share a POJO library between services? Generally we like to keep the sharing between services strictly limited to none if possible. There has been some debate whether or not the ...
107
votes
5answers
89k views

Why were default and static methods added to interfaces in Java 8 when we already had abstract classes?

In Java 8, interfaces can contain implemented methods, static methods, and the so-called "default" methods (which the implementing classes do not need to override). In my (probably naive) view, there ...
27
votes
9answers
13k views

Why there is no power operator in Java / C++?

While there is such operator - ** in Python, I was wondering why Java and C++ don't have one too. It is easy to make one for classes you define in C++ with operator overloading (and I believe such ...
1
vote
1answer
94 views

Writing Event Process architecture for multiple event handler interfaces

I am working on Java program which will listen multiple kind of events from multiple sources and store information to multiple sinks. Each interface will have its own source to listen and own sink ...
62
votes
6answers
27k views

Why was C# made with “new” and “virtual+override” keywords unlike Java?

In Java there are no virtual, new, override keywords for method definition. So the working of a method is easy to understand. Cause if DerivedClass extends BaseClass and has a method with same name ...
102
votes
6answers
151k views

Stack and Heap memory in Java

As I understand, in Java, stack memory holds primitives and method invocations and heap memory is used to store objects. Suppose I have a class class A { int a ; String b; //...
1
vote
2answers
73 views

Abstract factory pattern for creating complex shapes

At the moment my code looks like this. I have simplified the UML so it does not contain unnecessary information. I have used abstract factory design pattern. My job is to create shapes. The problem ...
0
votes
0answers
25 views

Forecasting future batch sizes to balance throughput capacity?

I've a data streaming platform (Nifi) where I need to transfer tables of data between databases on given schedules. I want to be able to calculate in advance the optimum batch/schedule size i should ...
1
vote
1answer
267 views

Appropriate design / technologies to handle dynamic string formatting?

recently I was tasked with implementing a way of adding support for versioning of hardware packet specifications to one of our libraries. First a bit of information about the project. We have a ...
3
votes
1answer
144 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 ...
-2
votes
1answer
57 views

What should I use to graphically represent an object's position on a fixed path using python(preferred)?

Consider 2 roads merging into one(This map is supposed to remain fixed). The program will not generate this map. The program will read this map and plot positions on it on its own. The python program ...
1
vote
1answer
7k views

use of minOccurs=“0” without nillable=“true” in SOAP

I have received an XSD from a 3rd party supplier generated from a Java based system; which is to be used to create a SOAP endpoint for us to receive data transfers. Their XSD does not make any use of ...
0
votes
1answer
60 views

Suggestion a Safe Strategy to Migrate to Monorepo

Consider a bitbucket project with 3 separate repos, A, B, C. These form the components of a microservices application, APP. We'd like to safely try out a monorepo pattern and see if it streamlines ...
0
votes
2answers
55 views

How to cover by tests HTTP API wrapping library

As mentioned in title, I don't understand how I supposed to cover by tests code which is just wrap http api. I guess I can write only unit tests, because wrapped service is paid. Integration tests in ...
0
votes
1answer
76 views

May I and should I include my dependencies in the jar i publish online?

I'm developing a java project that I'd eventually like to publish and make open source. To make a executable jar file I use the maven-assembly-plugin. This includes my dependencies in the jar, which ...
-4
votes
2answers
2k views

How to create a method that takes array list as argument?

To create a method that takes an array as an argument, you would do this: public static void printAges(int[] age) { // prints ages to screen for (int x = 0; x < age.length; x++) { ...
1
vote
3answers
5k views

How to use Guice for an effective API Design?

I am creating a base API in JavaSE, which includes modules like MVP architecture, Service & Repository Layer, Event Model to fire events between presenter etc. I am trying to implement all best ...
2
votes
1answer
99 views

Handling OAuth 2.0 access token

I am creating a rest template to consume REST API secured by OAuth 2.0. The provider has implemented an expiry for the access token for 5 mins. So Using the rest template, I will be calling the ...

1
2 3 4 5
94