Professional Documents
Culture Documents
1.1 - Introduction To Java
1.1 - Introduction To Java
Java
Session Objectives
Data
Hiding
Data Abstraction
Hiding
Implementation
details of the
Data
Inheritance
“Derived class”
inherits
features from
“Base Class”
History of Java
System.out.println(“Hello”);
}
In Java, the main() method and the class in which it is
defined should be declared public because the Java
runtime environment has to access the main() method to
execute a program
The main() method should be declared static because it
has to exist before any object of the class is created
The command line parameter is a String type variable –
main(String args[]). The number of arguments is
determined by the String class object
The String Object:
In Java, a String is a real object and not an array of null-
terminated characters as in C++
In Java, the String objects are consistent. The way in
which strings are obtained and the string elements are
accessed is consistent across all systems. They have well-
defined programming interfaces
In Java, the String objects are reliable. They do not give
rise to memory leaks in a program
Java uses all the system resources such as the display device
and the keyboard with the help of the System class. This class
contains all the methods that are required to work with the
system resources
The out object encapsulated inside the System class
represents the standard output device. This object contains the
println() method
The println() method displays data on the screen
Executing a Java Program:
Java programs are executed by a program called the Java
Virtual Machine (JVM). The JVM contains the runtime
environment and the class loader
You must save a Java source file with the .java extension.
The name of the file should be the same as the public class
name
When you compile a .java file, a .class file is created
To compile a file, you use the javac utility.
To execute a .class file, you use the java utility
For example, to compile and execute a class Welcome:
Save the file as Welcome.java
At the command prompt, type
javac Welcome.java <Enter>
At the command prompt, type
java Welcome <Enter>