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

0
votes
1answer
65 views

Controlling concurrency by Thread Pool in scenario of CPU-intensive and I/O intensive requests?

My goal is to understand how to handle jobs coming from the client side at very high frequency each job is either CPU-intensive or I/O intensive, but both types of jobs are continuously arriving at my ...
1
vote
0answers
101 views

How do I find which code is unused once my unit tests have been written? [migrated]

I'm developing unit tests to cover all of my code, but in IntelliJ IDEA the code no longer shows as "unused" because I have a unit tests which cover them. Is there a way to exclude unit tests from ...
3
votes
2answers
209 views

How should blank/empty value objects be instantiated/structured?

I was wondering... what is considered the best practice to instantiate blank value objects? (in Java) E.g. Assume we have some value object class Foo, that could be blank. Would creating methods ...
12
votes
2answers
505 views

Taming the 'utility functions' classes

In our Java codebase I keep seeing the following pattern: /** This is a stateless utility class that groups useful foo-related operations, often with side effects. */ public class FooUtil { ...
1
vote
1answer
141 views

Is this database design good? What JPA Entities should I create for this design?

I am trying my hands on JPA. For this I am thinking of using the example of a student admission process as shown in the diagram below. Is this design good ? Any suggestions for improvement are ...
0
votes
1answer
59 views

Bootstrap licence free template

I´m creating a new website. For that I´m using a free bootstrap template. On top of my index page I have: A Design by W3layouts Author: W3layout Author URL: http://w3layouts.com License: ...
0
votes
1answer
108 views

Where would be better to handle an exception?

Imagine I have the following DAO method: public Employee getEmployeeById(Integer id){ NamedParameterJdbcTemplate jdbcTemplate = new NamedParameterJdbcTemplate(getJdbcTemplate()); String sql = ...
0
votes
0answers
5 views

Extract variable references in Javac [migrated]

I am developing a java program extends TreeScanner from com.sun.source.util. I am looking for sth like visitMethodInvocation, but for variable. I was wondering if there is a way to extract variable ...
0
votes
1answer
134 views

What kind of reputation does Java 8 have among “enterprise” companies? [closed]

Are the new, functionally-inspired features of Java 8 well-regarded within the enterprise development community? Have they been adopted by large companies? Have coding standards been updated to ...
2
votes
2answers
187 views

Is using generics to indicate some class/method is aware of a type good idea?

I'm going to use Java for code/idea demonstration. Imagine it's needed to define two interfaces: Observer and Observable (observer pattern). It's a good idea to have two generic interfaces, so there ...
21
votes
8answers
2k views

Is there a conventional way to combine file path strings?

In an example: var assets = "images/" var sounds = assets+"sounds/" Is it more conventional to put the slash on the back of a file path? var assets = "/images" var sounds = assets+"/sounds" Is ...
-1
votes
0answers
8 views

Change IntelliJ code construct symbols [migrated]

Is there a way to change the icons for symbols suchs the C for classes and the M methods. They're a little hard to distinguish on my laptop. Ideally I'd like to change it throughout the IDE but fine ...
1
vote
4answers
154 views

Adding values to HashMap

I want to add values to a HashMap, which would be used by methods in the same class. I have two solutions: Adding all the values with static When the first method is called, add the values ...
2
votes
4answers
129 views

Range of values based on key values

I'm trying to implement a method of searching trough a large amount of 2D points for those that match a certain range. I'm thinking of creating HashMaps for <X, Point> and <Y, Point> but ...
2
votes
1answer
106 views

How to access secure web services from a desktop application?

I'm writing a Java desktop application that will be available to the public. It will contact backend APIs via HTTPS using Jersey client. I don't know anything about using certificates in desktop apps ...
24
votes
9answers
3k views

What is different between the internal design of Java and C++ that lets C++ have multiple inheritance? [duplicate]

It's drilled into the newbie Java programmers that Java (pre-Java 8) has no multiple class inheritance, and only multiple interface inheritance, because otherwise you run into diamond inheritance ...
2
votes
3answers
182 views

Declaring lambdas in Java8

What would be the best practice to declare lambdas in Java8 code? How it was designed to be used? For example, let's say that we have a method that accept a Function. I want to provide function ...
0
votes
0answers
105 views

Java Ceil Weirdness [migrated]

Why does this output 0 instead of 1? System.out.println((int) (Math.ceil(1/2))); While this one correct outputs 1 System.out.println((int) (Math.ceil((double) 1/ (double) 2))); Shouldn't ...
0
votes
1answer
206 views

String[] args vs (String . . . args)

When programming for android, whenever I use an AsyncTask the doInBackground method looks like this. protected String doInBackground(String... args) But when using the arguments anywhere in that ...
-1
votes
0answers
62 views

Converting List of objects to an Array of Strings [migrated]

In my main class, I have: List<Person> allPeople = new ArrayList<>(); Then in the class I have a method which returns a String array of all the Id of people (Person has an accessor method ...
10
votes
1answer
343 views

Efficient way to represent hexagonal board logic for abalone-like games

I have to implement the AI for Abalone game and I'm wondering what is the best way to represent the board logic using Java without wasting too much resources in all checks and updates routines ...
6
votes
3answers
280 views

Design solution for communicating between multiple layers

We are developing a framework that has several layers and would be deployed in a multi-threaded environment. Each layer may have its own input/output data type. The top layer takes the input, performs ...
1
vote
1answer
61 views

excute Vs excuteOnExecutor [closed]

There are two ways to execute AsynTask, i.e., execute and executeOnExecutor. I already know that execute works serially and executeOnExecutor works in parallel. So my question is: Which one to use? ...
2
votes
3answers
87 views

Design a Queuing Solution with Clustering and Multiple Consumers

It is a Design Problem which I am listing out here. I have different set of business operations that are carried out for different business entities. Operations: Operation A Operation B Operation ...
1
vote
2answers
84 views

JUnit3 and JUnit4 in the same project (but different module)? [closed]

I have an Android project with a Gradle build. We've decided to commit to writing a vanilla Java implementation of our business logic (since we took care to keep that divorced form the Android ...
1
vote
2answers
113 views

Overriding methods by passing as argument the subclass object where the supertype is expected

I am just learning Java, and am not a practicing programmer. The book I am following says that when overriding a method, the argument types must be the same, but the return types can be ...
0
votes
1answer
48 views

Java Doc - Do fields also get documented?

This is a really simple question but oddly, I'm finding it difficult to get a definite answer.... What do you do with fields? Is this valid? /** * Keeps track of all usernames in the system. */ ...
0
votes
0answers
60 views

Best approach to save relationship mapping of country,state,city in orm

I am building a project in play framework java with jpa and I want set country,state,city dropdown fields in a form to be dynamic(from database).So only admin can increase or decrease the value of ...
0
votes
1answer
151 views

What'd be better? To add one more local variable, or to call a method twice in general case?

I have the method which returns java.util.Date inside the hibernate-entity class: package ua.com.winforce.loto_partner.commons.db.entity; @Entity @Table(schema = "pr", name = "publice") public class ...
2
votes
0answers
122 views

Object caching in this code too expensive?

I'm having some trouble with a game developed in Java which is kinda slow. I benchmarked it a little bit and found the problem: most of the time, the JVM is in the Object.<init>() since there ...
2
votes
2answers
235 views

Development on Android without using Java [closed]

As the title of this question suggests, I am looking forward to develop app(s) on Android platform without using Java at all. It doesn't mean I have some kind of vendetta against this beautiful ...
0
votes
0answers
36 views

Using a mock Spring bean

I m actually introducting to unit testing with Junit and I am wondering if I m doing the things right. In fact, I want to test a service in which I inject a repository (a Spring bean in my case with ...
1
vote
1answer
59 views

JSP without .jsp-files?

I have a little project (a CMS) that was developed using .jsp-files in 2006. I moved in 2011 to JSF and had only one .jsp-file for the frontend. In 2014 I integrated the backend into the frontend ...
-1
votes
1answer
152 views

What's the returning a value in Java?

public void warning(){ System.out.println("Watch out!"); } public void warning(){ System.out.println("Watch out!"); return; } We must use "return" statement with void methods. Bot ...
0
votes
1answer
57 views

Reflection performance in this iteration of a (probably) large excel file

I'm wondering the performance of reflection in this situation. I'm iterating a (probably) large excel file (let's say 3000 max) which it's going to be done from time to time, and the implementation ...
0
votes
2answers
43 views

Which 'InputStream' subtype is used by 'Socket' type object here?

In the below server socket program, byte stream object is used to read data from client, as mentioned - InputStream in = socket.getInputStream(); public class SingleThreadTCPServer{ ...
1
vote
1answer
55 views

Query on java I/O BufferedOutputStream write() method

Below is the code that is written using byte stream non-buffer class FileInputStream and FileOutputStream with the usage of explicit user buffers. public class FileCopyUserBuffer{ public static ...
0
votes
1answer
167 views

Shortest path to visit all nodes [duplicate]

I am given a set of tourist attractions(nodes identified by x, y) and i need to find the shortest path to visit them. The way i thought of it, is i will ignore if there are streets available and ...
3
votes
1answer
60 views

Template pattern with varying input type in overridden method

I am trying to use template pattern to define a generic algorithm in java. But the method that needs to be overridden, takes an object as input. This object will vary depending on the concrete ...
0
votes
1answer
143 views

Whats the difference between byte and Byte? [duplicate]

Alright so of course, I know the differences. byte is a primitive and Byte is an object. Byte offers more functions but there is one thing I dont understand. Why would anyone create a variable using ...
1
vote
1answer
163 views

Why is close() implemented in InputStream/OutputStream?

It make sense to see close() as non-core functionality of stream objects. This is the reason this method is placed in interface Closeable. One evidence is that class ByteArrayInputStream does not ...
1
vote
2answers
64 views

Query on hiding implementation details in java

With the below piece of thread related code, I see that author of Thread class is hiding the details about the working of start() method. What a user of Thread class need to know is, class Thread ...
0
votes
0answers
43 views

vert.x message bus architecture

A large part of the vert.x architecture is around the message bus, and message passing between verticals. The main idea I guess being that I can create multiple modules (possibly in multiple ...
-1
votes
2answers
91 views

Initialize in Field, Constructor, or Argument

If I know what a field will be initialized to, should I initialize it in the field, constructor, or receive it as a parameter? For example, where should I initialize an ArrayList? Initialized in ...
2
votes
2answers
262 views

Unit testing and reality [closed]

I m actually studying Unit testing, reading some articles on the internet and trying to understand how it works exactly, but it's not very clear for me actually. What should I test ? I have seen ...
0
votes
2answers
191 views

What design pattern for changing interface?

Sorry guys, I should have clarified the fact that the modified method is abstract in Father. Then if the method signature changes, all its implementations in SonX shall also change(at least the ...
2
votes
1answer
135 views

Why use a enum to create the singleton pattern [duplicate]

Why would you use an enum to create a singleton pattern? To what purpose would it serve over a conventional singleton pattern? I have seen the above used. The code uses an enum to create this pattern ...
2
votes
1answer
44 views

Applying initialization-on-demand holder idiom at variable level rather than class

I was looking for the idiomatic way to implement thread-safe lazy initialization for a configuration collection retrieved from the DB inside a Spring bean. I decided to adapt the ...
0
votes
1answer
79 views

Continuous Integration for different languages [closed]

So, I understand Continuous Integration in theory, and have used Beanstalk. However, I've been charged with creating the process at my current PHP shop. My hope was maybe PHPCI, since it looked ...
4
votes
2answers
232 views

Is it better to use strings or int to reference enums outside the java part of the system?

We were having a discussion at my work about the use of enums in Java. A coworker was arguing that when using enums on the server-side, whenever required we should use string to reference to it (for ...