Lect-1C Intro to Java
Lect-1C Intro to Java
CS F213
Object Oriented Programming
08/01/25
Encapsulation
A mechanism of wrapping the data (variables) and code
acting on the data (methods) together as a single unit.
classes
▪ Class contains: Data
Member/Instance
variables
Inheritance
o A mechanism in which one class acquires the property of
another class.
o Example, a child inherits the traits of his/her
parents.
Polymorphism
▪ It is a OOP concept where one name can have many
forms.
Java Program
My first program
» The system locates and runs the main method for a class
when you run a program.
▪ String args[ ]
System.out.println
▪ println: It is a method
Blocks
▪ A pair of braces in a program form a block that groups
components of a program.
Comments
//my first java program
class myfirstjavaprogram
{
public static void main(String args[])
{
System.out.println("this is my first java
program");
}
}
// This is a single line comment
/* These are multiple
line comments */
Lexical constraints
▪ Whitespace – Java is a free-form language (indentation is not
necessary but desirable).
» As long as there is one whitespace character between each token –
Space, tab, and newline.
▪ Comments – /* */ and //