Know Java? Well,  I don’t see a reason not to start at the beginning, with the Getting Started trail as a warm-up.

.java -javac-> .class -java-> JVM

There, done 😉 Not too much to make notes on so this can be a General Java notes page and experiment with the format.

Documentation

Tools

  • Java
    • -ea (-enableassertions), e.g. assert(expr)

NetBeans

  • Tools | Java Platforms : e.g. to add other JDK
  • File | Project Properties -> Libraries -> Java Platform : to set project specific JDK

Getting Started Trail Exercises

Question 1: When you compile a program written in the Java programming language, the compiler converts the human-readable source file into platform-independent code that a Java Virtual Machine can understand. What is this platform-independent code called?

bytecodes

Question 2: Which of the following is not a valid comment:

a. /** comment */
b. /* comment */
c. /* comment
d. // comment

Question 3: What is the first thing you should check if you see the following error at runtime:

Exception in thread "main" java.lang.NoClassDefFoundError:
HelloWorldApp.java.

This means that java cannot find the bytecode file, HelloWorldApp.class. Check that the class file in the dir where java is being executed or that the CLASSPATH contains a path that the file is under.

Question 4: What is the correct signature of the main method?

public static void main (String[] args)

Question 5: When declaring the main method, which modifier must come first, public or static?

Either

Question 6: What parameters does the main method define?

An array of String arguments from the cmd line

Exercise 1: Change the HelloWorldApp.java program so that it displays Hola Mundo! instead of Hello World!.

Exercise 2: You can find a slightly modified version of HelloWorldApp here: HelloWorldApp2.java

System.out.println(” Hola Mundo!”);

The program has an error. Fix the error so that the program successfully compiles and runs. What was the error?

Missing “

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s