UNIT 2 Intro to Java Programming2G
UNIT 2 Intro to Java Programming2G
Object-Oriented
Programming
APPLE GRACE G. OLIVEROS
Nueva Ecija University of Science and Technology
UNIT 2
INTRODUCTION TO JAVA
PROGRAMMING
Review
• CLASS - is a logical template to create objects that
share common properties and methods.
Java undergoes
programming stages
such as;
1. Writing code
2. Compiling code
3. Executing application
Writing your first Java Program
Example
Class Names - For all class names, the first letter should be
in Upper Case. If several words are used to form a name of
the class, each inner word’s first letter should be in Upper
Case. Example class MyFirstJavaClass
1. Local Variables
2. Class Variables (Static Variables)
3. Instance Variables (Non-static
variables)
Java Arrays
Arrays are objects that store multiple
variables of the same type. However, an
array itself is an object. We will look into
how to declare, construct and initialize in the
upcoming chapters.
Java Reserved Words
The following list shows the reserved words
in Java. These reserved words may not be
used as constant or variable or any other
identifier names.
Print methods in Java
To display a literal values in Java over a
console, a programmer uses either
System.out.print(“”); or
System.out.println(“”); methods.
• System.out.print(“”); is used to print literals
on single line.
• System.out.println(“”); is used to print literals
providing new lines every after println()
methods.
Escape Sequence in Java
A character preceded by a backslash (\) is an
escape sequence and has a special meaning to
the compiler.
Java Program Comments
Comments can be used to explain Java code, and to
make it more readable. It can also be used to prevent
execution when testing alternative code.
Java Program Comments
Single-line Comments
Single-line comments start with two forward slashes (//).
Any text between // and the end of the line is ignored by
Java (will not be executed).
Java Program Comments