Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

2
votes
0answers
51 views

What is the best way to handle glue between different classicly OOP objects at the higher levels of abstraction?

In object oriented programming, it is commonly said that each class/object/instance should have a well-defined purpose. For example, there may be a Window class in a windowing toolkit, a ChunkLoader ...
0
votes
1answer
137 views

How best to avoid member implementation of class' Abstract/Interface instance variables

I'm sorry if the phrasing of the question is a bit unclear but let me try to clarify below. (If anyone can word it better, feel free to edit) I have a Map instance variable, groups, which is defined ...
1
vote
1answer
77 views

What naming convention should you use for the 2 model classes of the same business logic, one shallow and one deep [on hold]

In one of our services we have business objects, and sometimes we would like to return them in their "flat" form and sometimes in their hierarchical form. An example: Let's say we have an Account ...
1
vote
3answers
3k views

How to avoid != null statements? [duplicate]

I use code object != null to avoid NullPointerException. Is there a good alternative to solve this as follow ? if (someobject != null) { someobject.doCalc(); } This will not work for ...
22
votes
6answers
4k views

What are the benefits of prefixing function parameter names with p*?

I often see projects (in Java projects and teams using Eclipse) that prefix function parameters with p. For example public void filter (Result pResult) ... I personally don't see any benefit in ...
49
votes
6answers
20k views

Workaround for Java checked exceptions

I appreciate a lot the new Java 8 features about lambdas and default methods interfaces. Yet, I still get bored with checked exceptions. For instance, if I just want to list all the visible fields of ...
2
votes
3answers
10k views

How to reduce size of jar file?

I dont know how to reduce the size of jar file. When we normally code in Java Swing the jar file is created, is there any way to reduce the size of jar file? I can't remove the images and other stuff ...
6
votes
4answers
324 views

Advantages of HATEOAS based RESTful service

There is a scenario, where we have two commercial applications that are so called REST based(java) but not HATEOAS compliant. Development activity is out-sourced to vendor Development phase of ...
-1
votes
1answer
61 views

How to build a custom intermediate operation pipeline in Java for a series of API calls? [closed]

I am working on a project which provides a list of operations to be done on an entity, and each operation is an API call to the backend. Let's say the entity is a file, and operations are convert, ...
-1
votes
3answers
144 views

How do I transition a java application to have a web server? [closed]

I'm not a java programmer so I'm really struggling to figure out how to tackle this task. I was given a plain (not a web application) java SE application that creates multiple threads to control TCP ...
4
votes
3answers
2k views

Java Interfaces in Layers pattern

I'm developing a Java software according to the object-oriented Layers architectural pattern. Every layer should be clearly separated from the rest, and provide a well-defined interface to use it's ...
72
votes
7answers
141k views

Why declare final variables inside methods? [duplicate]

Studying some classes of Android, I realized that most of the variables of methods are declared as final. Example code taken from the class android.widget.ListView: /** * @return Whether the list ...
12
votes
4answers
16k views

What is the difference between Callable<T> and Java 8's Supplier<T>?

I've been switching over to Java from C# after some recommendations from some over at CodeReview. So, when I was looking into LWJGL, one thing I remembered was that every call to Display must be ...
2
votes
2answers
204 views

Java 8 - When should I use java.util.Stream instead of java.util.Collection?

I started studying functional programming with JavaScript. After this, I started to study it with Java 8 (streams, lambdas and method reference) and I realised that I tend to use streams as much as ...
39
votes
7answers
30k views

Is it a bad practice to have an interface to define constants?

I am writing a set of junit test classes in Java. There are several constants, for example strings that I will need in different test classes. I am thinking about an interface that defines them and ...
1
vote
0answers
41 views

Third-party API wrapper in Java: how to design

Suppose, there's a site that provides an API, such as this: Users post questions, answers on that site You can make GET and POST calls There are two types of authentication: weak (only gives read ...
1
vote
1answer
143 views

Why did Java and C sharply dip in popularity around 2017 in the TIOBE index? [closed]

The TIOBE Programming Community Index shows Java and C dramatically falling in popularity between late 2016 and mid 2017 before rebounding by mid 2018. What is the cause of the volatility? Source: ...
0
votes
2answers
166 views

Java Constructor Syntax and Design [closed]

With regards to object-oriented Java constructor syntax and design, specifically parameterized or specific constructors, it is the accepted process, as describe in books, to build a parameterized ...
0
votes
2answers
186 views

Is using Objects.requireNonNull() in production bad practice?

Objects.requireNonNull is a helpful method to spot NullPointerExceptions effectively while developing. But in fact it's throwing a RuntimeException which could crash the application (the worst thing ...
107
votes
12answers
14k views

Rationale to prefer local variables over instance variables?

The codebase I'm working on frequently uses instance variables to share data between various trivial methods. The original developer is adamant that this adheres to the best practices stated in the ...
1
vote
2answers
145 views

Unique Identifiers for classes - Java with Spring

My use case requires me to implement multiple validators which implement the interface: public interface Validator { boolean validate(Object o); } Based on the business group of the Object o, a ...
1
vote
1answer
28 views

How to Define the Bandwidth in Mean Shift Clustering?

I am making a program using Java todo colo quantization using mean shift clustering algorithm and the image is RGB with resolution of 512x512. I want to reduce the image file size by reducing the ...
6
votes
3answers
3k views

Clean Architecture - Too many Use Case Classes

I'm going into Clean Architecture and lift my Android level from MVC to MVP, introducing DI with Dagger 2, Reactivity with RxJava 2, and of course Java 8. In MVP clean architecture there is a layer ...
-1
votes
1answer
78 views

Project design/structuring using DDD for an API with a lot of third party services integrated? [closed]

We have a Java/Spring Boot rest API project. This will be the first of several Microservices How do we structure based on Domain Driven approach for a microservice which has several third Party API ...
2
votes
1answer
74 views

Should I group related data fields and views together, or group data fields into a DataClass (as well as group views into a ViewsClass)?

For example, if I have a game which have some components, which has Player and Enemy,as well as the parent container,Game, e.g.: Version 1: public class Player{ private int hp; private ...
2
votes
1answer
32 views

Externalized properties for an Java EJB application

I am not sure if this is the right place to post this question, but I think this might be better suited than Stack Overflow. I have got an online application, a Java EJB application. Requirement is ...
5
votes
3answers
5k views

Should a Java Boolean be used for ternary (3-state) logic?

I'm trying to make a basic cache of a boolean value, and I did it like such: private Boolean _valueCache = null; private boolean getValue() { try { if (_valueCache == null) { // if cache ...
1
vote
0answers
66 views

jar deployment best practices for scaling [closed]

How to orchestrate deployment of a jar across machines (oddly 20 and could scale). Is there a known solution? Currently I’m copying the jar on to all the servers one by one for every release. (I know!)...
-1
votes
3answers
234 views

Can an object in java have behaviour without having any state

I was just studying the interdependence of state and behavior exhibited by the state of an object and its behavior.was wondering if an object can have behavior without having state. Because i am very ...
0
votes
1answer
52 views

Objectreference vs Equality [closed]

While coding I stumbled upon something like this (extremely simplified example): public bool Func() { Object[] array = new Object[] {false, false}; return array[0] != array[1]; } I was ...
0
votes
1answer
56 views

How to have parent and child modules in Maven that both package as jar files?

I have an unresolvable dependency issue in a Maven project; different pieces of code depend on different versions of dependency A (i.e. most code needs A:0.15; some needs A:0.18). Fortunately, the ...
-2
votes
0answers
37 views

Pattern for building objects from JSON [duplicate]

Is there a specific pattern that we can follow that allows to build and object graph from reading say JSON or Yaml config? I already have my object defined but now I want to build a bunch of them by ...
1
vote
4answers
91 views

filter + map api design

I am writing a library call that will allow you to filter and map in the same iteration of the loop, this is async/callback style in Java. The problem of course is that for filtering we usually return ...
4
votes
1answer
2k views

Microservices Architecture separating backend and front end

We are trying to move (slowly) into Microservices architecture from our current monolithic based architecture. I've done my research on microservices architecture and would like to get some feedback ...
89
votes
16answers
18k views

Do the young minds need to learn the pointer concepts?

Why did the C master Dennis Ritchie introduce pointers in C? And why did the other programming languages like VB.NET or Java or C# eliminate them? I have found some points in Google, and I want to ...
3
votes
2answers
130 views

Passing a list of base class objects to a method and using instanceof to filter them

I'm working on a Java reverse engineering project, where I am analyzing bytecode and trying to identify classes, methods and fields using the ASM framework. After identifying these I transform some ...
0
votes
2answers
91 views

How to design an API wrapper with bulky operations on domain object? (Need guidance)

I need some guidance in designing an API wrapper for my backend APIs. I have tried to keep it as specific as possible. Context: We have a project which supports certain file operations like edit, ...
2
votes
1answer
78 views

Applying Domain Driven Design - Model/Implementation

I'm quite new in the DDD-World and I'm just trying to figure out all the basics so please bear with me! I have the following Entities: - Datamodel - Object Types - Object Fields A datamodel can ...
29
votes
6answers
23k views

Programming language usage at Google [closed]

I have heard Google uses Python, Java and C++. But what I don't know is how is each of those programming language is used. I mean what is Python, Java and C++ is used for at Google. Why would they ...
218
votes
6answers
100k views

Choosing between Single or multiple projects in a git repository?

In a git environment, where we have modularized most projects, we're facing the one project per repository or multiple projects per repository design issue. Let's consider a modularized project: ...
2
votes
1answer
121 views

Do we include output space in space complexity?

For example. I have a function which generates an array with random numbers. int[] generateNum(int n) { int[] result = new int[n]; /* Logic to generate random number */ ............... ...
1
vote
2answers
214 views

New version of REST API - deploy two services?

Assume you need to define a completely new REST API for a given service. These rest APIs are distinguished by something like "v1" and "v2" in the path. If you develop these services in Java, would ...
53
votes
3answers
16k views

Is there a performance benefit to using the method reference syntax instead of lambda syntax in Java 8?

Do method references skip the overhead of the lambda wrapper? Might they in the future? According to the Java Tutorial on Method References: Sometimes... a lambda expression does nothing but call ...
0
votes
1answer
58 views

Push partial result to user [closed]

I'd like to build a small system which takes a user input in a web page, submits the information to a backend, which subsequently calls a few different apis, and then updates the user with the results ...
7
votes
3answers
4k views

var args constructors/methods vs lists

In the long debate of using arrays vs lists in the public API of Java classes, I tend to prefer lists in most situations. However, I also found convenient to use var arguments in many constructors and ...
1
vote
1answer
638 views

Composite and Observer pattern implementation

I'm learning Composite and Observer design patterns and I have created a FileSystem class where I define Node, Folder and File as a composite relationship. Now I want to implement Observer pattern so ...
-2
votes
1answer
49 views

Montoring website for Job scheduling software [closed]

I have a job scheduling software that uses Unix cron for scheduling a job. Unix Cron takes care of launching a Job process at a specified time. Each run of Job has a key (job_name and a date) ...
1
vote
1answer
89 views

Have generic methods that transfer DTO's from different packages, but contain same fields

I have 3 services Service A, B, C which put and get data to/from Service D +============================================+ | Service A | Service B | Service C | +==============================...
2
votes
4answers
848 views

Is “Let more people able to review” a valid reason to “write c++ as if Java” at some degree?

According to Should we avoid language features that C++ has but Java doesn't?, I know it is horrible to write C++ as if Java, mostly because it drops the beneficial features of C++ languages. But ...
0
votes
1answer
68 views

When to use logger.info in sl4j

For my application logs for a REST server, I'd like to log some details about each http request. I'm using sl4j. Should I use logger.debug or logger.info More generally what sort of things should be ...