Download presentation
Presentation is loading. Please wait.
Published byRose Hutchinson Modified over 8 years ago
1
Topics introduced today (these topics would be covered in more detail in later classes) – Primitive Data types Variables Methods “for” loop “if-else” statement Introduce “String” object Exercise 1 would be posted
2
Primitive data types in Java: byte (8 bits) short (16 bits) int (32 bits) long (64 bits) float (32 bit single precision) double (64 bit double precision) boolean (true/false value) char (16 bit Unicode character)
3
Examples of variable declaration(initialization is optional): boolean result = true; char capitalC = 'C'; byte b = 100; short s = 10000; int i = 100000;
4
Method declaration has 6 components modifier (public/private) return type method name parameter list exception list( will be discussed later ) method body
5
Example for method declaration: public int add(int a, int b) { return a+b; }
6
The ‘for’ loop: for( ; ; increment) { //program statements. }
7
If-then statement: if( ) { //program statements. } else { //program statements. }
8
If-then-else statement: if( ) { //program statements. } else if( ) { //program statements. } else { //program statements. }
9
‘String’ – the string class represents character strings. String str = “abc”; String str = new(“abc”);
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.