Stack Exchange Network

Stack Exchange network consists of 174 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.

1
vote
1answer
156 views

Metrics that measure the readability of the function

Functions are the first line of organization in any program.I believe writing them well improves the readability of code to some extent.I am working on metrics that describe how readable the function ...
-2
votes
1answer
269 views

How to clean a refactor Java for-if-try-catch-else kind of messy code [duplicate]

Often I came across situations like this, how to write this code in a neat and clean way. One more issue I find here is performance as I am iteration a list and then it's properties. Edit : - while ...
0
votes
1answer
119 views

Correct way to receive bulk data from a server in Android?

Ok so to explain I have server in Java that receives data from a C++ program that I have no control over. So the data is transferred over TCP/IP and the Java server just receives it. The volume of ...
0
votes
0answers
43 views

Building a Generic SOAP Layer for an external Service

Status quo: For an existing software product (java) we have built another software (in java) that provides a SOAP service for many of those available calls so we can build our own product in our ...
30
votes
9answers
5k views

Designing a Class to take whole classes as parameters rather than individual properties

Let's say, for example, you have an application with a widely shared class called User. This class exposes all information about the user, their Id, name, levels of access to each module, timezone etc....
0
votes
2answers
115 views

Using the same name for setter and gettter methods for a boolean member variable

Say I have class with a boolean member variable fancy: public class MyClass { private boolean fancy; } Case 1. I could the define the setter and getter as follows: // getter public boolean ...
0
votes
0answers
188 views

Multi-threaded socket chat server design

I've a general question about the design of a multi-threaded chat server application written in Java. At the moment I've the following structure: ConnectionController class which handles the I/O ...
2
votes
2answers
153 views

Input based data fetch optimization

Is there a cleaner/ better readable way to maintain and iterate many-many mapping rather than multiple if conditions ? (One way would be to store the mapping of ReportType -> DataSet Req. in the ...
5
votes
0answers
126 views

Reason for sudden rise in popularity of compile-time annotation processing in Java [closed]

So compile-time annotation processing is as old as the annotations themselves in Java. Yet most of the useful libraries were developed with the runtime approach in mind – at least at first. Now, ...
0
votes
0answers
30 views

Service Discovery and services with multiple protocols

I have a use case where I want to ask a service discovery node about available services. All of these services will have a REST API, but some will also have a Vert.x event bus. The REST endpoints will ...
-1
votes
1answer
162 views

Design pattern for a sequence of related operations

I have a use case where I need to process a request as follows Authenticate the Request Authorize the Request Validate the message (Reads the database for the existing record and validates it) ...
1
vote
0answers
90 views

Are constructors with complex initialization logic always bad? [duplicate]

I've recently read this blog post regarding what a constructor should do and I am also reading Eric Evans' book on Domain Driven Design. Both the blog post and the book state that a constructor ...
0
votes
2answers
147 views

How to represent shortcut nodes in Java?

How would I implement a shortcut finder into an A* path-finding algorithm? Assume that every tile is represented by an (x,y) coordinate, and I know where every "good" tile and every "non-walkable" ...
1
vote
1answer
350 views

Passing context to the execute method in command design pattern

Going through the Command design pattern I understand that we need to create a Command by setting the context via constructor and then calling the execute method to perform some action on the context. ...
1
vote
0answers
100 views

Making java code usable from other programming/scripting language

We are "extending" a product developed by a third party and working with them on that. There's a small problem though. They have some functions (written in java) that they use in their Android mobile ...
3
votes
4answers
856 views

Public static method calls private constructor

I'm working in a C# codebase that was largely written by a former developer and this pattern is used extensively... public class AuditInserter { public static void Insert( DataContext ...
3
votes
2answers
160 views

Singleton for Java Functional Interface

I know there has been 1 million and 1 discussions about Singletons on SO and here and I have had to clean up my fair share of terrible singletons in our code base; one of the reasons I am gun-shy here....
0
votes
2answers
124 views

design discussion, user experience first or correctness first in our case

We are discussing the system configuration module design in our Java medical device software. The system has a voice instruction function used to guide patient during the examination. Different ...
1
vote
0answers
98 views

Putting the rowmapper inside the domain class

Normally in java the RowMapper is placed in its own class. Instead, what about this design, putting the RowMapper inside each domain object, and giving all of them a consistent name: public class ...
0
votes
4answers
179 views

Improvements in java based test framework to reduce execution time

Let me give a bit of background on the problem. We have a java application which has MQ integration and an Integration Test pack which is also written in java. The test pack runs all scenarios (...
1
vote
3answers
211 views

How do I compare parameter- and returntypes at runtime?

I have a Java application that needs to process some data. The data starts off in format A. The application consists of a number of modules which are each capable of processing data. But not every ...
4
votes
2answers
268 views

Clean Architecture: get instance in inner circle of class from outer circle

This might be an easy question for experienced software engineers. I'm currently reading the book Clean Architecture by Uncle Bob, and I'm trying to implement clean architecture in a Java project. ...
1
vote
0answers
201 views

Maven plugin to operate at parent and child module levels?

I have a large multi-module java/maven application where each child module is it's own java application and the root parent pom defines the standard dependencies pom.xml - parent pom - child1/pom.xml ...
0
votes
0answers
168 views

REST API standards to include method in Controller or service layer

We are using REST API with Spring MVC to develop endpoints. I have a question related to method location (controller layer or service layer). Controller has a get() method which accepts some ...
0
votes
1answer
124 views

What is the best way to represent data with inheritance?

In my current work, we need to serialize some data and use it later. Our data is in this format: <resources> <style name="Person"> <item name="name">name</item> <...
5
votes
2answers
248 views

Using static factory methods to prevent unwanted input

Many years ago, I posted a problem I had with some code and received a well written detailed answer that suggested the use of factory methods. I liked this approach, because I can provide a method ...
-1
votes
2answers
216 views

Is it good practice to add comments above generated fields?

Every time I let Eclipse generate a field (most often a serial version UID), it adds a comment above it. Example: /** * */ private static final long serialVersionUID = 6347144762354188381L; This ...
2
votes
4answers
704 views

Is “Let more people able to review” a 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
122 views

Is invoking one repository from another a code smell?

I recently came accross an old webapp project which is using a repository layer between domain and persistance layer. However, the repository layer has been used weirdly. One example is the blog ...
0
votes
4answers
168 views

Should NullPointerExceptions be avoided in Integration Tests?

While writing Integration tests for spring applications, I tend to come across checks for different Multilevel Data Objects For Eg: AssertNotNull("Node 10 is null", getNode1().getNode8().getNode10()....
0
votes
0answers
131 views

Best way to reduce memory consumption on persisting Java objects

Let's say I have an application that maintains relationships between objects - think of a parent-child relationship tree. The lineage of these objects are critical, so maintaining references from ...
0
votes
3answers
4k views

Best way to naming classes and packages in Java

Apart of the code conventions to use camelCase, PascalCase etc., are there any conventions for naming packages and classes in Java? For example, I have an mvc project and the main package is com....
0
votes
2answers
42 views

Ensuring consistency between solr and oracle database

I have a java program, I want to insert data into oracle db and solr at the same time. How can I make sure that data in the db and solr are consistent?
1
vote
2answers
104 views

My implementation accepts only URLClassLoader, may I be less restrictive in my method signature?

I wrote a Java API that accepts ClassLoaders as parameter, even though it won't accept any ClassLoader that isn't a URLClassLoader (because I'm only interested in the URLClassLoader::getURLs() method):...
0
votes
1answer
378 views

Passing an inputStream vs String [closed]

I have a file on the disk. I want a clear distinction of responsibilities between my reader and parser. The reader reads the file and extracts the content as a string. This string is input to the ...
8
votes
2answers
349 views

Philosophy on unit testing daisy-chained methods?

Problem Statement: I have a class that does some validation and it looks something like this: func a() {b()} func b() {c()} func c() {d()} func d() {e()} func e() {return} This is a simplified view,...
-1
votes
2answers
206 views

Prefix name of functions with “Try”

I read in the book "Clean Code" from Robert C. Martin (at page 71) that the better way to handle try/catch block is to separate process (the "try" part) from the error handling (the "catch part"). ...
1
vote
3answers
147 views

difference between expected inputs and implementation details

During a code review, I suggested to my coworker that he had questionable parameters for one of his methods. In particular, the parameters revealed too much about the method's implementation details. ...
-1
votes
1answer
220 views

Best practice for handling many exceptions

I have Java microservice that exposes multiple APIs. Under each API there are many exceptions could be thrown. The last method that catches them all has big catch block ... catch(exc1 e1 | exc2 e2 | ...
-2
votes
2answers
211 views

Converting Java code run by dependency to native code

Is it, at least theoretically, possible to convert a Java application into native code that can be run by something else written in Java? One example of this could be a Minecraft Spigot server. You ...
59
votes
7answers
12k views

Code coverage highlights unused methods - what should I do?

I have been tasked to increase code coverage of an existing Java project. I noticed that the code coverage tool (EclEmma) has highlighted some methods that are never called from anywhere. My initial ...
-3
votes
2answers
847 views

Why does Integer.MIN_VALUE - Integer.MAX_VALUE equals to 1 in Java?

If you run the statement: System .out.println( (Integer.MIN_VALUE)-(Integer .MAX_VALUE )); In java it returns 1 as the answer. Is this because Java just considers those values as 32bit integers ...
-2
votes
1answer
220 views

Role-based declarative security for C#

According to Domain Driven Design and Development In Practice: Spring Security (a sub-project in Spring Portfolio) provides a fine-grained access control in both presentation (URL based) and ...
0
votes
2answers
197 views

what is the impact of logging (or excessive logging) of messages to log file on application performance?

Do logging impact application performance? First thing to know is , whether logs are written serially as processing takes place or are logged into file i a separate process? In java world how should ...
-4
votes
5answers
242 views

I learnt a languge suppose (Java). I also know python. I want to write a simple app. Is there any way to run both language same Time?

I had been learning python and i know Java. if i were to write a simple program, can i write both programming language in one document or compiler? I got into this problem because if i cannot merge ...
-3
votes
1answer
143 views

Using pattern “Repository” for table relations

Have read about "Repository pattern", before it, I have used pattern DAO (data-acess-object). How should I implement table relations with this pattern? Should I create entity for links between tables?...
0
votes
2answers
254 views

JSON in Database Schema Design

I'm working on a web application with constantly changing requirements. The relationships between entities in the database have mostly remained the same but the attributes of each entity type changes ...
3
votes
1answer
189 views

Reducing Redundant Calculations

I am experiencing a dilemma. Let me explain it with two functions: # Takes vector.magnitude(), vector.x, vector.y and uses it somewhere def func1(vector, {other parameters 1}): pass # Takes ...
0
votes
0answers
58 views

Finding appropriate positions for coordinates added to a coordinate-list

I am looking for the most efficient way to find the appropriate position of a geographical coordinate in a list of other (geographical) coordinates forming a route. That may sound a little cryptical, ...
1
vote
2answers
223 views

How to refactor code when capturing calls made to an API service

I am currently in charge of designing the API of a new service. It started simple enough, 10 different URIs or so were allowed. I knew I was not doing the best code, but frankly I did not see a better ...