ajsie
ajsie

Reputation: 79686

the main class in a java source file?

im new to java.

the standard code that is created after i created a new project in netbeans is:

package helloworldapp;

public class Main {

    public static void main(String[] args) {
        int[] array = new int[10];
        array[9] = 1;

        System.out.println(array[9]);
    }
}

so you see that it uses the System class, but i dont see that class has been imported. Is there another code somewhere that does that? How can i use it if its not imported.

Upvotes: 2

Views: 329

Answers (4)

user85421
user85421

Reputation: 29680

Additional info:

How can i use it if its not imported.

you can use any class in another package, without importing it, by using the fully qualified name. Example:

    java.util.Date now = new java.util.Date();

instead of

import java.util.Date;  // or java.util.*;
...
    Date now = new Date();

Update:
import is only used at compile time to determine the fully qualified name of classes.

Upvotes: 3

Dan
Dan

Reputation: 1813

Directories containing all standard Java classes are part of the default search algorithm used by both the compiler (javac) and java commands. As already described in other answers, java.lang and java.util are examples of the System classes being automatically available for the code you're writing.

The JAR file containing these classes can be found on the currently used JDK installation directory of your machine

Upvotes: 0

danben
danben

Reputation: 83250

System is in the java.lang package which is automatically available in all Java programs.

Upvotes: 2

Stu Thompson
Stu Thompson

Reputation: 38868

The System class is, along with everything else in java.lang, imported automatically. Other classes you probably use that are automagically imported include String and Exception.

Upvotes: 6

Related Questions