Computer History Notes - Herong's Tutorial Notes - v3.13, by Herong Yang
Java Is an Object-Oriented Language
This section provides a quick demonstration of the object-oriented programming nature of Java language.
Java is an object-oriented programming language.
What Is an Object? An object is a data instance of a user defined data type, which contains properties and methods.
What Is a Class? A class is a user defined data type which contains properties and methods.
Here is a sample Java program modified from Sun's "The Java Tutorials":
/* ObjectDemo.java
* Copyright (c) 2003 HerongYang.com. All Rights Reserved.
*/
class ObjectDemo {
public static void main(String[] args) {
// Creating 2 objects from the "Bicycle" class
Bicycle bike1 = new Bicycle();
Bicycle bike2 = new Bicycle();
// Working with the first object
bike1.changeCadence(50);
bike1.speedUp(10);
bike1.changeGear(2);
bike1.printStates();
// Working with the second object
bike2.changeCadence(50);
bike2.speedUp(10);
bike2.changeGear(2);
bike2.changeCadence(40);
bike2.speedUp(10);
bike2.changeGear(3);
bike2.printStates();
}
// Defining a class
private static class Bicycle {
// Defining properties
int cadence = 0;
int speed = 0;
int gear = 1;
// Defining methods
void changeCadence(int newValue) {
cadence = newValue;
}
void changeGear(int newValue) {
gear = newValue;
}
void speedUp(int increment) {
speed = speed + increment;
}
void applyBrakes(int decrement) {
speed = speed - decrement;
}
void printStates() {
System.out.println("Cadence: "+cadence);
System.out.println("Speed: "+speed);
System.out.println("Gear: "+gear);
}
}
}
If you run this Java sample program, you will get:
Cadence: 50 Speed: 10 Gear: 2 Cadence: 40 Speed: 20 Gear: 3
Table of Contents
2002 - .NET Framework Developed by Microsoft
1995 - PHP: Hypertext Preprocessor Created by Rasmus Lerdorf
►1995 - Java Language Developed by Sun Microsystems
Java Compilation and Execution Processes
►Java Is an Object-Oriented Language
Java Supports Automatic Garbage Collection
Java Supports Multi-Threading Programming
1991 - WWW (World Wide Web) Developed by Tim Berners-Lee
1991 - Gopher Protocol Created by a University of Minnesota Team
1984 - X Window System Developed a MIT Team
1984 - Macintosh Developed by Apple Inc.
1983 - "Sendmail" Mail Transfer Agent Developed by Eric Allman
1979 - The Tcsh (TENEX C Shell) Developed by Ken Greer
1978 - Bash (Bourne-Again Shell) Developed by Brian Fox
1978 - The C Shell Developed by Bill Joy
1977 - The Bourne Shell Developed by Stephen Bourne
1977 - Apple II Designed by Steve Jobs and Steve Wozniak
1976 - vi Text Editor Developed by Bill Joy
1974 - Internet by Vinton Cerf
1972 - C Language Developed by Dennis Ritchie
1971 - FTP Protocol Created by Abhay Bhushan
1970 - UNIX Operating System Developed by AT&T Bell Labs