Umesh Patidar PPT On Java Final PPT 011
Umesh Patidar PPT On Java Final PPT 011
Sagar, Madhya-Pradesh
College
Internship Presentation on
• if (x < y) smaller = x;
• if (x < y){ smaller=x;sum += x;}
else { smaller = y; sum += y; }
• while (x < y) { y = y - x; }
• do { y = y - x; } while (x < y)
• for (int i = 0; i < max; i++) sum += i;
Control statements II
switch (n + 1) {
case 0: m = n - 1; break;
case 1: m = n + 1;
case 3: m = m * n; break;
default: m = -n; break;
}
• Java also introduces the try statement, about which more later
Java isn't C!
import java.awt.*;
import java.util.*;
public class SomethingOrOther {
// object definitions go here
...
}
• A class consists of
• a collection of fields, or variables, very much like the named fields of a struct
• all the operations (called methods) that can be performed on those fields
• can be instantiated
• A class describes objects and operations defined on those objects
An example of a class
class Person {
String name;
int age;
void birthday ( ) {
age++;
System.out.println (name + ' is now ' + age);
}
}
Another example of a class
• Person john;
john = new Person ( );
john.name = "John Smith";
john.age = 37;
• Person mary = new Person ( );
mary.name = "Mary Brown";
mary.age = 33;
mary.birthday ( );
An array is an object