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

97
votes
16answers
48k views

When are Getters and Setters Justified

Getters and setters are often criticized as being not proper OO. On the other hand most OO code I've seen has extensive getters and setters. When are getters and setters justified? Do you try to ...
31
votes
6answers
4k views

How do you encode Algebraic Data Types in a C#- or Java-like language?

There are some problems which are easily solved by Algebraic Data Types, for example a List type can be very succinctly expressed as: data ConsList a = Empty | ConsCell a (ConsList a) consmap f ...
570
votes
22answers
64k views

Where did the notion of “one return only” come from?

I often talk to Java programmers who say "Don't put multiple return statements in the same method." When I ask them to tell me the reasons why, all I get is "The coding standard says so." or "It's ...
24
votes
6answers
7k views

Is there a canonical book for learning Java as an experienced developer? [closed]

I have been a .NET developer now for about the past 5/6 years give or take. I have never done any professional Java development and the last time I really touched it was probably back in college. I ...
10
votes
6answers
1k views

Should I extract specific functionality into a function and why?

I have a large method which does 3 tasks, each of them can be extracted into a separate function. If I'll make an additional functions for each of that tasks, will it make my code better or worse and ...
21
votes
11answers
4k views

Is it a really required skill to program without API documentation?

I barely passed my Java programming exam today. I had to answer some general questions about threading which I did well and to write a little threaded program which was worse. I had to connect my ...
55
votes
11answers
6k views

Did the developers of Java consciously abandon RAII?

As a long-time C# programmer, I have recently come to learn more about the advantages of Resource Acquisition Is Initialization (RAII). In particular, I have discovered that the C# idiom: using (var ...
15
votes
6answers
5k views

Efficient try / catch block usage?

Should catch blocks be used for writing logic i.e. handle flow control etc? Or just for throwing exceptions? Does it effect efficiency or maintainability of code? What are the side effects (if there ...
295
votes
39answers
254k views

Why isn't Java used for modern web application development? [closed]

As a professional Java programmer, I've been trying to understand - why the hate toward Java for modern web applications? I've noticed a trend that out of modern day web startups, a relatively small ...
81
votes
3answers
29k views

Choosing between Single or multiple projects in a git repository?

In a git environment, where we have modularized most projects, we're facing the one project per repository or multiple projects per repository design issue. Let's consider a modularized project: ...
52
votes
1answer
8k views

What are these different Java versions for?

I am just about to start my Java journey, ( I've already dabbled in C++) but I am getting really confused about all the different versions of Java: JavaSE JavaEE JavaFX etc. Can someone explain ...
45
votes
8answers
4k views

Why a static main method in Java and C#, rather than a constructor?

I’m Looking for a definitive answer from a primary or secondary source for why (notably) Java and C# decided to have a static method as their entry point, rather than representing an application ...
15
votes
5answers
10k views

When to use primitive vs class in Java?

I see that Java has Boolean (class) vs boolean (primitive). Likewise, there's an Integer (class) vs int (primitive). What's the best practice on when to use the primitive version vs the class? ...
8
votes
4answers
1k views

Make methods that do not depend on instance fields, static?

Recently I started programming in Groovy for a integration testing framework, for a Java project. I use Intellij IDEA with Groovy plug-in and I am surprised to see as a warning for all the methods ...
1
vote
2answers
2k views

What other reasons are there to write interfaces rather than abstract classes? [duplicate]

Possible Duplicate: When to use abstract classes instead of interfaces and extension methods in C#? When I read and looked at codes using Abstract classes, I was able to justify it because ...
150
votes
10answers
18k views

Mono is frequently used to say “Yes, .NET is cross-platform”. How valid is that claim? [closed]

In What would you choose for your project between .NET and Java at this point in time? I say that I would consider the "Will you always deploy to Windows?" the single most important (EDIT: technical) ...
42
votes
6answers
11k views

What is the point of having every service class have an interface? [duplicate]

At the company I work at, every service class has a corresponding interface. Is this necessarily? Most of these interfaces are only used by a single class and we are not creating any sort of public ...
26
votes
15answers
34k views

When is Java a good choice for web development? [closed]

When is Java a good choice for web development? Please do not say "When you have a development team that knows only Java."
58
votes
11answers
5k views

I've been told that Exceptions should only be used in exceptional cases. How do I know if my case is exceptional?

My specific case here is that the user can pass in a string into the application, the application parses it and assigns it to structured objects. Sometimes the user may type in something invalid. ...
15
votes
5answers
8k views

What is the difference between all-static-methods and applying a singleton pattern?

I am making a database to store information about the users of my website (I am using stuts2 and hence Java EE technology). For the database I'll be making a DBManager. Should I apply singleton ...
90
votes
11answers
24k views

What backs up the claim that C++ can be faster than a JVM or CLR with JIT? [closed]

A reoccurring theme on SE I've noticed in many questions is the ongoing argument that C++ is faster and/or more efficient than higher level languages like Java. The counter-argument is that modern JVM ...
58
votes
3answers
29k views

How is a Java reference different from a C pointer?

C has pointers and Java has what is called references. They have some things in common in the sense that they all point to something. I know that pointers in C store the addresses they point to. Do ...
83
votes
10answers
51k views

How do you unit test private methods?

I am working on a java project. I am new to unit testing. What is the best way to unit test private methods in java classes?
35
votes
11answers
3k views

What are the factors that have made Java a success as a programming language in enterprise computing?

What are the factors that have made Java a success as a programming language in enterprise computing?
31
votes
11answers
14k views

Is it good practice to catch a checked exception and throw a RuntimeException?

I read some code of a colleague and found that he often catches various exceptions and then always throws a 'RuntimeException' instead. I always thought this is very bad practice. Am I wrong?
14
votes
8answers
10k views

What is the point of an interface? [duplicate]

Possible Duplicate: When to use abstract classes instead of interfaces and extension methods in C#? What other reasons are there to write interfaces rather than abstract classes? This ...
3
votes
2answers
871 views

Which Java framework meets these requirements? [closed]

Which Java framework meets these requirements? What set of frameworks would be best suited to meet these requirements? The requirements are: oriented for web support for transactions support for ...
138
votes
13answers
32k views

Should we avoid object creation in Java?

I was told by a colleague that in Java object creation is the most expensive operation you could perform. So I can only conclude to create as few objects as possible. This seems somewhat to defeat ...
46
votes
10answers
15k views

Why is String immutable in Java?

I couldn't understand the reason of it. I always use String class like other developers, but when I modify the value of it, I need to create new instance of String. What might be the reason of ...
31
votes
4answers
13k views

In Java, should I use “final” for parameters and locals even when I don't have to?

Java allows marking variables (fields / locals / parameters) as final, to prevent re-assigning into them. I find it very useful with fields, as it helps me quickly see whether some attributes - or an ...
14
votes
9answers
2k views

How do you learn to program? [duplicate]

Possible Duplicates: I still can't figure out how to program? I'm graduating with a Computer Science degree but I don't feel like I know how to program I don't known if you guys ...
24
votes
4answers
13k views

How to justify migration from Java 6 to Java 7?

We were migrating from Java 6 to Java 7. The project is behind schedule and risks being dropped, in which case it will continue to use Java 6. What are the specific improvements in Java 7 that we ...
15
votes
7answers
11k views

Is Java (still) the cross platform language of choice? [closed]

When I started using Java in the nineties, it was all "Write once, run anywhere!" from day one. That was probably all true then and I was a part of the choir as well. I am not sure what to think ...
13
votes
5answers
1k views

What makes JVM so much versatile to support so many JVM languages?

JVM supports so many languages other than Java like Groovy,Clojure,Scala etc which are functional languages unlike Java(I am referring to Java before Version 8 where Lambda's are not supported) that ...
5
votes
5answers
1k views

How should I handle exception that *should* never be thrown? [duplicate]

What is the best way to handle errors that shouldn't ever happen? My current way to do this is to throw an exception if the 'thing that shouldn't happen' does happen, like so: /* * Restoring from a ...
56
votes
7answers
41k views

Why use try … finally without a catch clause?

The classical way to program is with try ... catch. When is it appropriate to use try without catch? In Python the following appears legal and can make sense: try: #do work finally: #do ...
29
votes
4answers
35k views

What is the point of using DTO (Data Transfer Objects)?

What is the point of using DTO and is it an out dated concept? I use POJOs in the view layer to transfer and persist data. Can these POJOs be considered as an alternative to DTOs?
23
votes
8answers
21k views

Why can static methods only use static data?

I don't understand why a static method can't use non-static data. Can anybody explain what the problems are and why we can't do it?
27
votes
8answers
25k views

Can we use Java for commercial use?

The Java is GPL license (reference from wikipedia). I am not sure I can use it in in commercial projects. I already have a website written in Java and I plan to use this for commercial use. Is that ...
12
votes
3answers
2k views

What are the downsides of implementing a singleton with Java's enum?

Traditionally, a singleton is usually implemented as public class Foo1 { private static final Foo1 INSTANCE = new Foo1(); public static Foo1 getInstance(){ return INSTANCE; } private ...
1
vote
4answers
1k views

how to learn Java [closed]

This question I am asking because I couldn't find any source which gives complete overview of java development. I just want to know where java technology currently in market & what is preferable ...
25
votes
9answers
8k views

Should the methods of a class call its own getters and setters?

Where I work I see lots of classes that do things like this: public class ClassThatCallsItsOwnGettersAndSetters { private String field; public String getField() { return field; ...
10
votes
6answers
3k views

Is it necessary to write a javadoc comment for EVERY parameter in a method's signature?

One of the devs on my team believes that it is necessary to write a javadoc comment for EVERY parameter in a method's signature. I do not think this is necessary, and in fact I think it can even be ...
5
votes
3answers
1k views

How to create a manager class without global variables nor singletons?

I would like to implement some kind of manager class in my application. It will be in charge of loading textures, processing them, distributing them etc... At first, I wanted to make a global ...
7
votes
3answers
6k views

Does it make a difference if I declare variables inside or outside a loop in Java? [duplicate]

Possible Duplicate: Where do you declare variables? The top of a method or when you need them? Does it make a difference if I declare variables inside or outside a loop in Java? Is this ...
12
votes
2answers
1k views

Java and JVM license

Does Java license allow other companies to create their own versions of Java language or just implement it accurately? Same question about JVM. I heard about Sun suing Microsoft for changing their ...
113
votes
6answers
102k 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 ...
95
votes
15answers
13k views

Why did memory-managed languages like Java, Javascript, and C# retain the `new` keyword?

The new keyword in languages like Java, Javascript, and C# creates a new instance of a class. This syntax seems to have been inherited from C++, where new is used specifically to allocate a new ...
34
votes
7answers
8k views

Is Functional Programming possible in Java?

I was browsing through the Amazon.com Bookstore and I came across the book "Functional Programming for Java Developers". I know some very basic Functional Programming and have been programming in ...
33
votes
4answers
66k views

Stack and Heap memory in Java

As I understand, in Java, stack memory holds primitives and method invocations and heap memory is used to store objects. Suppose I have a class class A { int a ; String b; ...