0% found this document useful (0 votes)
183 views

Java Notes Naveen

The document discusses the main method in Java, which is where program execution begins. It notes that the main method must be public and static so that it can be accessed from outside the class. While main acts as the starting point, complex programs will contain many classes with only one containing the main method to launch the application. It also briefly touches on static methods and how they differ from instance methods by not having access to object instance variables.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
183 views

Java Notes Naveen

The document discusses the main method in Java, which is where program execution begins. It notes that the main method must be public and static so that it can be accessed from outside the class. While main acts as the starting point, complex programs will contain many classes with only one containing the main method to launch the application. It also briefly touches on static methods and how they differ from instance methods by not having access to object instance variables.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

line of code is shown here:

public static void main(String args[]) {

This line begins the main( ) method. As the comment preceding it suggests, this is the line at
which the program will begin executing. All Java applications begin execution by calling

main( ).

The public keyword is an access specifier, which allows the programmer to control the visibility
of class members. When a class member is preceded by public, then that member may be
accessed by code outside the class in which it is declared.

One other point: main( ) is simply a starting place for your program. A complex program will
have dozens of classes, only one of which will need to have a main( ) method to get things
started.

Two Control Statements

Static methods

Static methods use no instance variables of any object of the class they are defined in. If you
define a method to be static, you will be given a rude message by the compiler if you try to
access any instance variables. You can access static variables, but except for constants, this is
unusual. Static methods typically take all the data from parameters and compute something from
those parameters, with no reference to variables.

You might also like