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.
12
votes
11answers
14k views
+50
Best way to handle nulls in Java?
I have some code that is failing because of NullPointerException. A method is being called on the object where the object does not exist.
However, this led me to think about the best way to fix ...
-2
votes
0answers
44 views
Any tips for overcoming code quality obsession? [on hold]
So I'm self employed developer who works on commissioned projects. One issue I've seemed to develop over the last year is that I stress too much over the quality of my code rather than the finished ...
3
votes
0answers
23 views
How Should I Design JSON Serializable Data Classes To Respect Future @NonNull Fields
I have an app that uses Gson to serialize/deserialize data classes and persist data between runs.
My code uses @NonNull annotations for many fields/parameters/method returns and one thing that was ...
0
votes
2answers
73 views
What happens to lock's state and methods when a thread acquires a lock?
Assume I have following class
class Student{
void method1(){
// Do Something
}
void method2(){
// Do Something
}
}
And the object of this class is used as monitor in ...
2
votes
2answers
633 views
Methods to identify and resolve memory leaks in the JVM
As the data is migrated via the object level, there has been a slow upwards trend in memory usage. I can see the periodic gc activity, but the memory trend is still going up slowly. I have currently ...
0
votes
1answer
34 views
How should one model an ExchangeService object (in ews-java-api) for sharing MS Exchange connections?
I am creating an application which uses ews-java-api to connect to an MS Exchange server. Once the connection is authenticated, the api dictates use of ExchangeService object for searching mailboxes, ...
-4
votes
0answers
50 views
how does recursive backtracking work in this one? [on hold]
The question i encountered in this one :-
Write a method countBinary that accepts an integer n as a parameter and that prints all binary numbers that have n digits in ascending order, printing each ...
2
votes
1answer
113 views
Is it still an antipattern if we log an exception message and throw a different exception?
Our webapplication is using an ExceptionMapper to map some exceptions to Response. We log the exception messages before throwing a new exception as follows:
catch (SomeException ex) {
...
-5
votes
0answers
35 views
I need to create a stock class [on hold]
I need to create a class called Stock on BlueJ, with 2 parameters each to be assigned to the "symbol" and "name" instance variables & there should be 2 "set" methods , one each for the ...
0
votes
0answers
10 views
Better way to wrap incompatible objects with default-method emulated traits?
In my Selenium web tests, I wrapped some elements and custom widgets with trait-like interfaces with default methods[1].
I want to add a caching feature to this type hierarchy to avoid repeated ...
0
votes
2answers
243 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 ...
-4
votes
1answer
126 views
Unexpected IndexOutOfBoundsException [on hold]
I was given a project in which there are lines like
Object item = null;
try {
item = mShowsAdapter.get(0);
}
catch ...
7
votes
5answers
388 views
When to use generics in interface design
I have some interfaces that I intend third-parties to implement in the future, and I provide a base implementation myself. I'll only be using a couple to show the example.
Currently, they are defined ...
129
votes
7answers
118k views
What does the Spring framework do? Should I use it? Why or why not?
So, I'm starting a brand-new project in Java, and am considering using Spring. Why am I considering Spring? Because lots of people tell me I should use Spring! Seriously, any time I've tried to get ...
1
vote
3answers
124 views
How does recursive backtracking work ?
I am trying to figure out recursive backtracking, i have good understanding of recursion and till some extent the concept of backtracking too but i am having difficulty understand the chronological ...
0
votes
0answers
65 views
What is the use of stateless object? [on hold]
While it is possible to create a stateless object, I am curious to know a use case or advantage of the same. If a stateless object is created for only providing the behavior then I would prefer static ...
-6
votes
0answers
78 views
Recruitment Questions for the UK [on hold]
this is a bit cheeky of me but I've been referred here by a developer friend of mine.
I Work for the UK government and we have always used external companies for our coding needs. We have decided it ...
10
votes
6answers
24k views
Java serialization - advantages and disadvantages, use or avoid? [on hold]
Serialization is used for persistence in Java. It may be okay to persist a few objects using serialization. But, for a large number of objects, ORM, Database etc might be better. It seems that ...
13
votes
0answers
1k views
Can an abstract class be instantiated? [migrated]
abstract class A {
public void disp() {
System.out.print("Abstract");
}
}
public class B {
public static void main(String args[]) {
A object = new A(){ };
...
1
vote
0answers
148 views
Why aren't Java Collections put in a dedicated package
Why do they just reside in java.util and not somewhere more specialized like java.collections or java.util.collections?
It could contribute to mess up with different unrelated code. Couldn't it?
Was ...
1
vote
2answers
110 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:
...
3
votes
6answers
563 views
Design decisions while porting a non object-oriented C program to Java
Background:
My boss made a comment on porting a C program that acts as some a simulator that communicates with a remote process through sockets to Java. He didn't assign it to me, or to anyone for ...
-3
votes
0answers
136 views
Does a static class have to be nested? [on hold]
I have this problem: "Create a static class in java. This static class must be separate from the class that contain the main function."
Is this possible? I thought java only supported nested static ...
7
votes
5answers
8k views
Is it not a good practice to handle runtime exceptions in the code?
I am working on a Java application, and I see that Run time exceptions are handled in many places. For example,
try {
//do something
}catch(NullPointerException e){
...
2
votes
0answers
47 views
Could Java import C++ classes from a library using JNA or JNI?
In past, I used JNI to access some winapi functions, however winapi is C and therefore just procedural. Now my plan is different and I need to know whether I'm going in the right direction. What I ...
1
vote
0answers
49 views
Decoupled architecture in Android
I am building an app for Android that will have multiple data sources depending on who is using it. N-tier architecture with a repository pattern seems like the right way to go about this but I am ...
1
vote
1answer
115 views
How does Java's Scanner (System.in) input's buffering actually work?
Over the last days, I've being reading questions as the one that follows: "Why is my input code not working?" I myself had a couple times problems getting the input working right...
as far as good, i ...
7
votes
2answers
2k views
Why do we need an instance of the Scanner Class to get an Input on Java?
Java is object oriented, but, why do we need to create an object from the Scanner Class to get input? Couldn't next() methods, for example, just be Static?
C looks to me pretty simpler as you just ...
0
votes
1answer
152 views
Why are Strings in StringPool considered insecure?
Passwords are recommended to be stored in char[] instead of String, as Strings are stored in StringPool.
Read more here
As per this question Strings in StringPool are not available directly.
To ...
-1
votes
0answers
30 views
how to organize android activities to be related? [on hold]
I'm working alone on android Project , and this is my first complete android project , and there are many activities and more parts are related for each activity , I write each part (which is related ...
-3
votes
2answers
2k views
Difference between daemon and child thread? [closed]
As per my knowledge daemon thread is a thread that runs in background(low priority thread) and also a child thread runs in the background when the parent thread runs foreground so where does the ...
1
vote
1answer
48 views
Is it appropriate to pass in a derivative to calculate the error of a Neural Net?
I'm reading a guide for back-propagation of a neural net, and it gives the error function as:
Next work out the error for neuron B. The error is What you want – What you actually get, in other ...
0
votes
0answers
63 views
Make a program deactivate after time [duplicate]
What I am referring to is a free trial. I would like to have a program that runs to a user who downloads it just like normal. However, I want the program to deactivate and become useless after a ...
1
vote
0answers
37 views
Approaches to Modeling a Graph Database over the Google App Engine Datastore?
I want to model a graph database over the Google App Engine Datastore.
I am currently working on creating a Link entity to model the concepts of link/edge/relationship to the graph of objects.
I am ...
-1
votes
0answers
28 views
Optimal Persistance Solution in Java [closed]
I've been working with Java and Spring for 2 years now. Before hand I work in PHP writing straight SQL, I would say I'm more SQL minded than ORM minded. I have struggled to really find a persistence ...
-3
votes
1answer
245 views
Java Start JNLP without paying to certificate authority?
I've noted that now it is difficult to run Java Web start files (JNLP) by Oracle for Java8, without a proper certificate, due to "security reason".It is breaking thousands of applications across the ...
7
votes
2answers
140 views
Optional features: default method or separated interface
Dedicated interfaces seems to be a good way to expose the optional features in a domain-specific type hierarchy. However, they impede the use of decorator and composite patterns, which is also common ...
-3
votes
0answers
21 views
Mixing then printing arrays, but they all end up the same anyways? [migrated]
I'm making a sudoku game. I have an array (puzzle[][][]) containing nine other arrays (zone1[][]-zone9[][]), which each initially contain {{1,2,3},{4,5,6},{7,8,9}} (and they're assigned those values ...
0
votes
2answers
125 views
whats the relationship between integration testing, TDD and Agile methodology? [closed]
I recently attended an interview and was asked whats the relationship between integration testing, TDD and Agile methodology? I am still puzzled how to answer the question !!
2
votes
2answers
382 views
A 'task' system which has an ending, to get ready for next task
I want to make a system, so that there are certain tasks. For example, let's talk about a game. I want to make it so there are 100+ tasks doing different things, but when the player's magic level is ...
1
vote
3answers
222 views
Would combining enums with static strings in java be sloppy?
Currently my team has a number of constants defined as static final strings. I want to be able to iterate over these strings as if they were an enum in one location, but everywhere else they are used ...
1
vote
3answers
253 views
How to use Guice for an effective API Design?
I am creating a base API in JavaSE, which includes modules like MVP architecture, Service & Repository Layer, Event Model to fire events between presenter etc.
I am trying to implement all best ...
7
votes
4answers
856 views
Should Objects with lots of fields be broken up? [duplicate]
When I have an Object that has lots of fields is it better to have them all as fields or try to find logical groupings as their own Objects and make those the fields?
I guess it comes down to which ...
3
votes
1answer
135 views
Should a new type be created though it only wraps a single field?
Say I have an interface Species that's defined as
public interface Species {
String getId();
String getDescription();
}
The question is simply this: Should I create different classes to ...
2
votes
1answer
388 views
DataMapper for a MMO game plugin to send packets
I am working on an plugin for some game-server. The information about the plugin is not really necessary.
Few points you might find helpful to answer to this question:
The server
The server is ...
2
votes
3answers
93 views
Responsibility of the small business logic: in a class or in a method? [closed]
I have separated business logic to many small blocks. Each block can be coded in small number of lines.
Where should I put the block code?
[A] in a method, grouped in the class by some same feature
...
5
votes
4answers
214 views
Is Java package level scope useful?
I understand the idea of package scope, and at times have even thought I wanted it. However, every time I set down with a serious intent to try using it I discovered it did not fit the needs I ...
0
votes
1answer
78 views
JEE MVC, controller calls the interface instead of the interface implementation
I'm following this tutorial: http://wiki4.caucho.com/Building_a_simple_listing_in_JSP It creates a basic web application in Eclipse using the MVC pattern with Resin as the web container. Here's the ...
14
votes
6answers
4k views
Why did Java make package access default?
I'm asking this question because I believe they did it for a very good reason and that most people do not use it properly, well from my experience in industry so far anyway.
But if my theory is true ...
1
vote
1answer
148 views
Non-fixed-size Fenwick Tree implementation
I'm planning to implement a non-fixed-size Fenwick tree. That is, a Fenwick tree that allows interleaving range queries with adding/removing elements.
All implementations and samples I've seen so far ...