0% found this document useful (0 votes)
61 views16 pages

Dimentary Java 1

This document provides an overview of introductory Java programming concepts including: - The main method is executed first when running a Java program. Code is placed within methods and classes. - Variables are named locations in memory that contain data of a specified type like int or String. - Java uses primitive data types to store values and identifiers to name classes, methods, and variables. - Comments are used to explain code and are ignored by the compiler. Single-line comments begin with // and multi-line comments begin and end with /* and */.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
61 views16 pages

Dimentary Java 1

This document provides an overview of introductory Java programming concepts including: - The main method is executed first when running a Java program. Code is placed within methods and classes. - Variables are named locations in memory that contain data of a specified type like int or String. - Java uses primitive data types to store values and identifiers to name classes, methods, and variables. - Comments are used to explain code and are ignored by the compiler. Single-line comments begin with // and multi-line comments begin and end with /* and */.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 16

ITPF 01– Object Oriented Programming 1

C02.1 - Rudimentary
Java
Melgine M. Bauat, MSIT
Instructor
Components of Java Program

• In Java, executable statements are placed in functions,


known as methods, that belong to class definitions.

• The static method named main is the first method to be


executed when running a Java program.

• Any set of statements between the braces “{” and “}”


define a program block.
Reserved Words
Java Identifiers

• An identifier is the name of a class, method, or variable.


• An identifier cannot be any reserved word.
• It can be any string of Java letters, beginning with a letter
( or ‘$’ or ‘_’ ), followed by letters, including digits.

Examples:
o packages: org.omg.CORBA , java.lang , eecs2011.assignments
o Classes:Name , Math , enum , MyClass , YourClass
o Interfaces: Comparable, Clonable, Iterable
o methods: verb , getValue , isEmpty , equals , clone , toString
o variables: name , counter3 , $testVariable , _testVar
o CONSTANTS: PI , MAX_INT , ELECTRON_MASS
Variables and Data Types

• Variable definitions
• Variable: name of place in memory that can contain data
• All variables have:
• Data type  kind of data variable can contain
• Name  identifier that refers to the variable
• Value  the default or specified value
• also called the literal of the statement
• Semicolon
• Remember: All java statements end with a semicolon!
• e.g.
• String myname= “Melgine”;
• int count = 5;
Constants

• Using Constants
• Variable with a value that doesn’t change
• Keyword
• final
• Denotes value cannot change
• Example:
• final double SALES_TAX_RATE = 4.5;
• note the naming convention
• other examples?
Java Primitive Data Types
• Java has several primitive types, which are basic ways of storing
data.

• An identifier variable can be declared to hold any primitive type and


it can later be reassigned to hold another value of the same type.
Developing Java Program
use any text editor or
editor IDE
to create your program
your program (a text
Universe.java file)
type javac Universe.java
compiler to compile your program
byte-code version of your
Universe.class program
type java
JVM Universe
to execute your
program
“Hello Universe!” output
Developing Java Program

public class HelloJava {


public static void main(String[]args) {
String myname = “Melgine”;
int age
Every = of
line 18;code
System.out.println("Hello
that Java!
This is the Java Class
runs in Java I am " +
Name.
JavaPublic
Class static
Name void
mustmain().
be the This
must be inside a class
myname
And
sameiswith
forget+"
Don’tclosing
the starting and
to put
curly
the Java point ofI the
amJava
opening
Filename. " +variables.
curly brace
brace. In declaring
age +" year-old");
In program.
this Example,Code
the
Thewritten
filename
format
Declaring numeric
inside
is data type
variables.
} mustopening and closing
be HelloJava.java
int [space]
age =
curly
variable
18. As youname. In
can see,
brace will
In Java, the “+”ourbe executed.
sign can be used
} System.out.println().
in arithmetic and
numericexample,
value (18)theisn’t
concatenation.
data type is
If
This will show the output in a String
inside andquote
double the variable
becausename
Concatenation. used
(+). in two or more
Equivalent numeric value
single line. Text and variable it isisa myname
numeric value.
to >>“(“
inopen it will
joinperform
C++.parenthesis
It will literal addition. If used in
inside and
strings variables accompanied by literal
“)” close and variables.
parenthesis will be
string, it will function as
shown in the screen
concatenation
Developing Java Program

editor helloJava.java
Hellojava.java
HelloJava.java These are wrong

compiler

HelloJava.class

JVM

Output
Programmer and JVM perspective.

This is Java Language that programmers This is the compiled byte code that JVM
can understand. However, JVM can’t can understand. However, programmers
understand this. can’t understand this.

COMPILER
(javac)
Java Comments

• Comments
• Single line
• // compiler ignores
everything to end of line

• Multi-line
• /* compiler ignores
everything in between */

• Comments do not appear in


executable code
Literals
Numeric Literals String type Literals
int a = 8 + 12; char z = “Z”;
int b = a + 5; String myName = “Melgine”
System.out.println(“Enter
NOT Numeric Literal your Name: ”);
int c = a + b;
Additional Reading Materials

https://drive.google.com/file/d/1Has5wcqNkFy3pSPJpH6uw6O9_8JJq
j-q/view?usp=sharing

Read this PDF File on our extra time.


We will have a QUIZ next meeting. Questions will be from this PDF
file and PowerPoint Slides. C01.1 and C02.1
NEXT TOPIC

Next meeting we will discuss the ff:


1. Java Expressions and Operators
 Relational
 Equality
 Arithmetic
 Logical
 Increment / Decrement
2. Casting (Implicit, Explicit)
3. Java Instance Variables
4. Java Windowed Application
ITPF 01– Object Oriented Programming 1

Thank you for listening!

You might also like