240 likes | 254 Views
Road to Object Oriented Programming. Advanced programming ce244 Sharif University of Technology Feb 2007. Outline. Deadlines Objects Object Oriented Languages Editing your first java program Compiling, running and debugging Homework. Deadlines. By the end of the week you should have :
E N D
Road to Object Oriented Programming Advanced programming ce244 Sharif University of Technology Feb 2007 Taha Abachi
Outline • Deadlines • Objects • Object Oriented Languages • Editing your first java program • Compiling, running and debugging • Homework Taha Abachi
Deadlines By the end of the week you should have : • The Java CD • Java installed on your machines • Edited, run, debugged your first Java programs without any trouble • Examined Java IDEs Taha Abachi
Objects • Abstraction • Programming languages • Problem space • Definition • State : internal data • Behavior : methods • Identity : each object can be uniquely distinguished from every other object Taha Abachi
Features of an Object • An object has an interface • An object provides services • The hidden implementation • Data encapsulation • Reusing the implementation • Inheritance:reusing the interface Taha Abachi
Features of an Object (cont’d) • Sample object • Date : • Day : 1..31 • Month : 1..12 • Year : 1300..1500 • Problems • Inconsistent data: no dependency to other fields • Day := 32 • Inflexible representation • Date : longint Date := 28351 days passed after a specific date Taha Abachi
Features of an Object (cont’d) • Clients of the code • Yourself • Teammates • Customers • An infant programmer • Solution :Separating implementation form interface • More Secure and flexible Taha Abachi
Object Oriented Languages • Everything is an object. • A program is a bunch of objects telling each other what to do by sending messages. • Each object has its own memory made up of other objects. • Every object has a type. • All objects of a particular type can receive the same messages. Taha Abachi
Installing Java • Install JDK • Install Java Documentation • API(Application programming Interface) • Set Environment variables • Choose a text editor Taha Abachi
Java Characteristics • Portability : • compile programs to a intermediary format called JBC C:\>javac HelloWorld.java to produce HelloWorld.class • Interpreting : JVM Taha Abachi
Portability Taha Abachi
Java is Object Oriented • Every thing in Java is an Object. • Objects in OOP mirror the properties and behavior of the real world objects. • They have their own set of data and functions (called method) that operate on these data. Taha Abachi
First Program in Java • Use a text editor • Write down your program • Java is case sensitive • Compile your program • Run Taha Abachi
HelloWorld public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World"); } } Taha Abachi
Java program files • Each class is saved in a file of the same name with java extension. • Note java is case sensitive language, even as far as the class file names are concerned. • The Hello class should be saved in a file called HelloWorld.java class . Taha Abachi
Syntax Highlighting public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World"); } } Taha Abachi
The method main ( ) • The main() method is the point where a Java program starts running. • Any executable Java class must have the main() method in this specific format: public static void main(String[ ] args){ ………….. ………….. } Taha Abachi
Time to compile • Use javac command to compile your java programms : C:\> javac HelloWorld.java HelloWorld.class (JBC file) is created • You may face some errors • Correct erroneous parts and compile again Taha Abachi
Run • The Java command is used to run the class (JBC) file: c:\> Java HelloWorld Taha Abachi
Congratulations You are a Java programmer NOW! Taha Abachi
Java Development Environments • Sun's JDK is not an environment. • Sun's Java Workshop • Microsoft's Visual J++ • Symantec's Cafe • Borland's J Builder • Metrowerks' Code Warrior • Tek-Tools' Kawa. Taha Abachi
Java Development Environments • My candidates : • IntelliJ IDEA • Eclipse • Textpad Taha Abachi
Homework • Install Java properly • Write and Test you first Java program • Design an object oriented environment for manipulating geometrical shapes : • Different subtypes (square, circle, etc.) • Common characteristics (fields & methods) • Particular characteristics • Use UML (Unified Modeling Language) notation Taha Abachi
Questions? Taha Abachi