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
82 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
32 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 ...
28
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
148 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
81 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 ...
-1
votes
1answer
56 views

Servlets and JSP begginer help [closed]

I Just finished learning java fundamentals.It took me three days just to configure Apache tomcat into eclipse.Though I am familiar with eclipse, the whole Apache tomcat Interface looks very Alien to ...
4
votes
1answer
99 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
1k 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
1answer
59 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
237 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 ...
0
votes
0answers
21 views

What is determinism in computer science? [migrated]

I was asked if my computer program (in Java) was deterministic. I'm wondering how could it be not? There is no such thing as a non-deterministic Java program right? Even if I use a random number ...
1
vote
1answer
50 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. ...
0
votes
0answers
11 views

Transparency of Pixel under mouse - Java JFrame [migrated]

I'm new to java and decided to make a program that : sets a point in the window when you left click. And then another point when you click again. And so on... Then it joins all the points up with ...
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
79 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
745 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 ...
-1
votes
0answers
36 views

How to retrofit a program using log4j to use logstash instead?

I have a legacy java program that uses log4j. I would like to use the centralization features that logstash provides. How can I do this without modifying the original program? I don't have any ...
3
votes
1answer
179 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
140 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
242 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
160 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
3k 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
290 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 ...
0
votes
0answers
45 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 ...
0
votes
0answers
29 views

Does the zero that follows the fractional second part of a Jodatime formatted Date changes its Comparable order? [migrated]

Given two strings: a) 2013-05-02 02:11:05.24 b) 2013-05-02 02:11:05.240 Does joda time interpret these two to have the same Comparable order ? i.e. they are equivalent.
0
votes
0answers
4 views

Return message to Android client from java Server via tcp sockets [migrated]

I am a beginner in Android with intermediate Java programming skills. I am also just learning socket communication. I am trying to make a very simple client/server connection. I have Android app as a ...
1
vote
2answers
154 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 ...
2
votes
3answers
107 views

Java logging dependency for a low-level library

I inherited a lower-level open source Java network library. The library is intended to be used by higher-level application protocol libraries which are in turn used by application code. My library, ...
1
vote
4answers
208 views

Use JSON objects or POJOs in back end service?

I'm building a back end service for mobile clients. The requirement is that the mobile clients will pass me a token, I'll use that token to talk to other systems (behind the company firewall) in my ...
-4
votes
0answers
52 views

Why 1 bytes has 8 bits? [duplicate]

Past time Latin language was used in computer for giving command ,Latin language has 256 characters,for represent 256 word 8 bits was used . 2^8=256 8 bits are enough for representing 256 character . ...
0
votes
0answers
72 views

Java - Get Interface Generic Type

I'm trying to create an Interface with Generics which allows me to get the type of object in the generics but no matter what I try there's a syntax error. I've tried the following 3 methods. All of ...
14
votes
4answers
1k views

How does one keep argument counts low and still keep third party dependencies separate?

I use a third party library. They pass me a POJO that, for our intents and purposes, is probably implemented like this: public class OurData { private String foo; private String bar; private ...
-1
votes
0answers
21 views

Best way to get data from database inside Thread Class in Spring [migrated]

Currently i am troubling that how to get data from database inside my thread class. I can't make bean of my thread class because new instance is created of thread on every request. MyThread.class ...
5
votes
2answers
451 views

When to fix something that is “wrong” but works fine

Short version: I wrote some code that is not done "the right way" because, when I wrote it, I didn't know how to do it. Now that I know how to do it "the right way", how do I decide how to fix it? ...
4
votes
2answers
254 views

Is it a good practice to burn business logic into Enums?

Let's have a simplified business logic like this: public enum BusinessLogic { STAGE_ONE(true, false, false), STAGE_TWO(true, true, false), STAGE_THREE(false, false, true); private final ...
0
votes
3answers
128 views

Should abstract classes be used to prevent instantiation

Is preventing the instantiation of a class a valid reason to make it abstract? For example, if I have a class called Gauge which has subclasses HeadingIndicator and AirSpeedIndicator, is it a good ...
-1
votes
1answer
92 views

How to identify http requests made from a closed-source java app?

I am an avid Go player and play on the Kiseido Go Server. I would like to write an open source client for this, but the KGS protocol is a well-kept secret. Is there any way to catch the http ...
0
votes
3answers
190 views

Why Double.parseDouble(“ABC”) not returns Double.NaN?

This code: Double.parseDouble("ABC") throws a NumberFormatException. Why is it wrong to expect a Double.NaN (NaN is literally Not-A-Number). A working example is this: public static void ...
6
votes
2answers
336 views

Small code, big test

I have this code in a controller of an MVC implementation: public void execute() { try { String path = userSelectsFile(); if ( path == null ) return; //Just returns ...
0
votes
0answers
79 views

Best practices for programmatic describing of behavior of complex input forms

We have a complex web form (we use GWT/GXT stack) with lots of input elements of different types (text fields, selects, checkboxes, buttons), and behavior of these elements depends on each other. Now ...
2
votes
5answers
733 views

Is it possible to make some methods invisible/non-usable to some classes in Java?

I am developing an application in Java whereby I would like to pass an object as part of an interface into other methods of classes written by other developers in the team. The object I'm passing in ...
1
vote
0answers
49 views

Java MVC: multiple use of the same event for different actions

I am working on a large Java project which employs the model-view-controller pattern. Should I use a different event for each action (to let the views communicate with their respective controllers)? ...
0
votes
1answer
44 views

Is there an established pattern for associating a database entry with a Java class that executes on that data?

I have a behavior tree with different leaf nodes that execute tasks. When building out the tree relationship in the database I need an association between the leaf node entry and the Java class that ...
0
votes
1answer
42 views

Architecture question about data migration

I'm facing a new enterprise project in Java about data migration. I did one of them in the past, now I want to do a better work and I think I need your considerations. So, let's me explain the ...
-3
votes
1answer
43 views

How should I change in get method without calling getList() of Deque? [closed]

import java.util.List; import java.util.ArrayList; public class Test { /** * @param args * @throws Exception */ public static void main(String[] args) throws Exception { ...
1
vote
2answers
128 views

Is it better to perform a calculation in the field's setter or have a different method?

I'm implementing a simple Quota object which determines a usage percentage based on the maximum and the used. private int maximum; private int used; public Quota(int used, int maximum) { ...
0
votes
1answer
106 views

Enum as singleton or fully functional class [duplicate]

Joshua Bloch claims that "a single-element enumeration type is the best way to implement a singleton" Why? I totally disagree with this statement because enumeration is data type with some ...
0
votes
1answer
113 views

Should I use one class that calls Several static methods or several classes each calling one static method

I need to use instances which represent mathematical functions along with their parameters end enable their evaluation. I can take 2 approaches: 1: have a single class representing all the math ...
1
vote
0answers
36 views

Individual methods or parameters for Google Analytics abstraction on Android

A coworker and I are having a discussion around the best way to build our abstraction on top of Google Analytics for an Android application. A couple of data points. We have auto-tracking enabled ...
-4
votes
1answer
123 views

it is possible to implement keyloggers in java [closed]

I am researching on keyloggers and as a part of my research I would like to know if its possible to implement keyloggers in java edit * How can i create a keylogger in java or to be precise what ...