Date post: | 19-Dec-2015 |
Category: |
Documents |
View: | 223 times |
Download: | 2 times |
INTRODUCTION TO JAVAData Structure: Java Programming 1
Min ChenSchool of Computer Science and Engineering
Seoul National University
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
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)
Features of Java
Object-Oriented Programming Language
Write Once, Run Anywhere Java Virtual Machine (VM)
Machine Code
Java VM
Java Binary Files
(.class)
Java Code (.java)
Compiler
Java Developer’s Kit (JDK)
RuntimeInterpreting
Install Java SE JDK Website:
http://www.java.com/en/download/manual.jsp
IDE: Eclipse
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 … …
Integrated Development Environment
Start Eclipse Steps
1. Extract the zip file into your hard disk2. Double click to run “eclipse.exe”3. Select your workspace directory
Writing Code for HelloWorld
public static void main(String args[]){ System.out.print("Hello World in Java!");}
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
Object-Oriented Programming Example: Gobang Game (five-in-a-
row)Start
Black Turn
Draw chessboard
Black Win ?
End
White TurnDraw
chessboard
White Win ?
Y
N
Y
N
Process-OrientedProgramming:
Object-OrientedProgramming:
ChessboardSystem
JudgmentSystem
White Player
Black Player
Process-Oriented Programming Focus on the flow of the work The basis of programming
if… else… Loop Function
Recursion
Function
Usually called “Method” in Java
public int larger (int a, int b) { if(a>b) return a; else return b; }
Type of Return Value
Name of the method
Parameters for the method
Privilege of the method
Recursion
Fibonacci Number 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144,
…
1
1
0
,
,
,
)2()1(
1
0
)(
x
x
x
xfxf
xf
The function calls itself
Towers of Hanoi
Concept of Class
Example 1
Name: Bill Gates
Gender: Male
Age: 54
Born: U.S.
Company:
Microsoft
Products:
Windows, Office…
Name: Steve Jobs
Gender:
Male
Age: 54
Born: U.S.
Company:
Apple Inc.
Products:
Mac, iPod, iPhone…
CEOsName
Gender
AgePlace of
BirthCompany
Products
Attribute
Concept of Class (cont.)
Example 2Name: 박지성Gender: Male
Age: 28
Born: Korea
Employer:
Man. United
Sports: Football
League: Premier
Name: Yao Ming
Gender: Male
Age: 29
Born: China
Employer:
Rockets
Sports: Basketball
League: NBA
SportsmenName
Gender
AgePlace of
BirthEmployer
Sports
League
Name: 이병헌Gender: Male
Age: 39
Born: Korea
School: 중앙대Drama: All In,
Iris
Name: 김태희Gender: Female
Age: 29
Born: Korea
School: 서울대Drama: Love
Story in Harvard, Iris
Concept of Class (cont.)
Example 3
StarsName
Gender
AgePlace of
BirthSchool
Drama
Inheritance of Class
Higher Abstract
CEOsName
Gender
AgePlace of
BirthCompany
Products
SportsmenName
Gender
AgePlace of
BirthEmployer
SportsLeague
StarsName
Gender
AgePlace of
BirthSchool
DramaCEOs
Company
Products
SportsmenEmployer
SportsLeague
StarsSchool
Drama
PeopleName
Gender
AgePlace of
Birth
Superclass
Subclass
Subclass will inherit most of the attributes of his superclass
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()
Method Inheritance
Methods also can be inherited
HumanThink ( )Talk ( )Love ( )
AnimalsEat( )
Sleep( )
CreaturesSurvive( )
Plansphotosynthesi
s( )
Multiple Level Inheritance is allowed
Overwrite of Methods
So how about the situation below ?
CircleCenterRadiusDraw( )
ShapeDescribe
( )Draw( )
Circle c = new Circle(); c.Draw();
Overload of Methods
Can we have two methods with the same name but different parameters in one class ?
public void get() { System.out.print(“No parameters!”); }
public void get(int par) { System.out.print(“Has parameter of ”+ par); }
Overload ol= new Overload(); ol.get(); ol.get(32);
Public Class Overload
No parameters!Has parameter of 32
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
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!
Example CEO Class
Constructed Function:Run when the object is
initiated
Define the attributes for
Class CEO
Set to be public so that the function in CEO can be called in
other Class
Example (cont.) HelloWorld Class
Create an instance (steve)
of Class CEO
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