Questions tagged [java]

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.

Initial help

Before asking a question, use the search box in the upper right corner to see if it has been asked before by others (we have many duplicates), and please read Writing the perfect question to learn how to get Jon Skeet to answer your question.


Background

Java is a high-level, platform-independent, object-oriented programming language originally developed by Sun Microsystems and released in 1995. Java is currently owned by Oracle, which purchased Sun in 2010.

Very few computers can run Java programs directly. Therefore the Java environment is normally made available by installing a suitable software component. For Windows computers, this is usually done by downloading the free Java Runtime Environment (JRE) from Oracle which allows the system to run Java programs. The easiest way to do this is from java.com.

Developers frequently need additional tools which are available in the free Java Development Kit (JDK) alternative to the JRE, which for Windows must be downloaded from Oracle and installed manually.

Note: Other vendors exist but usually have license fees. For Linux and other platforms consult the operating system documentation.

Most of the Java platform has been open sourced. The open source Java project is called OpenJDK. All major components of the platform are in open source, including the JVM (Java Virtual Machine), the Java compiler, and the class libraries.

More information:

Hello World

public class HelloWorld {
  public static void main(String[] args) {
    System.out.println("Hello, World!");
  }
}

Java source code is compiled to an intermediate form (bytecode instructions for the JVM) that can be executed with the java command.

Beginners resources

  • The Java Tutorials - Starts from scratch on Windows/Linux/Mac and covers most of the standard library.

Day to day resources

Advanced resources

Free Online Resources

4929 questions
39
votes
8 answers

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?
JAVA
  • 1,220
35
votes
4 answers

Is it possible to compile Java into machine code? (Not bytecode)

Can you have Java compiled straight into machine code? I want to do this so I have control over what platforms it's used on, and don't know C,C++ etc.
Russell
  • 453
  • 1
  • 6
  • 10
34
votes
9 answers

Force other developers to call method after completing their work

In a library in Java 7, I have a class which provides services to other classes. After creating an instance of this service class, one method of it may be called several times (let’s call it the doWork() method). So I do not know when the work of…
hasanghaforian
  • 651
  • 1
  • 6
  • 14
25
votes
3 answers

Why does java use an @Override annotation, instead of a modifier?

What were the motivations for java to use the @Override annotation, instead of creating a new override modifier? @Override public String toString() { return ""; } vs. public override String toString() { return ""; }
jwa
  • 359
25
votes
14 answers

Why do we study Java at university?

Java is often found in academia. What is the reason behind that?
Goma
  • 3,853
  • 6
  • 33
  • 55
24
votes
2 answers

Parameters are passed by value, but editing them will edit the actual object (like passed by reference)?

I've just discovered a huge hole in my Java knowledge. I knew that Java passes parameters by value. I thought I understand that and whenever I needed to edit the field object of a class, I create a field. For example, private int mNumber; void…
deviDave
  • 2,943
24
votes
5 answers

Should I use initializer blocks in Java?

I recently came across a Java construct I have never seen before and was wondering whether I should use it. It seems to be called initializer blocks. public class Test { public Test() { /* first constructor */ } public Test(String s) { /* second…
dirkk
  • 348
24
votes
1 answer

What is the difference between channel-based I/O and stream-based I/O in java?

What is the difference between stream-based Input and Channel-Based Input? The java API provides both stream-based in "java.io" package and channel-based in "java.nio" package. Which one of the two is better in performance and reduced run-time…
23
votes
6 answers

Is it bad practice to create new objects without storing them?

I've seen objects created in Java code without storing a reference to the object. For example, in an eclipse plugin I've seen a SWT Shell created like so: new Shell(); This new Shell object is not stored in a variable, but will remain referenced…
Buttons840
  • 1,866
21
votes
8 answers

Java - Why do we call an array a "vector"?

I am reading a book on Java Programming, and want to confirm I understand the definition of the word "vector". Wikipedia says vector is "A one-dimensional array", source http://en.wikipedia.org/wiki/Vector. Wouldnt it be simpler to call the…
davidjhp
  • 397
  • 1
  • 2
  • 8
20
votes
2 answers

what is the difference between callbacks and listeners?

In blackberry we can override keyChar() method and capture the keypress event or we can register onKeyPressListener. i know, onKeyListener is observer pattern. In android also there is a KeyEvent.callback and onKeyListener Both are events why we no…
Vivart
  • 369
  • 1
  • 3
  • 10
20
votes
4 answers

Why is heap size fixed on JVMs?

Can anyone explain to me why JVMs (I didn't check too many, but I've never seen one that didn't do it that way) need to run on a fixed heap size? I know it's easier to implement on a simple contiguous heap, but the Sun JVM is now over a decade old,…
themel
  • 309
20
votes
2 answers

Java void methods implicitly returning this

there are a couple of discussion on SO about setter methods returning "this" type. And looks like java 7 had the proposal of void methods returning this. But this proposal could not make it to java 7 features. I could not find if this proposal is…
Tarun
  • 942
19
votes
6 answers

Why does Java not permit the use of headers as in C++

I have a question that I did not find an answer for except the following answer that does not meet my requirements: "Because James Gosling didn't want to" I know that Java can have interfaces (only pure virtual functions, no attributes), but it is…
17
votes
4 answers

What is the difference between Callable and Java 8's Supplier?

I've been switching over to Java from C# after some recommendations from some over at CodeReview. So, when I was looking into LWJGL, one thing I remembered was that every call to Display must be executed on the same thread that the Display.create()…
Dan
  • 654
1
2 3
16 17