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

5
votes
2answers
204 views

Does sun.misc.Unsafe give access to the system or just the JVM?

Please note: Although this question involves microcontrollers, it is at its core, a Java question, and so I believe it can be answered by any battle-weary Java guru. I stumbled accross this blog ...
1
vote
0answers
68 views

Will using a pure MQTT approach be the right decision?

I plan to provide additional functions for a closed-source 3rd party point of sales application. That application is used in restaurants, is run on Windows and uses dbase style databases. I know the ...
60
votes
9answers
10k views

How do you avoid getters and setters?

I'm having something of a hard time with designing classes in an oo way. I've read that objects expose their behavior, not their data; therefore, rather than using getter/setters to modify data, the ...
3
votes
3answers
165 views

Design suggestions for converters in Java

I'm trying a set of converters which will convert an object to some older form. And there are different objects which are converted. By older form I mean changing the values of some fields and in case ...
6
votes
3answers
247 views

Advantage/Disadvantage of having all variables declared in a JUnit Test

I've been writing some unit tests for some new code at work, and sent it off for a code review. One of my co-workers made a comment about why I was putting variables that are used in a number of those ...
15
votes
2answers
2k views

Declaring a class final? [duplicate]

I like my code to be written well; however, I have run into not really an problem, but more of a question about conventions. Say I have this class. public class Test { public void doStuff() { ...
0
votes
0answers
45 views

Run fat jar as a service on Amazon Linux EC2 instance using Ansible

I want to deploy a Ninja app to an EC2 Amazon Linux instance using Ansible. Being a Linux noob and completely new to Ansible, I wonder what the best way would be to start the app via Ansible as a ...
0
votes
1answer
43 views

Java: Weighted Selection help [closed]

I have this code that randomly selects a item from a enum. Each of the enum items have a integer weight to it. The higher that weight is, the higher chance that item has of being picked. Here's what ...
0
votes
1answer
178 views

I need a data structure for a card game

I am programming a card game in java, and unsure what data structure I should use for the player's hand. I considered using an array, with one integer to traverse the array and another integer to ...
3
votes
1answer
156 views

What is the motivation behind the @ImplementedBy annotation in Guice?

I recently read about the @ImplementedBy annotation available in Google Guice. It allows the programmer to specify a binding between an interface and its implementation for future use in dependency ...
0
votes
3answers
247 views

What arguments are there to use a coding style for each distinct language? [duplicate]

I recently had a discussion about our coding style for C# projects. Two things in particular were very hard to agree upon. Method Naming C# has the de-facto standard of naming (at least public, ...
2
votes
1answer
132 views

Does the LGPL apply if I rewrite a portion of JasperReports in C++?

I would like to rewrite a portion of the JasperReports library in C++. The library will read from the same XML format used by JasperReports. If I integrate this C++ library to my proprietary ...
0
votes
1answer
99 views

Should a comparison method ever return the same type back as it's comparing?

First, this is homework, but no, I'm not asking for anyone to do any code for me. My course start date isn't for another month (it's online), so I can't ask for clarification. I thought I'd see if ...
0
votes
1answer
125 views

Changing the Garbage Collector on your JVM [closed]

My understanding is that the JVM specification only defines the behavior of a garbage collector, but does not provide implementation details. This means it is up to the JVM implementation to build the ...
2
votes
0answers
98 views

Cross-compiling Java app to run directly on ARM

Please note: although I am using ARM SAM3X8E in this example, I'm just using that as a concrete example, and the answer to this question could easily be given using any other MCU such as AVR, etc. I ...
2
votes
0answers
44 views

Embedded tomcat cold deployment without service disruption

I have the following scenario. For various reasons I chose to use embedded tomcat for my rest backend that will form a cluster of AWS machines. I will want to deploy fairly frequently updates ...
0
votes
2answers
134 views

What is the best type to represent a number in java and why? [closed]

I am developing a dynamically typed, interpreted programming language, which is interpreted by a runtime written in Java. As Java is statically typed, I need to define how the numbers used in the ...
3
votes
1answer
83 views

Do I need a web-service for this case? Data-synchronization over multiple clients

I'm new in this area and a little bit confused about my current thoughts on a web-service implementation for my application. I want to synchronize all connected clients with the current data on a ...
1
vote
1answer
70 views

role based access control model in object oriented

I want to prepare a swing application. I am designing a role based access control model in mvc design. When a view wants to request something from a controller, how can this request be realized in ...
1
vote
1answer
120 views

Java partial enum backed by the database

I have following problem: need to use enum in my java code, since I'll have to ask in my business logic things like if(someting == enumname.VALUE_ENUM){... but I don't have all the enum types at the ...
9
votes
6answers
438 views

Does it always make sense to “program to an interface” in Java?

I've seen the discussion at this question regarding how a class that implements from an interface would be instantiated. In my case, I'm writing a very small program in Java that uses an instance of ...
3
votes
1answer
126 views

What was the date of the Java Alpha and Beta releases

The date of the public 1.0 release of Java is easy to find: January 23, 1996. But there were public Alpha and Beta releases before that, and in December 1995 Java already appeared on the list of Time ...
4
votes
1answer
239 views

Is Collection.stream().filter().forEach() inefficient compared to a standard for each loop?

IntelliJ IDEA recommended to me just now to replace the following for-each loop with a Java 8 "forEach" call: for (Object o : objects) { if (o instanceof SomeObject) { ...
0
votes
0answers
24 views

Classes, Datatypes and replicating Methods [duplicate]

I've gone from writing code procedural-style to object-oriented recently and during my development as an object-orientated programmer I have made a few mistakes. What I have been doing is, inside my ...
12
votes
2answers
627 views

Java: why do collections accept a Comparator but not (a hypothetical) Hasher and Equator?

This issue is most apparent when you have different implementations of an interface, and for the purposes of a particular collection you only care about the interface-level view of the objects. For ...
26
votes
4answers
3k views

Why is .compareTo() in an interface while .equals() is in a class in Java?

I want to know why the .compareTo() is in the Comparable interface while a method like .equals is in the Object class. To me, it seems arbitrary why a method like .compareTo() is not in the Object ...
3
votes
2answers
148 views

Best strategy to find the root cause when exception is swallowed by 3rd party

I am sure we have all run into a scenario where a 3rd part API complains with an incomplete stack trace. In essence the error handling in the 3rd party API does something like this, catch ...
0
votes
1answer
51 views

Is there any reason not to allow negative numbers to be entered into a JSP field labeled for positive numbers?

Our application, a fairly complicated money ledger, has a JSP field for entering a certain type of money due, balanced by payments made towards that amount due. In the application, this field is ...
1
vote
2answers
31 views

Application model management questions

Consider the following type of Java / Spring web application, with an SQL database: there are multiple data entity types (about 100) with relations between them the entities are viewed, edited or ...
-3
votes
1answer
39 views

Connecting to MySQL with JDBC through Network

I have a desktop application that access the mysql database through Local Area Network. Do i need to install xampp mysql on client computer in order to access mysql database on another computer?
4
votes
4answers
337 views

Legitimate cases of having .equals() behaving inconsistently with .compareTo()?

Java documentation says it's "strongly recommended" to have them behaving consistently. But are there legitimate cases of java/c#/python/etc Object.equals() method behaving inconsistently with the ...
-2
votes
1answer
41 views

ClickHandler for button = strategy pattern? [closed]

If you provide a implementation of a ClickHandler interface to a button (defining some behaviour), is this the strategy design pattern?
1
vote
1answer
120 views

How to concurrently write data in Java without locking?

How to implement a multi-threaded program in which each thread needs to write/output some data (in any order of course) but without the locking overhead that is involved with files or a particular ...
4
votes
3answers
499 views

How to open a desktop application through browser without a Java applet?

We run a cloud-based medical software, and a very important part of the program is bridging to an imaging software straight from our website, passing information through command line arguments. We ...
0
votes
2answers
138 views

Check if a variable is equal to any of several values

I'm trying to check if an integer is equal to any of several values and don't want to do this: int d = 0; if(d == 3 || d == 8 || d == 1) { System.out.println("d is one of the special numbers!"); ...
1
vote
2answers
105 views

Should method names getX and setX only be used for fields and have no other effects? [duplicate]

Should I avoid using getX() and setX() as names for methods that aren't "traditional" getters or setters? (Let's define traditional as it only gets/sets the field and has no other effects.) I guess ...
2
votes
3answers
255 views

Using System.err.println() for debugging in Java

System.err The "standard" error output stream. This stream is already open and ready to accept output data. Typically this stream corresponds to display output or another output ...
30
votes
10answers
4k views

Is it okay to have objects that cast themselves, even if it pollutes the API of their subclasses?

I have a base class, Base. It has two subclasses, Sub1 and Sub2. Each subclass has some additional methods. For example, Sub1 has Sandwich makeASandwich(Ingredients... ingredients), and Sub2 has ...
3
votes
2answers
239 views

Why are the types in Java considered less 'strong' than haskell?

I asked this question a while ago - the answers were really helpful, and as I read them and the questions that were linked - I also saw this, and the first answer I think really addresses what I ...
29
votes
7answers
3k views

Should I validate a method call's return value even if I know that the method can't return bad input?

I'm wondering if I should defend against a method call's return value by validating that they meet my expectations even if I know that the method I'm calling will meet such expectations. GIVEN User ...
19
votes
4answers
3k views

How much refactoring is acceptable? [duplicate]

I am currently in a project where one of my developer colleagues constantly refactors stuff on every ticket he's doing. We are using agile methodologies. I know that refactoring is a good thing to do ...
18
votes
5answers
2k views

If Scala runs on the JVM, how can Scala do things that Java seemingly cannot? [duplicate]

I just learned about Scala yesterday, and I'd like to learn more about it. One thing that came to mind, however, from reading the Scala website is that if Scala runs on the JVM, then how is it ...
2
votes
1answer
51 views

Keeping lists of Objects, some with, some without inheritance

Let's say I have two classes, Foo and ExtendedFoo where ExtendedFoo inherits from Foo. Foo has a method .getValue() which returns a number, ExtendedFoo also has .increaseValue() which adds to the ...
4
votes
3answers
244 views

Automatic builders/chain setters for Java?

Consider that code: FancyClass c = new FancyClass(); s.setParameter(value); s.setParameter2(value2); //a lot of parameters It is really naive, so we can use a builder pattern: FancyClass c = new ...
-2
votes
2answers
155 views

Is this a good game plan to become a fluent Java developer? [closed]

I am an efficient person, and I am trying to find the best method of becoming a great Java developer. Here's what I'm thinking: First, learn syntax and Object Oriented concepts. Practice it, and ...
0
votes
1answer
291 views

Java front-end, PHP/MySQL back end methodology

I have been basically out of the programming world for about 10 years, with only a bit of dabbling here and there with small Java utilities and one large Access database I wrote for someone, and some ...
4
votes
4answers
771 views

Should I edit a codebase's whitespace to conform to a coding style? [duplicate]

We have a large Java project (1m+ SLOC) with mixed whitespace - some files have tabs and some have spaces. It's tricky to make my editor work with whichever file I happen to be editing. We are ...
0
votes
1answer
115 views

Access fields of super class from derived classes [duplicate]

There is an abstract BaseGame class that will be inherited by specific game classes. This class has an attribute requestHandler that will be used in all subclasses and should be initialized in the ...
2
votes
0answers
61 views

Conventions for revision control with Maven/Jenkins

For a software project I am working on, we have a 'dev => QA => production' methodology. That is, we create a release candidate (deployed to Artifactory), give it to QA (deploy to QA systems and a QA ...
14
votes
5answers
1k views

Why does the TRACE level exists, and when should I use it rather than DEBUG?

In Log4J, Slf4J and a couple other logging frameworks in Java, you have two "developper" level for logging. DEBUG TRACE I understand what DEBUG do, because the explanation is clear. The ...