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
2answers
181 views

Why 'class String' definition has 'final' modifier? [duplicate]

This answer gives an indication that class String is declared final for thread safety, which does not convince. This answer does not convince when it says: And so, you make the classes final. There ...
32
votes
6answers
4k views

What's the point of implementing a Stack using two queues?

I have the following homework question: Implement the stack methods push(x) and pop() using two queues. This seems odd to me because: A Stack is a (LIFO) queue I don't see why you would need ...
1
vote
2answers
85 views

Dependency injection of ViewModel with unmanaged parameter

I have a PersonEditViewModel which needs two other objects, the personId and the PersonRepository. PersonRepository is obtained from a service locator: private final int personId; public ...
1
vote
3answers
70 views

When is a event listener invoked during program execution?

I am using the Obervable-Observer Pattern. MyClass extends Observable{ invokeListeners(){ doSomething; setChanged(); notifyListeners();//This invokes onUpdate() in "implements ...
0
votes
0answers
21 views

WebService NameSpace doubt

I am creating a java webservice. For that I am using @WebService annotation and @WebMethod for defining endpoint and service respectively. In both place I have option to provide targetNameSpace. Can ...
1
vote
1answer
89 views

If the representation part of type abstraction is declared private, then how does sub-classing violate encapsulation?

Here, I learned that sub-classing violates encapsulation: it violates encapsulation, since the implementations of the superclass and subclass become tightly coupled For instance, If we consider ...
0
votes
1answer
85 views

How to decompose Monolithic applications into Microservices with interdependent functional modules?

I work with a large monolithic web application that has between 12-24 functional modules and these are all maintained inside a single war project structure. While the code itself is already segmented ...
2
votes
1answer
134 views

Difference between Consumer/Producer and Observer/Observable

I am working on the design of an application that consists of three parts: a single thread that watches for certain events happening (file creation, external requests etc.) N worker threads that ...
0
votes
1answer
47 views

Graphs and minimum spanning trees?

I am having a hard time finding information on how Graphs and spanning tree's work and how to construct/structure them. The reason is that I'm using a Delaunay Triangulation algorithm within the ...
1
vote
4answers
95 views

Best way to handle blank dates

I'm trying to create a contact book application, and currently I'm working on a class called Person. One of the fields of person is dateOfBirth, however I don't know how to handle unknown dates. Until ...
3
votes
2answers
132 views

Is it still a good practice to log parameters and returns?

Just a context, I am currently making a base code for a Java Spring Boot Application. I am currently setting up the logging of the application and I stumbled upong this url and found it helpful. ...
0
votes
0answers
47 views

What exactly meant exactly by “to sort a stack in ascending order”?

There is an assumption made in solutions to this problem: Sort a stack in ascending order. The non-recursive solution looks like this: public static StackWithMin<Integer> ...
0
votes
0answers
28 views

synchronized procesing of queued objects [migrated]

I have a queue, where new objects are inserted and processed. For processing I use singleton thread that can end and can be restarted. private Thread backgroundThread; private final ...
0
votes
0answers
42 views

MVC architecture with JavaFX

I am working on a rather small Java application for a university project. We are forced to use a pretty strange interpretation of the MVC pattern which says that we should only have one generic ...
5
votes
2answers
337 views

How many threads is too many to maintain a chat server?

I'm writing a chat server and client. For the chat server I have 3 "services" all running on their own threads: ConnectionListener that loops over accept, and adds any new clients to a ...
2
votes
0answers
74 views

Architecture design for Java servlet that triggers work (for sending push notifications)

I'm designing a push notification server (for pushing notification via APNS and Google servers) and have come up with the following design for a Java based web application server. I would really like ...
0
votes
1answer
87 views

Java Serialization - Variables Visible in Text Editor

When I serialize my class and save it as a custom file extension, some of the variables and imports are visible when you open the file in a text editor. Is there a way to avoid this or is there an ...
1
vote
1answer
188 views

Why would we need to rollback twice before closing in a finally block?

I'm trying to implement the change in database connection closing suggested in this question's answers. More than once, I've come across this block of code at the end of my try blocks: try { ...
-1
votes
0answers
6 views

Drawing works fine with glDrawArrays, but is failing using glDrawElements [migrated]

My shader works fine, and I can draw with glDrawArrays, but am having a hard time getting glDrawElements to work. I've added comments to where lwjgl function calls are different than standard openGL. ...
1
vote
3answers
90 views

Can multiple synchronized methods in same object run concurrently

As far as i know when there are multiple synchronized methods(both static and instance) in a class, java allows only one such method to run at a time. But what if a thread acquires lock on an object ...
0
votes
0answers
35 views

Class design for Token, TokenType and regex constants

For use in a lexer class a have a class Token which represents a token of a specific type and its value, while the types are defined by the enum TokenType in which every token holds its own regular ...
2
votes
1answer
70 views

Is there a way to make the default way a class is accessed a field within the class?

I'm trying to write a wrapper for the following bit of scala code: val vertBuffer: FloatBuffer = createFloatBuffer(vertex_positions.length) vertBuffer.put(vertex_positions) vertBuffer.flip() ...
22
votes
3answers
3k views

Are “plus” and “minus” appropriate method names?

Java SE 8 comes with a new mechanism for dates, introducing LocalDate, LocalTime and LocalDateTime classes to represent instants of time. To manipulate such instants, a set of methods are given: ...
-1
votes
1answer
66 views

How to name methods where one takes a single object as input and one takes multiple? [closed]

I have two methods in my class: public String widgetToHtml(Widget widget){...} and public String widgetsToHtml(List <Widget> widgets){ for(Widget widget : widgets){ ...
0
votes
2answers
208 views

Way to organize repetitive text in Java

Some times I have texts that appears in different places, like comments, messages... For example if I have a custom Exception, probably class doc, messages that passes as parameter to its constructor ...
-3
votes
0answers
48 views

Java for non computer devices [duplicate]

hello all there is an old saying that java is actually developed to run on different devices like VCR, AC etc. then my confusion is if they do so where they compile there code to run on different ...
0
votes
0answers
38 views

Java platform vs Source/Binary format settings in Netbeans

I've just wanted to get to know what these particular settings really do: Project Properties -> Libraries -> Java Platform Project Properties -> Sources -> Source/Binary Format After a little bit ...
1
vote
0answers
71 views

MVC question for a console application with multiple controllers?

My question concerns an administrator's console application. The requirements around it are that administrators should be able to log in (other types of user cannot), and they should then be able to ...
1
vote
0answers
37 views

Sliding Collision Detection (Java) [migrated]

I need a really specific kind of square collision in my game. In it, if a square entity moves into, say, a vertical wall from the left, the entity is set to the left of the wall, but any vertical ...
4
votes
1answer
108 views

Do java .class files have a lexer/parser?

I've been learning ANTLR, by writing my own (extremely simple!) programming language It made me curious about how the lexer/parser/AST is implemented for java. Obviously there is a grammar for .java ...
0
votes
2answers
236 views

Parameters are passed by value, but editing them will edit the actual object (like passed by reference)? [duplicate]

I've just discovered a huge whole in my Java knowledge. I knew that Java passes parameters by value. I thought I understand that and whenever I needed to edit the field object of a class, I create a ...
4
votes
4answers
120 views

Testing concurrency/thread-safety

A program I have wrote uses multiple threads and I believe my program is thread-safe but how can I really know? I've read a number of examples online and none of them describe how to test the code is ...
0
votes
0answers
39 views

Tomcat Backend & Java Desktop Client

I want to setup a Tomcat server that performs unattended automated tasks. It will have a Web Service to allow access to some of its functions/methods, such as updating its configuration, which are ...
0
votes
0answers
24 views

Tomcat & Apache(PHP) HTTPD - integration limitations

I started developing an application using PHP/HTML/CSS/JQuery/SQL and after a few months of development I discovered that some automation would be required. The level of automation that is required ...
1
vote
1answer
45 views

Should heavy initialization be stored as a static variable or instance variable?

I have a that class does not really specify any real object on its own but is more of a utility class. It has some data whose initialization is expensive. I see two options on how to store the data: ...
1
vote
1answer
76 views

How do Java AOT compilers work?

There are a few number of tools out there (Excelsior JET, etc.) that claim to transform Java app's into native executables (*.exe). However it is my understanding that these tools are really just ...
7
votes
3answers
1k views

Is there an issue with closing our database connections in the “Finally” block of a Try statement?

I'm doing some refactoring for our application, and trying to reduce the number of issues reported in our ISO Scan (a static code analysis tool based on HP Fortify). Right now, what I'm trying to ...
5
votes
1answer
246 views

In Java, why does (unsorted) Set implement Iterable, but SortedMap does not?

There are two aspects to this question that I felt were too closely related to ask as separate questions. Why doesn't SortedMap implement Iterable<Map.Entry<K,V>>? If you need to ...
0
votes
2answers
62 views

Round amounts internationalized

Rounding amounts in Germany we must use Math.round instead of Math.floor. The rule is called "Kaufmännisches Runden" Is there any rounding-function for amounts who accepts the Locale in Java? ...
0
votes
0answers
57 views

How to refactor bad Java modules into Java or NodeJS [duplicate]

A programmer, I have 5 years working experience with Java/JEE, with the following skill sets: - I have excellent knowledge about testing - I am not so good in Java (still don't know why, after ...
1
vote
1answer
23 views

Advantage of non-deterministic staistical analysis?

I am working with a Java Library used for identifying the language of a given text. It relies on an n-gram analysis of the text to return a set of languages it might be and the "confidence" that it ...
1
vote
2answers
125 views

One Enum vs Multiple Enums

I am developing an application where a user submits a mission and other users accept the mission. Pretty simple. I want to keep a track of the mission progress status and store it into a database. ...
0
votes
0answers
16 views

One Enum vs Multiple Enums [duplicate]

I am developing an application where a user submits a mission and other users accept the mission. Pretty simple. I want to keep a track of the mission progress status and store it into a database. ...
2
votes
1answer
43 views

Best practice for allowing mutation of a Collection type field

Suppose I have a (DTO style) class with a field that is a list: public class MyClass { private List<String> stuff = new LinkedList<>(); } There are a few choices to allow mutation ...
-1
votes
2answers
87 views

Personalization of code: Personalized debugging message, personalized strings and project tags [closed]

I was given a code review today by a coworker. 1) I'm told not to use personalized tags to aid in searching for important portions of the code. For example: Personalized Strings, for example ...
11
votes
3answers
720 views

Unit Testing Competition

My employers runs a monthly unit testing day competition. One entire day is dedicated to writing unit tests -- obviously we do more testing throughout the month, but this is an entire day -- and the ...
8
votes
8answers
1k views

What stops C from being compiled/interpreted/JIT'ed?

Java is often praised for its amazing portability, which I presume is because of the JVM. My question is what stops C from being being compiled/interpreted/JIT'ed.., if so, C can also be write once ...
1
vote
2answers
157 views

Is there a hashCode()-like method that can be used for state checking?

I thought up a simple and efficient way to combine states with events to make event handling more efficient. My idea of state checking involves State objects that hold reference to mutable variables ...
1
vote
2answers
102 views

distinguish requests from the same vehicle

I am implementing an small app to track buses based on Crowdsorcing. The riders send data long, lat, mac, route to the server as JSON string. In my database I have table bus to insert the transmitted ...
1
vote
1answer
73 views

Method documents differs between Java docs and Android docs

Some times I see problematic differences between Java doc and Android doc in about method documents.For example in about setReadable (boolean readable, boolean ownerOnly) method you can see java doc ...