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.

learn more… | top users | synonyms

-1
votes
0answers
13 views

Pointers to use org.xml.sax.EntityResolver.class [on hold]

I have a small situation while implementing the org.xml.sax.EntityResolver.class. The sample XML file that's used to reproduce XXE attacks is provided below. <?xml version='1.0' encoding='UTF-8'?&...
19
votes
5answers
2k views

Should non-trivial conditional statements be moved to the initialization section of loops?

I got this idea from this question on stackoverflow.com The following pattern is common: final x = 10;//whatever constant value for(int i = 0; i < Math.floor(Math.sqrt(x)) + 1; i++) { //...do ...
3
votes
2answers
59 views

Pattern for a method call outcome

Most often I need to call a service method from a controller, and based on the outcome, if there's an error show an appropriate error message depending on the error (or some other action, showing ...
0
votes
0answers
17 views

Implementing Data Type Independent User Set Values

I'm trying to set up a very simple user defined variables that can be set in an administration panel and used in the system. Our application is going in the direction of configuration over custom ...
-4
votes
0answers
29 views

How to overcome the timeout issue during an ElasticSearch call from Spring Microservice?

We are using Spring Microservice. We need to implement a Java library that makes ElasticSerach calls using Jest as our ELK Client API. The exposed interface of this library would then be used by the ...
7
votes
4answers
269 views

Subtyping without adding state or behavior - Bad Practice?

Observation There are many Exception subtypes that don't have any added state or behavior. For example, ClosedByInterruptException code. Question Why is subtyping without adding state or behavior "...
-2
votes
0answers
44 views

Easiest way to develop a web app in Java [closed]

It seems like developing a Web App in Java is simply not a straight forward process. From the hosting to selecting a framework and a dom to the template engines it seems like you have 100 different ...
1
vote
2answers
173 views

How come language designers don't upgrade their global functions?

For example, when working with arrays there are methods like indexOf() that works like this: if (array.indexOf("something")!=-1) { // do something or nothing } Why hasn't someone made a contains ...
1
vote
1answer
85 views

Is it a good programming practice to store java properties keys in ENUM for validation once application starts?

Sample Java properties file which is read by the properties class appl.component1.property1=value1 appl.component1.property1=value2 Custom class which extends the java.util.Properties class adding ...
1
vote
0answers
73 views

Is Java for server runtimes like JBoss EAP / Wildfly still free to use? [closed]

With Oracle starting to collect license fees from different customers for using Java SE I've asked myself if the usage with a server runtime is still free. I'm no lawyer and all these licenses are ...
-2
votes
0answers
72 views

How to create an application to look up users from a database? [closed]

Following is a problem that I am trying to solve: If I have a database of 2 million employee records each of which includes a first name, last name, company id(unique for every employee), and ...
-1
votes
1answer
25 views

method to check nested transaction

So I am writing a method to check and throw if a new transaction is being made in another transaction. I first came up with straight forward checkNestedTransaction, but this seems vague since I cannot ...
1
vote
1answer
73 views

Generating a Beta Reduced Lambda Expression in Java

Good day, I'm a beginner in Java and I was wondering if, in Java, I'm able to do a beta reduction with a given lambda expression in Java. Basically lambda reduction is like this: 1.) Expression : (...
8
votes
2answers
122 views

Is it ok to have dependencies inside a class that's meant to be exchangable?

Let's say I'm having a domain-model and I want to read and save it from any persistence layer - right now it might be a json file but in the future it could be xml or a database (which might also ...
3
votes
1answer
37 views

How would you create a custom CDI @ProcessScope?

I am coding a Java EE application that provides REST services via JAX-RS resource classes, the application makes extensive use of CDI. My resource classes are @RequestScoped, the application returns ...
3
votes
1answer
71 views

Contract interface/class with inner classes/interfaces

Brief description of my project structure. I have some base classes like BaseView, BasePresenter ... . Also my project consists of modules, module represents one complete part of the application. ...
10
votes
5answers
881 views

Is “static interface” a good practice?

I've just recently noticed there is an option to have static methods in interfaces. Same as with static fields of interface, there is an interesting behavior: These are not inherited. I'm unsure it's ...
-1
votes
1answer
70 views

Question about the Java objects' equals() method

I have a question about the object X.equals(Y). I use Sonar and it says that I have to move the "" string literal on the left side of this string comparison: !date.equals(""). So I did that: !("")....
3
votes
2answers
65 views

Value object that depends on multiple aggregates' lifecycle in DDD

During prototyping a simple ddd application from public transit domain I've faced a problem with one value object - Transit Pass: Each Customer can buy a transit Pass thatallows a passenger of the ...
4
votes
2answers
74 views

Java Properties Files for Both Operations and Developers

We have an enterprise application. Maven build, about 20 submodules with more submodules. We have a dedicated Ops (operations) which deploys our application to 10 clusters. Installations are running ...
3
votes
2answers
165 views

Is expecting the API user to implement an UnsupportedOperationException okay?

I'm writing a handler for download/import of data. After inserting data to the database, several import jobs can be called, but usually it is just one. So there are two methods to get the import job(s)...
1
vote
1answer
122 views

Number equality / abstraction from precision and representation

I try to have find solution to get away from these heavy problems of number comparisons in Java... at least for numbers in a certain range with a certain precision with certain representation error. ...
6
votes
2answers
298 views

Is it considered a bad practice to create the Object.equals() method for testing purposes only? [duplicate]

Like the title says, is it a bad practice to create/generate the Object.equals() method because I need it in my unit tests, but not in my regular code?
-2
votes
0answers
29 views

Scala returning object type in if/else statements [migrated]

currently i have an abstract class called example, three case classes extending abstract class, and a function with a return type of example. in the function, when a certain condition is met, it is ...
3
votes
1answer
93 views

What are common Java dependency management strategies?

I am currently preparing a presentation for my software engineering class, in which I want to present the idea of package dependency management in Java on the example of "radial encapsulation" (http://...
-1
votes
3answers
141 views

Anonymous class as singleton

While implementing one of my modules, I needed a singleton for one of my classes, say, ModuleManager. Instead of creating a class with singleton criteria, I created an interface ModuleManager to ...
9
votes
7answers
2k views

Why is cyclomatic complexity that important for a single method?

I am using SonarLint for Eclipse since recently, and it helped me a lot. However, it raised to me a question about cyclomatic complexity. SonarLint considers as acceptable a C.C of 10, and there are ...
1
vote
1answer
103 views

Pass result in API Chaining

We have set(6-8) of API and it will be invoked in a sequence . there are cases, want to use output of first/second API in the third/fourth API . We have request object which is passed as input to all ...
19
votes
1answer
367 views

Does it make sense to measure conditional coverage for Java 8 code?

I'm wondering whether measuring conditional code coverage by current tools for Java are not obsolete since Java 8 came up. With Java 8's Optional and Stream we can often avoid code branches/loops, ...
5
votes
2answers
139 views

How to encapsulate internal classes in an API written in Java?

We have to write a library. Naturally, it should only have a very small API (as broad as needed as small as possible). The internals of the library are somewhat complex. Therefore, they need ...
3
votes
1answer
75 views

Parsing Multiple Files and Their Contents in Java using Multithreading without ExecutorService

I'm learning concurrency in Java and went over the tutorials on oracle website. While I have understood some of it, a greater portion eludes me. I was thinking of a hypothetical problem (though it may ...
3
votes
2answers
100 views

Mechanical State Estimator design

I want to write a library for Mechanical State Estimation of a vehicle. This is, estimate variables as position, velocity an so on, using the information provided by different sensor measurements (GPS,...
7
votes
4answers
245 views

Composition of two classes with common inheritance root

Hope your day is going well. I want to make the following composition of two objects with the same inheritance root: There will be 3 basic operations on the Wallet class: add, getCards and ...
1
vote
0answers
32 views

Spring MVC - Handling validation errors using the jQuery Validation plugin

Using jQuery validation, I send an AJAX request which is handled by the controller. The controller does send a response, but jQuery fails to insert the respective error message into the DOM. Instead, ...
1
vote
2answers
221 views

Java - Processing a large file concurrently

So at a high level my use case is as follows - I periodically (every 24 hours) get a very large file (size can vary from MBs to 10s of GBs) which I need to process within 24 hours. The ...
8
votes
2answers
170 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 ...
1
vote
1answer
80 views

How to design the system which executes two process independently with different configuration?

I have two process ProcessA and ProcessB. I want to run these two process independent of each other. There is no relation between them at all. Each process should have a different Properties object. ...
4
votes
2answers
52 views

Deleting a node and returning the deleted node's value in a Binary Search Tree?

Hi I have a programming project where I'm basically using a Binary Search Tree to implement a min/max priority queue. I'm having trouble with the popMin/popMax methods. I get how to get the minimum/...
3
votes
1answer
130 views

Algorithms comparison and complexity

I want to sole this problem: Write a method to return all valid combinations of n-pairs of parentheses. The method should return an ArrayList of strings, in which each string represents a ...
2
votes
3answers
419 views

Should only static functions print to screen?

My question is more about trying to figure out if my belief is correct or valid in that a static method should be the only one that prints to the screen (let's say in a terminal). I am using Java and ...
1
vote
1answer
106 views

Message driven architecture and horizontal scaling

During working on a pet project in microservice event driven architecture, I've faced a problem of delivering responses to a client. Each microservice (API Gateway etc) has many replicas and has it's ...
2
votes
0answers
179 views

Design elevator system algorithm and classes? [closed]

Here are the main classes I can think off the top of my head. All business objects will follow the abstraction (implement interfaces). I have not mentioned interface names to avoid verbosity. I have ...
4
votes
1answer
138 views

Are there only 2 places you can declare new generic type parameters in Java?

It's confusing because type declaration and usage both use the <T> syntax. I think there are only 2 places where you can declare new generic types in Java: 1. In the definition of a class or ...
1
vote
0answers
46 views

Reuse of java beans for REST acceptance tests

We have acceptance tests for our REST endpoints using rest-assured. The tests currently have they're own fluent JSON builders. They help us remove noice from our tests. For example. .body(someUser()....
4
votes
4answers
165 views

Indicating the end of a stream when null is a valid return

I have two kinds of data streams that both implement the same interface: public interface DataReceiver { public Data getData(); } public class DeviceDataReceiver implements DataReceiver { // ...
8
votes
4answers
589 views

What are the responsibilties of the main in object oriented programming?

I'm new to object oriented programming and I don't understand what's the purpose of the main. Yes, I read that it's the "entry point" of the program but what I don't understand is what should be in ...
2
votes
0answers
51 views

Pattern for retrieving batches of Objects?

This seems to be a recurring requirement for me, so I'd like to get some feedback on how to implement it and what sort of test code makes sense. I need to retrieve batches of data and stitch it ...
7
votes
0answers
102 views

I need to write my own version of a bounded queue [closed]

I need to write my own version of a bounded queue. It must be thread safe. The consumption of this queue is based on a priority system, where a consumer makes a request for an object in the queue. ...
3
votes
1answer
85 views

Is avoiding having the fields representing the same object in different communicating classes reasonable?

I'm developing a program which does communication to different types of devices (with respective protocols). It should concurrently acquire messages from devices and write them to a file with specific ...
-1
votes
1answer
113 views

MVC with several MVC-patterns and gameloop

I made a small program using several MVC-patterns. So far I havnt got to much stuff to put in the model so I havnt got any model yet. My idea is to make one MVC pattern for each panel. And looping ...