Introduction to java - PowerPoint PPT Presentation

dutch
data structure java programming 1 n.
Skip this Video
Loading SlideShow in 5 Seconds..
Introduction to java PowerPoint Presentation
Download Presentation
Introduction to java

play fullscreen
1 / 30
Download Presentation
Introduction to java
160 Views
Download Presentation

Introduction to java

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. Min Chen School of Computer Science and Engineering Seoul National University Data Structure: Java Programming 1 Introduction to java

  2. Content • Overview of Java • Integrated Development Environment (IDE) • Install Java SE • Introduction to Eclipse • Setup your IDE in Windows • Start a new Java Project • Object-Oriented Programming • Concept of Class • Method in Class • Class in Java Programming

  3. Overview of Java • Began as an internal project in 1990 • Named “Oak” first • Sun Microsystem • Providing an alternative to the C++/C • Re-target Java to Internet in 1994 • Versions • Java Card • Java ME (Micro Edition) • Java SE (Standard Edition) • Java EE (Enterprise Edition)

  4. Features of Java • Object-Oriented Programming Language • Write Once, Run Anywhere • Java Virtual Machine (VM) Java Code (.java) Java Binary Files (.class) Compiler Java VM Runtime Interpreting Java Developer’s Kit (JDK) Machine Code

  5. Install Java SE JDK • Website: • http://www.java.com/en/download/manual.jsp

  6. IDE: Eclipse Integrated Development Environment • A powerful IDE for Java development • As Microsoft Visual C++ for C++/C Development • Totally Free of Use !!! • A large number of Plug-in • Enable C++ development • Enable Website Design • … …

  7. Eclipse: Download • Website: • http://www.eclipse.org/downloads/

  8. Start Eclipse • Steps • Extract the zip file into your hard disk • Double click to run “eclipse.exe” • Select your workspace directory

  9. Start a new Java Project

  10. Writing Code for HelloWorld public static void main(String args[]) { System.out.print("Hello World in Java!"); }

  11. HelloWorld: Result

  12. Object-Oriented Programming • Process-Oriented Programming • Focus on a flow process • Separates the concerns of data structures and the concurrent processes that act upon them • Object-Oriented Programming • Uses "objects" – data structures consisting of datafields and methods together with their interactions – to design applications • Feature • Information hiding, Data abstraction, Encapsulation, Modularity, Polymorphism, Inheritance

  13. Object-Oriented Programming • Example: Gobang Game (five-in-a-row) Object-Oriented Programming: Process-Oriented Programming: Start Judgment System Black Turn Draw chessboard Y Black Win ? Chessboard System N White Turn Draw chessboard N White Win ? Black Player White Player Y End

  14. Process-Oriented Programming • Focus on the flow of the work • The basis of programming • if… else… • Loop • Function • Recursion

  15. Function Type of Return Value Name of the method Parameters for the method • Usually called “Method” in Java public int larger (int a, int b) { if(a>b) return a; else return b; } Privilege of the method

  16. Recursion • Fibonacci Number • 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, … The function calls itself Towers of Hanoi

  17. Concept of Class CEOs Attribute • Example 1 Name Gender Age Place of Birth Company Products

  18. Concept of Class (cont.) Sportsmen • Example 2 Name Gender Age Place of Birth Employer Sports League

  19. Concept of Class (cont.) Stars • Example 3 Name Gender Age Place of Birth School Drama

  20. Inheritance of Class People Name • Higher Abstract Gender Superclass Age Place of Birth Subclass Sportsmen Stars CEOs Name Name Name Gender Gender Gender Age CEOs Sportsmen Stars Age Age Place of Birth Place of Birth Place of Birth School Employer Employer Company Company School Drama Sports Sports Products Products Drama League League Subclass will inherit most of the attributes of his superclass

  21. Method in Class • A class is not just a collection of data (we call it attribute), but also a collection of methods • Method • As the function in C++/C • Define procedure with input and output • Example: • People • Think() • Eat() • Sleep()

  22. Method Inheritance • Methods also can be inherited Multiple Level Inheritance is allowed Human Animals Creatures Plans Think ( ) Eat( ) Survive( ) photosynthesis( ) Talk ( ) Sleep( ) Love ( )

  23. Overwrite of Methods • So how about the situation below ? Circle c = new Circle(); c.Draw(); Circle Shape Center Describe( ) Radius Draw( ) Draw( )

  24. Overload of Methods • Can we have two methods with the same name but different parameters in one class ? Public Class Overload public void get() { System.out.print(“No parameters!”); } public void get(int par) { System.out.print(“Has parameter of ”+ par); } No parameters! Has parameter of 32 Overload ol= new Overload(); ol.get(); ol.get(32);

  25. Summary of Class • Consist of Attributes and Methods • Represents a collection of data and functions which have relationship to each other • Other features • Information hiding • Data abstraction • Encapsulation • Modularity • Polymorphism • Inheritance

  26. Class in Java Programming • Personally, I classify the Classes in Java Programming into two types: • Entrance Class (Project Class) • With main method in the Class • The entrance and control center of the whole program • Accessories Class • Provide functional part • Call in the main function to create instance HelloWorld.java is an Entrance Class The method in Accessories Class being called should be public!

  27. Example Constructed Function: Run when the object is initiated • CEO Class Define the attributes for Class CEO Set to be public so that the function in CEO can be called in other Class

  28. Example (cont.) • HelloWorld Class Reset the name of the instance by the method setName in Class CEO Get the name of the instance by the method getName in Class CEO Create an instance (steve) of Class CEO

  29. Example Result • The system print out: Hello World in Java! My name is Steve Jobs

  30. Thank you