2. Class Sampleone
{
public static void main(String args[])
{
System.out.println(“Java is better than C++”);
}
}
Class Declaration:
Class Sampleone
declares a class, which is an object-oriented construct. Java
is a true object oriented language and therefore ,
everything must be placed inside a class.
Class is a keyword and declares that a new class definition
follows. Sample one is a identifier that specifies the name of
the class to be defined.
3. Opening Brace:
Every class definition in java begins with an opening
brace “{“ and ends with a matching closing brace”}”.
The Main Line:
public static void main(String args[])
define a method name main. Every java program must
include the main()method. Java application can have any
number of classes but only one must include a main
method .
4. This line contains a number of keywords public,
static and void
Public The keyword public is an access specifier that
declares the main method it accessible to all
other classes. This is similar to the C++ public
modifier.
Static The Keyword static, which declares this
method as one that belong to the entire class
and not a part of any objects of the class.
Void The type modifier void states that the main
method does not return any value.
5. The Output Line:
System.out.println(“Java is better than C++”);
This is similar to printf() statement of C or cout <<
constructor of C++. Every method must be an object.
The println method is a member of the out object, is a
static data member of system class.
Java is better than C++
The method pritnln always appends a newline
character to the end of the string .
Every java statement must be end with a
semicolon.