Road to Object Oriented Programming Advanced programming ce244 Sharif University of Technology Feb 2007 Sunday, February 18, 2007 Taha Abachi
Outline Deadlines Objects Object Oriented Languages Editing your first java program Compiling, running and debugging Homework 5/5/2019 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 5/5/2019 Taha Abachi
Objects Abstraction Definition Programming languages Problem space State : internal data Behavior : methods Identity : each object can be uniquely distinguished from every other object 5/5/2019 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 5/5/2019 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 5/5/2019 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 5/5/2019 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. 5/5/2019 Taha Abachi
Installing Java Install JDK Install Java Documentation API(Application programming Interface) Set Environment variables Choose a text editor 5/5/2019 Taha Abachi
Java Characteristics Portability : Interpreting : JVM compile programs to a intermediary format called JBC C:\>javac HelloWorld.java to produce HelloWorld.class Interpreting : JVM 5/5/2019 Taha Abachi
Portability 5/5/2019 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. 5/5/2019 Taha Abachi
First Program in Java Use a text editor Write down your program Java is case sensitive Compile your program Run 5/5/2019 Taha Abachi
HelloWorld public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World"); } 5/5/2019 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 . 5/5/2019 Taha Abachi
Syntax Highlighting public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World"); } 5/5/2019 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){ ………….. } 5/5/2019 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 5/5/2019 Taha Abachi
Run The Java command is used to run the class (JBC) file: c:\> Java HelloWorld 5/5/2019 Taha Abachi
You are a Java programmer NOW! Congratulations You are a Java programmer NOW! 5/5/2019 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. 5/5/2019 Taha Abachi
Java Development Environments My candidates : IntelliJ IDEA Eclipse Textpad 5/5/2019 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 5/5/2019 Taha Abachi
Questions? 5/5/2019 Taha Abachi