엄현상 (Eom, Hyeonsang) School of Computer Science and Engineering Seoul National University COPYRIGHTS 2017 EOM, HYEONSANG ALL RIGHTS RESERVED

Similar documents
Computer Programming Lecture 11 이윤진서울대학교

엄현상 (Eom, Hyeonsang) School of Computer Science and Engineering Seoul National University COPYRIGHTS 2015 EOM, HYEONSANG ALL RIGHTS RESERVED

Chapter 4 Java Language Fundamentals

Introduction to Visual Basic and Visual C++ Introduction to Java. JDK Editions. Overview. Lesson 13. Overview

Introduction to Java

Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub

Outline. Overview. Control statements. Classes and methods. history and advantage how to: program, compile and execute 8 data types 3 types of errors

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

Chapter 4 Defining Classes I

Introduction to Programming Using Java (98-388)

CS321 Languages and Compiler Design I. Winter 2012 Lecture 2

CSCE3193: Programming Paradigms

THE CONCEPT OF OBJECT

Java for Programmers Course (equivalent to SL 275) 36 Contact Hours

Outline. Java Models for variables Types and type checking, type safety Interpretation vs. compilation. Reasoning about code. CSCI 2600 Spring

Java How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved.

Lecture 1: Overview of Java

Atelier Java - J1. Marwan Burelle. EPITA Première Année Cycle Ingénieur.

Short Notes of CS201

2. The object-oriented paradigm!

C10: Garbage Collection and Constructors

CS201 - Introduction to Programming Glossary By

Learning objectives. The Java Environment. Java timeline (cont d) Java timeline. Understand the basic features of Java

Distributed Information Processing

From C++ to Java. Duke CPS

CHAPTER 7 OBJECTS AND CLASSES

Java Primer 1: Types, Classes and Operators

CHAPTER 7 OBJECTS AND CLASSES

Crash Course in Java. Why Java? Java notes for C++ programmers. Network Programming in Java is very different than in C/C++

PIC 20A The Basics of Java

Assumptions. History

Class, Variable, Constructor, Object, Method Questions

Object Orientation Fourth Story. Bok, Jong Soon

Chapter 6 Introduction to Defining Classes

Lecture 1: Object Oriented Programming. Muhammad Hafeez Javed

CMSC 132: Object-Oriented Programming II

Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson

Agenda. CSE P 501 Compilers. Java Implementation Overview. JVM Architecture. JVM Runtime Data Areas (1) JVM Data Types. CSE P 501 Su04 T-1

AP Computer Science Chapter 10 Implementing and Using Classes Study Guide

Games Course, summer Introduction to Java. Frédéric Haziza

Chapter 1 Introduction to Java

Index. Course Outline. Grading Policy. Lab Time Distribution. Important Instructions

CSE P 501 Compilers. Java Implementation JVMs, JITs &c Hal Perkins Winter /11/ Hal Perkins & UW CSE V-1

Programming Language Concepts: Lecture 2

Java: introduction to object-oriented features

Operating Systems CMPSCI 377, Lec 2 Intro to C/C++ Prashant Shenoy University of Massachusetts Amherst

Java. Classes 3/3/2014. Summary: Chapters 1 to 10. Java (2)

1 Shyam sir JAVA Notes

Certified Core Java Developer VS-1036

Chapter 2: Java OOP I

1. Java is a... language. A. moderate typed B. strogly typed C. weakly typed D. none of these. Answer: B

15CS45 : OBJECT ORIENTED CONCEPTS

StackVsHeap SPL/2010 SPL/20

Paytm Programming Sample paper: 1) A copy constructor is called. a. when an object is returned by value

CS260 Intro to Java & Android 02.Java Technology

COMP 250 Winter 2011 Reading: Java background January 5, 2011

COP 3330 Final Exam Review

Selected Questions from by Nageshwara Rao

CSE 421 Course Overview and Introduction to Java

Objects and Classes. Basic OO Principles. Classes in Java. Mark Allen Weiss Copyright 2000

Java Programming. MSc Induction Tutorials Stefan Stafrace PhD Student Department of Computing

OOSD. Introduction to JAVA. Giuseppe Lipari Scuola Superiore Sant Anna Pisa. September 12, 2011

Character Stream : It provides a convenient means for handling input and output of characters.

Index COPYRIGHTED MATERIAL

Final CSE 131B Spring 2004

Inheritance. Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L

Java Overview An introduction to the Java Programming Language

Review questions. Review questions, cont d. Class Definition. Methods. Class definition: methods. April 1,

Kickstart Intro to Java Part I

Answer1. Features of Java

The Java programming environment. The Java programming environment. Java: A tiny intro. Java features

Sample Copy. Not for Distribution.

Introduction to Java. Lecture 1 COP 3252 Summer May 16, 2017

CS 251 Intermediate Programming Methods and Classes

CS 251 Intermediate Programming Methods and More

Java Fundamentals (II)

Lecture 6 Introduction to Objects and Classes

Introduction to Java. Nihar Ranjan Roy.

B2.52-R3: INTRODUCTION TO OBJECT ORIENTATED PROGRAMMING THROUGH JAVA

Chapter 1 GETTING STARTED. SYS-ED/ Computer Education Techniques, Inc.

C11: Garbage Collection and Constructors

CHETTINAD COLLEGE OF ENGINEERING & TECHNOLOGY JAVA

OOSD. Introduction to JAVA. Giuseppe Lipari Scuola Superiore Sant Anna Pisa. September 29, 2010

Object Oriented Design

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

CLASS DESIGN. Objectives MODULE 4

Implementing Higher-Level Languages. Quick tour of programming language implementation techniques. From the Java level to the C level.

Programming overview

public class Foo { private int var; public int Method1() { // var accessible anywhere here } public int MethodN() {

Unit 4 - Inheritance, Packages & Interfaces

S.E. Sem. III [CMPN] Object Oriented Programming Methodology

Introduction to Java. Handout-1d. cs402 - Spring

Chapter 4: Threads. Operating System Concepts 9 th Edit9on

Programming Language Concepts: Lecture 2

Software Development & Education Center. Java Platform, Standard Edition 7 (JSE 7)

Objects, Distribution, and the Internet. Update on Java. Introduction, fundamentals and basic concepts. Outline

CISC370: Inheritance

Modern Programming Languages. Lecture Java Programming Language. An Introduction

Java Basics. Object Orientated Programming in Java. Benjamin Kenwright

Chapter 5: Procedural abstraction. Function procedures. Function procedures. Proper procedures and function procedures

Transcription:

엄현상 (Eom, Hyeonsang) School of Computer Science and Engineering Seoul National University COPYRIGHTS 2017 EOM, HYEONSANG ALL RIGHTS RESERVED

Outline - Questionnaire Results - Java Overview - Java Examples - C++ vs java - Q&A COPYRIGHTS 2017 EOM, HYEONSANG ALL RIGHTS RESERVED

Java Overview Object-Oriented Programming Language (OOPL) by Sun in 1991 Programming with One or More Classes Simple Structure w/o header files, preprocessor, struct, operator overloading, multiple Inheritance, pointers, etc. Garbage Collection No need to delete or return any storage Dynamic Loading Classes being loaded as needed Platform Independence Java Virtual Machine (JVM) Multithreading Support for multiple threads of execution

Some Differences with C/C++ Automatic Memory Management Garbage Collector No Dangling Pointers or Memory Leaks No Pointer Handling No Explicit Reference/Dereference Operations No Makefiles No Header Files cf, imported Packages No Function Declaration (Similar to C) No Default Function Argument

Java Platform S/W Platform for Running Java - on Top of any Platforms Java Virtual Machine (JVM) Java Application Programming Interface (Java API) Java Platform Java Program Java API Java Virtual Machine Underlying Platform Collection of ready-made software components - grouped into Packages of classes and interfaces)

Java Interpreter Implementation of the JVM Executing Java Bytecodes Java bytecodes can be considered as intermediate code instructions for the JVM Java programs, once compiled into bytecodes, can be run on any JVM

How a Java Program Runs Compilation and Interpretation Compiler First Translates a Java Program into Java Bytecodes Once Interpreter Parses and Runs Each Java Bytecode Instruction Multiple times on different platforms

Java Program Saved in Files, Each of Which Has the Same Name as the public Class Containing Only One public Class Containing Other Non-public Classes

Memory Layout of a Java Program

Class Unit of Programming Java Program: a Collection of Classes Source code in.java files Description (Blueprint) of Objects (Instances) Common Characteristics Instances Have These Characteristics Attributes (Data Fields) for Each Object Methods (Operations) That Work on the Objects

Member Access Control Way to Control Access to a Class Members from Other Classes private Accessible only in the class itself Default (package or friendly) Accessible in the same-package subclasses of the class or in the classes of the same package protected Accessible in the subclasses of the class or in the classes of the same package public Accessible everywhere

Object Instance of a Class Uniquely Identifiable Entity w/ Its State, Behavior, and Interface Maintaining Data Values in Its Attributes Referenced by a Reference Variable (of Reference Type) Inheriting from the Class Object w/ a number of methods tostring(), equals(), &, clone()

Managing Objects Referencing Objects of Specified Types Objects Created by the new Operator Creating Objects by Executing the Constructors Constructor (Function) Overloading Deleting Objects via Garbage Collection Reference Count for Each Object Cleanup occurs at the convenience of the Java runtime environment

Java Example: Abstraction Online Retailer Such as Amazon.Com Item: Type, Title, Maker, Price, Availability, etc. class Item { // Class definition Attribute of the class public String title; // String is a predefined class public double price; // double is a primitive data type public double SalePrice(){ return (price * 0.9); Method of the class Item A = new Item(); // Class object definition and creation // OKAY : A.title, A.price, and A.SalePrice() Variable of reference type

Java Example: Encapsulation Online Retailer Example Cont d class Item { public String title; public double price; private int instockquantity; public double SalePrice(){ return (price * 0.9); public boolean isavailable(){ if(instockquantity > 0) return true; else return false; Item A = new Item(); // Class object definition and creation // NOT OKAY: A.inStockQuantity // OKAY: A.isAvailable() instockquantity attribute is not accessible outside of the Item class

Java Example: Inheritance Online Retailer Example Cont d class MusicCDItem extends Item { public String singer_name; // Class object definition and creation MusicCDItem B = new MusicCDItem; Item MusicCDItem // OKAY: B.singer_name, B.title, B.price, B.SalePrice(), // and B.isAvailable() // NOT OKAY: B.inStockQuantity

Java Example: Polymorphism Online Retailer Example Cont d class Item { public String title; public double price; private int instockquantity; public double SalePrice(){ return (price * 0.9); public boolean isavailable(){ if(instockquantity > 0) return true; else return false; public void specificinfo() { System.out.println("no info: a base-class object");

Java Example: Polymorphism Cont d class MusicCDItem extends Item { public String singer_name; public void specificinfo(){ System.out.println("signer name=" + singer_name + " : a derived-class object"); public class OnlineRetailer { static void printspecificinfo(item Item){item.specificInfo(); public static void main(string args[]){ Item A = new Item(); MusicCDItem B = new MusicCDItem(); printspecificinfo(a); // Call Item.specificInfo() printspecificinfo(b); // Call MusicCDItem.specificInfo() // - Another derived class (e.g., MovieDVDItem) with specificinfo()

Static Modifier Use: Static Attributes & Static Methods Features All Classes Share Static Members It Is Possible to Invoke Static Methods w/o Instantiation In Static Methods, It Is Allowed to Access Non-Static Data or Non-Static Methods of Classes after the Instantiation of the Objects class A{ private int i = 5; public static printi(){ System.out.println(i); System.out.println(new A().i); // error!

Static Modifier Cont d Differences between C++ and Java Static Method Invocation C++ : Class::method(); Java : Class.method(); Static Data Member Initialization C++ : No In-Class Initialization (ANSI/ISO) Java : In-Class Initialization class A{ C++ class A{ JAVA public: public static int i = 10; static int i; // declare int A::i = 0; // define & initialize

Locating Classes Filesystem Names Consist of: CLASSPATH Environment Variable Set to a List of Pathnames: Separated by ; in autoexec.bat on Windows Separated by : in a Shell Initialization File on Unix/Linux Package Name» Bash: $ export CLASSPATH=/a:/a/Java/:. Name of a Collection of Individual.class Files in a Directory Class Name

Locating Classes Cont d CLASSPATH Tells the Class Loader Where to Begin Looking for All Possible Starting Places Take the Full Name Including the Package Name, e.g., Java.d1.j11 Replace the Dots with / or \ and Suffix with.class, e.g., Java/d1/j11.class Concatenate It onto Each Element of the CLASSPATH /a/java/d1/j11.class /a/java/java/d1/j11.class./java/d1/j11.class

Locating Classes Cont d Package Statement (at the Top of Each Source File) Which Package the Class Belongs to package packagename; E.g., package d1; (with /a/java as an element of CLASSPATH) Import Statement Permitting Using a Class Name Directly import packagename.classname; E.g., import d1.j11; (with /a/java as an element of CLASSPATH)

Example: Locating Classes CLASSPATH=/a:/a/Java:. Current Directory: /a/java/d1 File j11.java // package d1; public class j11 { protected static int i = 1; File j12.java // package d1; // import d1.j11; public class j12 extends j11 { public static void main(string args[]) { System.out.println("i = " + i); i = 1

Example: Locating Classes CLASSPATH=/a:/a/Java:. /a/java/d1/j11.java package d1; public class j11 { protected static int i = 1; Cont d /a/java/d2/j15.java package d2; import d1.j11; public class j15 extends j11 { public static void main(string args[]) { System.out.println("i = " + i); i = 1 Error javac d. j15.java../d1/j11.java