ASCII
American Standard Code
Information Interchange
for
ASCII is now the universal
standard for computers to decode
all letters of the alphabet and
special
characters.
Powerpoint Templates
Page 1
ASCII
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
Symbol
@
A
B
C
D
E
F
G
H
I
J
K
L
M
N
Powerpoint Templates
O
Page 2
Casting
process of converting a
value to the type of a
variable
Powerpoint Templates
Page 3
Concatenation
process of joining
values together
Powerpoint Templates
Page 4
Constant
identifier whose value
can never be changed
once initialized
Powerpoint Templates
Page 5
Identifier
user-defined name for
methods, classes,
objects, variables, and
labels
Powerpoint Templates
Page 6
Java Keyword
word used by the Java
compiler for a specific
purpose
Powerpoint Templates
Page 7
Literals
values assigned to
variables or constants
Powerpoint Templates
Page 8
Variable
identifier whose
value can be
changed
Powerpoint Templates
Page 10
Identifiers
are user-defined names for methods, variable,
constants, and classes.
Rules:
1. The first character of your identifier should start
with a letter of the alphabet, an underscore
( _ ), or a dollar sign ($). After that, the identifier
can then be composed of alphanumeric
characters and underscores.
Powerpoint Templates
Page 11
2. Create identifiers that are descriptive of
their purpose. If your identifier is composed
of several words, capitalizing the first letter
of each word is a good programming
practice.
Powerpoint Templates
Page 12
Valid Identifiers
Invalid Identifiers
MyIdentifierName
My Identifier Name
myidentifiername
my+identifier+name
my_identifier_name
my-identifier-name
_myidentifiername
my_identifiers_name
$myidentifiername
my_identifier_&_name
_3names
3names
Powerpoint Templates
Page 13
Data types
Primitive data types
Reference data types
Powerpoint Templates
Page 14
Data type
Example/s
string
hello world
boolean
true, false
char
A, z, \n, 6
byte
short
11
int
167
long
11167L
float
63.5F
double
63.5
Primitive data
types
Powerpoint Templates
Page 15
Data Type
Length
Range
byte
8 bits
-2 7 to 2 7 -1
short
16 bits
-2 15 to 2 15 -1
int
32 bits
-2 31 to 2 31 -1
long
64 bits
-2 63 to 2 63 -1
Powerpoint Templates
Page 16
Variables
are identifiers whose values
can be changed.
general syntax is :
<data_type> <identifier>;
int number
Powerpoint Templates
Page 17
Examples
boolean
char
byte
short
int
long
float
Double
String
Passed;
EquivalentGrade;
YearLevel;
Classes;
Faculty_No;
Student_No;
Average;
Logarithm;
LastName;
Powerpoint Templates
Page 18
Examples
boolean
Passed =true;
char
EquivalentGrade =F;
byte
YearLevel =2;
short
Classes =19;
int
Faculty_No =6781;
long
Student_No =76667L;
float
Average =76.87F;
double
Logarithm=0.879463434;
String
LastName =Bonifacio;
Powerpoint Templates
Page 19
Examples
boolean
Passed =true, Switch;
char
EquivalentGrade =F, ch1,ch2;
byte
YearLevel =2;
short
Classes =19;
int
Faculty_No =6781, Num1;
long
Student_No =76667L,
Long;
float
Average =76.87F, Salary;
double
Logarithm =0.879463434,
Tax, SSS;
String
LastName =Bonifacio,
FirstName=Andres;
Powerpoint Templates
Employee_No,
Page 20
Casting
Powerpoint Templates
Page 21
public class Core
{
public static void main (String [] args)
{
int x=10, Average=0;
double Quiz_1=10, Quiz_2=9;
char c=a;
Average=(int) (Quiz_1=Quiz_2)/2);//explicit casting
x=c; //implicit casting from char to int
System.out.println(The ASCII equivalent);
System.out.println(of the character a is : +x);
System.out.println(This is the average of the two quizzes:
+Average);
}
}
Powerpoint Templates
Page 22
Powerpoint Templates
Page 23
public class Core
{
Powerpoint Templates
Page 24
public static void main (String [] args)
{
Powerpoint Templates
Page 25
int x=10, Average=0;
double Quiz_1=10, Quiz_2=9;
char c=a;
Powerpoint Templates
Page 26
Average=(int) (Quiz_1+Quiz_2)/2);
//explicit casting
Powerpoint Templates
Page 27
x=c; //implicit casting from char to int
Powerpoint Templates
Page 28
System.out.println(The ASCII
equivalent);
System.out.println(of the
character a is : +x);
System.out.println(This is the
average of the two quizzes: +Average);
}
}
Powerpoint Templates
Page 29
public class Core
{
public static void main (String [] args)
{
int x=10, Average=0;
double Quiz_1=10, Quiz_2=9;
char c=a;
Average=(int) (Quiz_1+Quiz_2)/2); //explicit casting
x=c; //implicit casting from char to int
System.out.println(The ASCII equivalent);
System.out.println(of the character a is : +x);
System.out.println(This is the average of the two quizzes:
+Average);
}
}
Powerpoint Templates
Page 30
Powerpoint Templates
Page 31
Get sheet of paper
Powerpoint Templates
Page 32
Write V if the identifier is
valid.
Write I if it is invalid.
Powerpoint Templates
Page 33
1.
2.
3.
4.
5.
6.
7.
8.
variable 2
main
Average+quizzes
principal_amount
$rate
sum_quiz1&quiz2
int
3x
Powerpoint Templates
Page 34
9. x-5
10. PRODUCT
11. firstname
12. AreaofSquare
13. periMeter
14. num_1
15. a*b
Powerpoint Templates
Page 35
1.
2.
3.
4.
5.
6.
7.
8.
I
I
I
V
V
I
I
I
9. I
10. V
11. V
12. V
13. V
14. V
15. I
Powerpoint Templates
Page 36
Powerpoint Templates
Page 37
Powerpoint Templates
Page 38
Identify the data type for
variables and literals given.
Powerpoint Templates
Page 39
Identify the data type for variables
and literals given.
1.
2.
3.
4.
5.
x = a
quiz1 = 90.75
age = 15
age2=15 years old
num3 = 10.91F
Powerpoint Templates
Page 40
Identify the data type for variables
and literals given.
6. failed = false
7. interest = 1000
8. size = small
9. cents = 0.87539
10. date = 11-30-1998
Powerpoint Templates
Page 41
Identify the data type for variables
and literals given.
1.
2.
3.
4.
5.
x = a
quiz1 = 90.75
age = 15
age2=15 years old
num3 = 10.91F
Powerpoint Templates
Page 42
Identify the data type for variables
and literals given.
6. failed = false
7. interest = 1000
8. size = small
9. cents = 0.87539
10. date = 11-30-1998
Powerpoint Templates
Page 43
Create a program that will
compute the sum of 20 and 11.5
and display the result.
Powerpoint Templates
Page 44
let
num1 = 20
num2 = 11.5
Variables
sum = num1+num2
(Identifiers)
Powerpoint Templates
Page 45
int
num1 = 20
double num2 = 11.5
double sum
Powerpoint Templates
Page 46
public class Sum
Powerpoint Templates
Page 47
public class Sum
{
Powerpoint Templates
Page 48
public class Sum
{
public static void main (String[]args)
Powerpoint Templates
Page 49
public class Sum
{
public static void main (String[]args)
{
Powerpoint Templates
Page 50
public class Sum
{
public static void main (String[]args)
{
int num1=20;
double num2=11.5;
double sum;
Powerpoint Templates
Page 51
public class Sum
{
public static void main (String[]args)
{
int num1=20;
double num2=11.5;
double sum;
sum=num1+num2;
Powerpoint Templates
Page 52
public class Sum
{
public static void main (String[]args)
{
int num1=20;
double num2=11.5;
double sum;
sum=num1+num2;
System.out.println(The sum is: +sum);
Powerpoint Templates
Page 53
public class Sum
{
public static void main (String[]args)
{
int num1=20;
double num2=11.5;
double sum;
sum=num1+num2;
System.out.println(The sum is: +sum);
}
Powerpoint Templates
Page 54
public class Sum
{
public static void main (String[]args)
{
int num1=20;
double num2=11.5;
double sum;
sum=num1+num2;
System.out.println(The sum is: +sum);
}}
Powerpoint Templates
Page 55
public class Sum
{
public static void main (String[]args)
{
int num1=20;
double num2=11.5;
double sum;
Declarations
sum=num1+num2;
System.out.println(The sum is: +sum);
Formula
}
}
Powerpoint Templates
Page 56
The sum is: 31.5
Powerpoint Templates
Page 57
1. Create a program that will get the
difference of 150 and 75. Then display
the result.
Use Difference as the class name
Powerpoint Templates
Page 58
2. Create a program that will get the
average of 35, 42 and 23. Then display
the result.
Use Average as the class name.
Powerpoint Templates
Page 59
3. Create a program that will get the
product of 18 and 15. Then display the
result.
Use Product as the class name.
Powerpoint Templates
Page 60
4. Create a program that will get the
quotient of 185 and 13. Then display
the result.
Use Quotient as the class name.
Powerpoint Templates
Page 61
public class Difference
{
public static void main (String[]args)
{
int num1=150;
int num2=75;
int difference;
difference=num1-num2;
System.out.println(The difference is:
+difference);
}
}
Powerpoint Templates
Page 62
The difference is 75.
Powerpoint Templates
Page 63
public class Average
{
public static void main (String[]args)
{
int num1=35;
int num2=42;
int num3=23;
double ave;
ave=(num1+num2+num3)/3;
System.out.println(The average is: +ave);
}
}
Powerpoint Templates
Page 64
The average is 33.33
Powerpoint Templates
Page 65
public class Product
{
public static void main (String[]args)
{
int num1=18;
int num2=15;
int product;
product=num1*num2;
System.out.println(The average is: +product);
}
}
Powerpoint Templates
Page 66
The product is 270.
Powerpoint Templates
Page 67
public class Quotient
{
public static void main (String[]args)
{
int num1=185;
int num2=13;
int quotient;
quotient=num1/num2;
System.out.println(The quotient is: +quotient);
}
}
Powerpoint Templates
Page 68
The quotient is 14.23
Powerpoint Templates
Page 69
public class Sample
{
public static void main (String [] args)
{
System.out.println(Melanie Cruz);
}
}
Powerpoint Templates
Page 70