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
62 views

Lock object in base class: private or protected? [closed]

I have a base class that contains some lists, queues, and other fields which determine its state. In the base class I only access these fields within a protected lock object since there could be ...
-1
votes
3answers
166 views

How to design a solution that needs dynamism using Inheritance [closed]

I have below code/classes/interfaces: An Interface: public interface Animal<A extends Animal<A>>{ void fight(A otherAnimal); } 2.Tiger class which is implementing Animal ...
0
votes
1answer
54 views

How is ServletContext created?

When the webapp gets loaded the container will create the ServletContext. There is only one ServletContext per webapp per JVM. The ServletContext object is contained within the ServletConfig ...
1
vote
1answer
153 views

Problems with OO design for application with pluggable components

I'm trying to refactor an ugly code and make it easly extendable in the future. The application should be nothing else but a series of components that have input(s) and output(s). The components ...
0
votes
1answer
71 views

Return values and exceptions [closed]

I wrote simple function that returns a string depending on which condition is TRUE. Here is my code: private String getMyString() { if(!mStrigMember.isEmpty()) { return mStrigMember; ...
1
vote
4answers
175 views

What is the proper way for these methods to function?

How can I properly design what a method or function should do? To clarify the question I am going to use an example from a simple (non GUI) hangman game I created. The design is simple, it has a ...
0
votes
0answers
70 views

Is there any necessity to pass a variable parameter to a method while the variable declared global? [duplicate]

I am writing a class in java of Monte-Carlo algorithm. Here is the written code - public class MonteCarlo { int[][] matrix; public void monteCarlo(List<Node> nodeList) { matrix ...
2
votes
5answers
196 views

Implement multiple separate interfaces or interface hierarchy

I've been refactoring one of my projects recently and ran into a decision I have to make. I have several interfaces: Entity: Something in the game world Actor: An Entity that can perform actions ...
0
votes
3answers
211 views

Why are there no java compiler alternatives to allow new functionality? [closed]

For example, a new java compiler could allow for some breaking backwards compatibility to allow for things like overloading on generic types like: void foo(List<String> arr); void ...
11
votes
2answers
631 views

Java has the JVM, what does C have?

I know that C has a compiler but what determines execution performance? For example in an if else block, what if the code just had all ifs instead of if elses, what determines that all the ifs will ...
2
votes
2answers
217 views

When to use a SortedMap interface?

The rule in programming is to use the most general interface possible. But the difference between Map and SortedMap is more subtle. They compile to the same bytecode [I think] No additional safety ...
1
vote
2answers
111 views

Caveats of using String.hashCode() on a switch on java < 1.7

There are several cases when I want to switch over a String input. I decided for implementing something like: public Object doStuff(String param) { switch (param.hashCode()) { case 1234546: ...
1
vote
2answers
152 views

My value checker function needs to return both a boolean and a message

I have a value checking function, something much like a credit card number checking function, that is passed in a string, and needs to check that the value is of the right format. If it's the right ...
9
votes
7answers
2k views

Does Oracle reap economic benefits by maintaining Java? [closed]

It occurred to me that many programming languages such as Python and Javascript are maintained by non-profit foundations. I can see why a foundation would update a free programming language- in order ...
1
vote
2answers
98 views

Adding Logging to a pre-existing Program

I have a game that I have been writing in java as a hobby for a number of years. I have very sparse logging, just some simple output when something goes really wrong. It's about 25,000 lines of code. ...
4
votes
2answers
214 views

Exception versus return code in DAO pattern

After reading a lot about the abusive use of exceptions in Java and how you should let an exception bubble up through the different layers of an application, I've come to a point where I don't know ...
2
votes
1answer
75 views

Transactions and subresources with JAX-RS

I'm porting an existing application RESTful API to a Java web framework -- I don't actually care which -- but it's proving hard to get the basics right. The core of the problem appears to be getting ...
7
votes
2answers
246 views

Retry design for high volume

I have a Java system using ActiveMQ for messaging. And the system processes about 400 to 600 transactions a second and we have no issue when everything is running smoothly. The system also got to send ...
0
votes
1answer
70 views

Pattern for separating UI code from logic in Wicket

I'm using Apache Wicket for developing web apps, I have developed a few for the last year and it has been great; today I was looking at a few pages and most of them look like this: public class ...
1
vote
0answers
42 views

Enforce coding decision to include or exclude an Enum element in an EnumSet at compile time

I would like to enforce that the elements of a Java Enum are chosen or excluded from an EnumSet at compile time i.e. I am forced to make the decision to put it in the set or not whenever I create a ...
1
vote
2answers
122 views

Is it a good idea to require passwords in offline applications?

I am developing an application which can install extension modules (plugins, if you will) from APT-style repositories hosted elsewhere. The plugins need not be signed (although the downloads are ...
1
vote
2answers
164 views

Smells in exception handling: how to separate between public and internal exceptions?

During the development of a small web API, we decided to separate internal exceptions from public exceptions. Public exceptions are HTTP exceptions, that translate into HTTP responses with proper ...
1
vote
0answers
26 views

do my “dal” and “fileHandler” interfaces overlap?

I want my program to: 1) read some input lines from csv file 2) write the output lines to plain string file 3) read some input from the same file in (2) and compare it to some calculated data. I ...
1
vote
0answers
111 views

Optimal data structure for binary data/Java

I have several input formats mostly restricted to geotiff and some proprietary binary formats. I import them into my program and then need to export them into various other data formats (also binary) ...
0
votes
1answer
116 views

advantage of having multiple REST web services

I have a application designed using Spring REST service. the application has two REST projects: Web Core Web has html, JavaScript and Java classes (ajax calls this REST). These Java classes in ...
0
votes
2answers
64 views

Handling DomainExceptions using REST endpoint

Suppose I'm doing some DDD. Now, I have a microservice reflecting a bounded context/a part of a bounded context. Now, suppose there is a REST endpoint: '/somedomainmodel/someaction' My API user is ...
1
vote
0answers
88 views

How and where to make global function file in jsp sevlet web application

I am making a website in Servlet&JSP. I am looking for good way to make a specific function file from where I can call and declare my common functions. If I made a java file function. Java, so is ...
4
votes
1answer
166 views

What are the reasons for sealing a .jar and how would I verify that?

I have created a sealed jar, but I don't see difference compared to using a non-sealed one. What tests I can perform to verify the jar is sealed? What reason we could have to prefer using a sealed ...
0
votes
1answer
96 views

Possible way to make java class builder more abstract by using interface required keys

I'm looking for a more abstract pattern for builders that handles required fields without the need of writing a validator that checks if all requried fields are set. I like this builder. But is ...
0
votes
1answer
85 views

Is set of libraries called API only if it talks to a system/server?

I have read few articles about API. Can't find the reference now. In some of them, they define API as set of tools, routines and protocols which are helping programmer to build a software with use of ...
0
votes
1answer
80 views

best way to export binary data with additional text attributes to a stream

I would like to create a command line API in a Java application to export a binary blob to stdout. I would additionally like to export certain attributes about the blob, ideally in a non-binary ...
29
votes
8answers
4k views

Is throwing an exception an anti-pattern here?

I just had a discussion over a design choice after a code review. I wonder what your opinions are. There's this Preferences class, which is a bucket for key-value pairs. Null values are legal ...
2
votes
3answers
159 views

What is the difference between a variable and a parameter? [closed]

Its a conceptual question. But I would like to use the right term at the right place. That is why I would like to read some other views on this.
-4
votes
1answer
102 views

Why java has so many frameworks [closed]

why java has so many frameworks? why core java is not sufficient enough to solve the problem or develop anything? Even if core java is insufficient enough that we need frameworks,why there are ...
4
votes
1answer
106 views

How would I isolate changes to mutable state if I need to run two queries to get the final result?

I'm working on some code that takes search criteria from a Rest API and uses it to query a remote API to return results. As an exercise, I wanted to try to separate all state changes to one place, as ...
-1
votes
5answers
2k views

Why Java is a factor 2-3 slower than equivalent C++ program? [closed]

I know there is an opinion that programs written in Java and running under JVM as as fast as C++ programs, after introducing just-in-time (JIT). I see many cases when Java is terribly slow for simple ...
0
votes
2answers
103 views

How to write a new annotation that behaves precisely like an existing one?

Here is my use case. Suppose annotations did have inheritance and would automatically inherit the entire behaviour of the base class. Then I would do the following (note the two package statements): ...
0
votes
2answers
260 views

What is the rule for nested loop code?

I am new to programming and currently learning Java from Stanford free learning course. There was this assignment that I had trouble translating my algorithm into code. I feel like I have a ...
1
vote
1answer
74 views

Language support for (syntactic) delegation in Java

Composition over inheritance is an old trend or even accepted state of the art in object oriented programming. It would be even easier to use in Java, if there were language support for delegation. ...
17
votes
7answers
3k views

Why is instance creation the way it is?

I've learned C# over the course of the past six months or so and am now delving into Java. My question is about instance creation (in either language, really) and it's more of: I wonder why they did ...
1
vote
1answer
107 views

Open closed principle vs abstraction leaking (Java enums)

In Java, an enum is not a plain replacement for a number (like in C/C++), but a family of objects which can have properties. For instance public enum Order { NAME("Ordering by name"), ...
12
votes
4answers
845 views

“Use map instead of class to represent data” -Rich Hickey

In this video by Rich Hickey, the Clojure creator, he advises to use map to represent data instead of using a class to represent it, as done in Java. I don't understand how it can be better, since how ...
3
votes
1answer
266 views

How should I annotate, that a class is immutable in Java?

I recently stumbled upon how useful immutable objects are and that e.g. if you pass elements to a constructor and your class should be immutable, you have to copy these elements if they are not ...
3
votes
1answer
204 views

Does the JVM's Garbage Collector clean the entire JVM HotSpot memory (C-Heap, Java Heap and Permanent Generation space) or just Java Heap?

I know that the JVM has some JVM HotSpot memory which is further divided into three areas: Java Heap Permanent Generation Space Native Heap (C-Heap) I know that Java has automatic garbage ...
3
votes
2answers
282 views

Do wildcards in Java generics restrict or increase flexibility?

I have read many sources about wildcards and Java generics. Even though I have seen many explanations and answers, none of them seems correct. The question is very simple: Do wilcards in Java ...
1
vote
1answer
209 views

Most efficient way of searching very large strings of text in java

I have a question that I have been thinking about recently but I am still not sure of the answer(s) so I would like a broader opinion. Imagine the scenario where text strings of up to lets say ...
23
votes
4answers
4k views

Why doesn't Java have optimization for tail-recursion at all?

From what I have read: The reason is because it is not easy to determine which method will actually be called as we have inheritance. However, why doesn't Java at least have tail-recursion ...
0
votes
3answers
385 views

Overriding equals() method in Java

Short question: Why does Java allow overriding equals(), why is it not final? I am reading Effective Java 2nd edition by Joshua Bloch. I am a bit baffled by the conclusion that There is no way to ...
1
vote
0answers
55 views

Multiple 1024x1024 texture pages or one 2048x2048 texture page?

I have a lot of textures around the size of 512x512, and the LibGDX texture packer can't find a way to put more than one of those on one page for some reason. So, I end up with fifteen or sixteen ...
1
vote
2answers
182 views

Why can we use the same name for local variable in different scopes?

I was wondering why is it possible that we can use the same name for local variable in different scopes? Like we can have two methods which both can have variable with the same name. What makes ...