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

UNIT 2 Intro to Java Programming2G

Uploaded by

jiexfg
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

UNIT 2 Intro to Java Programming2G

Uploaded by

jiexfg
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 28

IT PF-01

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.

• OBJECT - is an instance of a Java class, meaning it is a


copy of a specific class.

• METHOD - a behavior of an object.


• ATTRIBUTES - a characteristic/s that describes an object

• Instance Variables - Each object has its unique set of


instance variables.
Review
Review
1. Java was first introduced by ____________ and
was further acquired by _______ in 1995.
2. It’s first name was________.
3. It was immediately collaborated with
Netscape
Navigator’s_____________________.
4. Java adapted the syntax of_______.
5. It promised ________________________providing
no cost run-times on popular platforms.
Topics:
1. Programming Basics
2. Parts of a Java Program
3. Things to Remember about
Java
4. Print methods in Java
5. Escape Sequences in Java
6. Java Program Comments
Java Programming Life Cycle

Java undergoes
programming stages
such as;
1. Writing code
2. Compiling code
3. Executing application
Writing your first Java Program
Example

Write a Java Program that prints


the statement Hello World!
Writing your first Java Program
5. Compile your java file using the
For PC users, follow the command
following steps. javac (your Java File.java)
(after installation of JDK)
6. Execute your file using the
1. Open any text editor. command
2. Type your code java (your Java File)

3. Save your file in .java extension


4. Open cmd go to your directory
where you saved your file
Case Sensitivity
Java is case sensitive, which means
identifier HelloWorld and helloWorld
would have different meaning.
Naming Convention

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

Method Names - All method names should start with a


Lower Case letter. If several words are used to form the
name of the method, then each inner word's first letter
should be in Upper Case. Example myMethodName()
Naming Convention
Constant Names – All constant names should be
in written in Upper Case. If several words are
used to form the name of the constant, then put
underscore between words.
Program File Name
Name of the program file should exactly match
the class name. When saving the file, you should
save it using the class name (Remember Java is
case sensitive) and add '.java' to the end of the
name
(if the file name and the class name do not match your program will not
Example : Assume 'HelloWorld' is the class
compile).
name, then the file should be saved
as'HelloWorld.java'
Main Method
public static void main(String args[]) -
Java program processing starts from the
main() method, which is a mandatory part of
every Java application.
Java Identifiers
1. All identifiers should begin with a letter (A to Z or a to
z), currency character ($) or an underscore (_).
2. After the first character, identifiers can have any
combination of characters.
3. A keyword cannot be used as an identifier.
4. Most importantly identifiers are case sensitive.
Examples of legal identifiers: age, $salary, _value, __1_value
Examples of illegal identifiers: 123abc, -salary
Java Modifiers
Like other languages, it is possible to modify classes,
methods, etc., by using modifiers. There are two
categories of modifiers:

Access Modifiers: default, public, protected, private


Non-access Modifiers: final, abstract
Java Variables
Type of variables in Java:

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

Java Multi-line Comments


Multi-line comments start with /* and ends with */.
Any text between /* and */ will be ignored by Java.
End of Discussion
Task No. 1
Write, compile, and test a class that displays
the following pattern on
the screen:
Use the print methods and the appropriate
escape sequence.
Comment out your Full Name at the end of
your code.
Screenshot your code and your output and
upload them over this assignment.
Thank you!

You might also like