Object Oriented Programming with Java

Size: px
Start display at page:

Download "Object Oriented Programming with Java"

Transcription

1 CSC System Development with Java Object Oriented Programming with Java Department of Statistics and Computer Science 1

2 Advantages of OOP Provides a clear modular structure for programs OOP makes it easy to maintain and modify existing code (new objects can be created with small differences to existing ones) OOP provides a good framework for code libraries Software components can be easily adapted and modified by the programmer. 2

3 Concepts of OOP Objects Classes Data Abstraction Encapsulation Inheritance Polymorphism 3

4 What is an Objects? Object is a software bundle of related state and behavior Characteristics: state and behavior 4

5 What is a class? A Java class is a group of Java methods and variables Object is an instance of a class 5

6 Object Oriented Concepts 6

7 Constructors Very similar to C++ You can create multiple constructors, each must accept different parameters. If you don't write any constructor, the compiler will (in effect) write one for you: classname() {} If you include any constructors in a class, the compiler will not create a default constructor! 7

8 Multiple Constructors One constructor can call another. You use "this", not the classname: class Foo { int i; Foo() { } this(0); Foo( int x ) { } i = x; A call to this must be the first statement in the constructor! 8

9 Destructors No! There is a finalize() method that is called when an object is destroyed. you don't have control over when the object is destroyed (it might never be destroyed). The JVM garbage collector takes care of destroying objects automatically (you have limited control over this process). 9

10 Class Modifiers Public Abstract Final Default (none) 10

11 Class Modifiers public: anyone can create an object of the defined class. only one public class per file, must have same name as the file (this is how Java finds it!). default: is non-public (if you don't specify "public"). 11

12 Class Modifiers Abstract: modifier means that the class can be used as a superclass only. no objects of this class can be created. Final: if its definition is complete and no subclasses are desired or required a final class never has any subclasses, the methods of a final class are never overridden 12

13 Field Modifiers public protected private none or package or default Static Final 13

14 Field Modifiers public: any method (in any class) can access the field. protected: any method in the same package can access the field, or any derived class. private: only methods in the class can access the field. Default: is that only methods in the same package can access the field. 14

15 Field Modifiers Static: Fields declared static are called class fields (class variables). others are called instance fields. There is only one copy of a static field, no matter how many objects are created. Final:class and instance variables (static and non-static fields) may be declared final. The keyword final means: once the value is set, it can never be changed static final int BUFSIZE=100; final double PI= ; 15

16 Method Modifiers public protected none or package or default private final abstract static native synchronized 16

17 Method Modifiers private/protected/public: same idea as with fields. abstract: no implementation given, must be supplied by subclass. the class itself must also be declared abstract 17

18 Method Modifiers static: the method is a class method, it doesn't depend on any instance fields or methods, and can be called without first creating an object. final: the method cannot be changed by a subclass (no alternative implementation can be provided by a subclass). 18

19 Method Modifiers native: the method is written in some local code (C/C++) - the implementation is not provided in Java. synchronized: only one thread at a time can call the method. 19

20 Method Overloading You can overload methods: same method name, different parameters. you can't just change return type, the parameters need to be different. Method overloading is resolved at compile time. int CounterValue() { return counter; } double CounterValue() { } return (double) counter; Won't Work! 20

21 All Possible Combinations of Features and Modifiers Modifier Class Variable Method Constructor public yes yes yes yes protected no yes yes yes None (default) yes yes yes yes private no yes yes yes final yes yes yes no abstract yes no yes no static no yes yes no native no no yes no transient no yes no no volatile no yes no no synchronized no no yes no strictfp yes no yes yes 21

22 Java Modifier Summary Modifier Used on Class Meaning Contains unimplemented methods and cannot be instantiated abstract interface All interfaces are abstract. Optional in declarations method No body, only signature. The enclosing class is abstract 22

23 Java Modifier Summary Modifier Used on Class Meaning Cannot be subclassed Final method field Cannot be overridden and dynamically looked up Cannot change its value. static final fields are compile-time constants. variable Cannot change its value. 23

24 Java Modifier Summary Modifier Used on Meaning Native method Platform-dependent. No body, only signature Modifier Used on Meaning Private member Accessible only in its class Modifier Used on protected member Meaning Accessible only within its package and its subclasses 24

25 Java Modifier Summary Modifier Used on Meaning Class Accessible only in its package None Interface Accessible only in its package Member Accessible only in its package 25

26 Java Modifier Summary Modifier Used on Class Meaning Accessible anywhere Public interface Accessible anywhere Member Accessible anywhere. 26

27 Java Modifier Summary class Make an inner class top-level class method A class method, invoked through the class name. static field initializer A class field, invoked through the class name one instance, regardless of class instances created. Run when the class is loaded, rather than when an instance is created. 27

28 Packages 28

29 Package defined as a grouping of related types existing packages in Java are: java.lang - bundles the fundamental classes java.io - classes for input, output functions are bundled in this package 29

30 Creating a Package Put a package statement with the package name At the top of every source file that contains the classes, interfaces, enumerations, and annotation types that you want to include in the package The package statement should be the first line in the source file There can be only one package statement in each source file, and it applies to all types in the file 30

31 Example /* File name : Animal.java */ package animals; interface Animal { public void eat(); } package animals; /* File name : MammalInt.java */ public class Mammal implements Animal { public void eat() { System.out.println("Mammal eats"); } Now you compile these two files and put them in a sub-directory called animals 31

32 The Import Keyword If a class wants to use another class in the same package, the package name does not need to be used. Classes in the same package find each other without any special syntax The fully qualified name of the class can be used. import animals.mamal The package can be imported using the import keyword and the wild card (*) import animals.*; 32

33 Abstraction 33

34 Abstraction Refers to the ability to make a class abstract in OOP Abstract class Cannot be instantiated Other functionality of the class still exists Cannot create an instance of the abstract class 34

35 Abstract Class Use the abstract keyword to declare a class abstract public abstract class Employee { } private String name; private String address;... Cannot use Employee e = new Employee(); Employee.java: xx: Employee is abstract; cannot be instantiated Employee e = new Employee(); ^ 1 error1 35

36 Extending Abstract Class public class Salary extends Employee { } private double salary; Salary(String name, String address, { }... int number, double salary) super(name, address, number); setsalary(salary); Call Employee class Extend Employee class 36

37 Abstract Methods Can declare the method in the parent class as abstract Abstract methods consist of a method signature, but no method body public abstract class Employee { private String name; private String address; private int number; public abstract double computepay(); //Remainder of class definition } 37

38 Declaring a Method as Abstract The class must also be declared abstract Any child class must either override the abstract method or declare itself abstract A child class that inherits an abstract method must override it If they do not, they must be abstract,and any of their children must override it 38

39 Salary is Extending Employee class it is required to implement computepay() method public class Salary extends Employee { private double salary; //Annual salary public double computepay() { System.out.println("Computing " + getname()); return salary/52; } //Remainder of class definition } 39

40 Example 40

41 Example(1) Employee Name Address Number computepay() mailcheck() tostring() getname() 41

42 Salary class Employee Salary 42

43 Abstract Demonstration Employee Salary 43

44 Exercise Remove computepay() methods in the Salary class and re-run the program. Change the computepay() as public abstract double computepay() ; And re-run the program Identify the correct usage of the Abstract class Abstract methods 44

45 Encapsulation 45

46 Encapsulation Information Hiding. Don't need to know how some component is implemented to use it. Implementation can change without effecting any calling code. "protects us from ourselves" 46

47 Encapsulation is the technique of making the fields in a class private and providing access to the fields via public methods is also referred to as data hiding Benefit is the ability to modify our implemented code without breaking the code of others who use our code Encapsulation gives maintainability, flexibility and extensibility to our code 47

48 Example public class Encap { private String name; private String idnum; private int age; public int getage() { return age; } public String getname() { return name; } public String getidnum() { return idnum; } public void setage( int newage) { age = newage; } public void setname(string newname) { name = newname; } public void setidnum( String newid) { idnum = newid; } } 48

49 Example public class RunEncap { public static void main(string args[]) { EncapTest encap = new EncapTest(); encap.setname("james"); encap.setage(20); encap.setidnum("12343ms"); } } System.out.println("Name : " + encap.getname()+ " Age : "+ encap.getage()); 49

50 Benefits of Encapsulation: The fields of a class can be made read-only or write-only. A class can have total control over what is stored in its fields. The users of a class do not know how the class stores its data. A class can change the data type of a field, and users of the class do not need to change any of their code. 50

51 Inheritance 51

52 Inheritance On the surface, inheritance is a code re-use issue. we can extend code that is already written in a manageable manner. Inheritance is more, it supports polymorphism at the language level! Information is made manageable in a hierarchical order 52

53 Inheritance cont. With Inheritance, new class can be derived from existing classes as a building block New class Inherit properties and methods from the existing class New class can also added Its own properties and methods Keyword Extends Implements 53

54 Inheritance cont. Take an existing object type (collection of fields and methods) and extend it. create a special version of the code without rewriting any of the existing code (or even explicitly calling it!). End result is a more specific object type, called the sub-class / derived class / child class. The original code is called the super class / parent class / base class. 54

55 IS-A Relationship (Example) public class Animal { } extends Animal public class Mammal extends Animal { } public class Reptile extends Animal { } Mamal public class Dog extends Mammal { } 55

56 IS-A Relationship (Example) public class Dog extends Mammal { public static void main(string args[]) { Animal a = new Animal(); Reptile r = new Reptile(); Mammal m = new Mammal(); Dog d = new Dog(); System.out.println(m instanceof Animal); System.out.println(d instanceof Mammal); System.out.println(d instanceof Animal); } } Animal Mamal Dog Reptile 56

57 IS-A Relationship In Object Oriented terms following are true: Animal is the superclass of Mammal class. Animal is the superclass of Reptile class. Mammal and Reptile are sub classes of Animal class. Dog is the subclass of both Mammal and Animal classes. 57

58 IS-A Relationship IS-A relationship we can say: Mammal IS-A Animal Reptile IS-A Animal Dog IS-A Mammal Hence : Dog IS-A Animal as well Use of the extends keyword the subclasses will be able to inherit all the properties of the superclass except for the private properties of the superclass 58

59 Accessing superclass methods Can use super() to access all (non-private) superclass methods. even those replaced with new versions in the derived class. Can use super() to call base class constructor. 59

60 Single Inheritance You can't extend more than one class! the derived class can't have more than one base class. You can do multiple inheritance with interface inheritance. 60

61 Inheritance Example cont. Employee: name, , phone FulltimeEmployee: also has salary, office, benefits, Manager: CompanyCar, can change salaries, rates contracts, offices, etc. Contractor: HourlyRate, ContractDuration, A manager a special kind of FullTimeEmployee, which is a special kind of Employee. The relationship modeled by inheritance is often referred to as a is a relationship 61

62 Inheritance Example Employee Name Phone FulltimeEmployee Salary Office Manager CompanyCar Phone Contractor HourlyRate, ContractDuration 62

63 Inheritance Example Is a Employee Name Phone Is a FulltimeEmployee Salary Office Manager CompanyCar Phone Is a Contractor HourlyRate, ContractDuration 63

64 Inheritance Example Manager is a full time employee Full time employee is a employee 64

65 HAS-A Relationship relationships are mainly based on the usage determines whether a certain class HAS-A certain thing helps to reduce duplication of code as well as bugs 65

66 Example public class Vehicle {} public class Speed {} public class Van extends Vehicle { private Speed sp; } class Van HAS-A Speed Reuse the Speed class in multiple applications Vehicle Van sp 66

67 Interface 67

68 Interfaces is a collection of abstract methods An interface is not a class A class describes the attributes and behaviors of an object An interface contains behaviors that a class implements 68

69 Interfaces cont. Interfaces have the following properties: An interface is implicitly abstract. You do not need to use the abstract keyword when declaring an interface. Methods in an interface are implicitly public. 69

70 Interfaces cont. An interface is a definition of method prototypes and possibly some constants (static final fields). An interface does not include the implementation of any methods, it just defines a set of methods that could be implemented. 70

71 Implement an interfaces A class can implement an interface, this means that it provides implementations for all the methods in the interface. Java classes can implement any number of interfaces (multiple interface inheritance). 71

72 Interfaces Creation (definition) of interfaces can be done using inheritance: one interface can extend another. Sometimes interfaces are used just as labeling mechanisms: Look in the Java API documentation for interfaces like Cloneable. 72

73 Interfaces An interface is similar to a class in the following ways: An interface can contain any number of methods. An interface is written in a file with a.java extension, with the name of the interface matching the name of the file. The bytecode of an interface appears in a.class file. Interfaces appear in packages, and their corresponding bytecode file must be in a directory structure that matches the package name. 73

74 Interfaces An interface is different from a class in several ways, including: You cannot instantiate an interface. An interface does not contain any constructors. All of the methods in an interface are abstract. An interface cannot contain instance fields. The only fields that can appear in an interface must be declared both static and final. An interface is not extended by a class; it is implemented by a class. An interface can extend multiple interfaces. 74

75 Declaring Interfaces The interface keyword is used to declare an interface public class MammalInt implements Animal { public void eat() { System.out.println("Mammal eats"); } public static void main(string args[]) { MammalInt m = new MammalInt(); m.eat(); } } interface Animal { public void eat(); } 75

76 Extending Interfaces An interface can extend another interface public interface Sports { public void sethometeam(string name); } Sport public interface Football extends Sports { public void hometeamscored(int points); } Football Hockey public interface Hockey extends Sports { public void homegoalscored(); } 76

77 Multiple Interfaces A Java class can only extend one parent class. Multiple inheritance is not allowed An interface can extend more than one parent interface Extends keyword is used once, and the parent interfaces are declared in a comma-separated list. public interface Hockey extends Sports, Event Sports Event Hockey 77

78 The instanceof Keyword the instanceof operator to check determine whether Mammal is actually an Animal, and dog is actually an Animal 78

79 Polymorphism 79

80 Polymorphism is the ability of an object to take on many forms OOP occurs when a parent class reference is used to refer to a child class object 80

81 Polymorphism Create code that deals with general object types, without the need to know what specific type each object is. Generate a list of employee names: all objects derived from Employee have a name field! no need to treat managers differently from anyone else. 81

82 Polymorphism The real power comes with methods/behaviors. A better example: shape object types used by a drawing program. we want to be able to handle any kind of shape someone wants to code (in the future). we want to be able to write code now that can deal with shape objects (without knowing what they are!). 82

83 Example public interface Vegetarian {} public class Animal{} public class Deer extends Animal implements Vegetarian{} Deer class is considered to be polymorphic since this has multiple inheritance A Deer IS-A aanimal A Deer IS-A Vegetarian A Deer IS-A Deer A Deer IS-A Object 83

84 Types of Polymorphism Overloading Overriding Dynamic method binding 84

85 Example public static void main ( String ary[ ] ) { Box x; Box b1 =new Box( ); WoddenBox wb=new WoddenBox( ); SteelBox s1=new SteelBox( ); LargeWoddenBox p1=new LargeWoddenBox( ); b1.info( ); wb.info( ); s1.info( ); p1.info( ); System.out.println(" "); Box b[]=new Box[5]; b[1]=new Box(); b[2]=new WoddenBox(); b[3]=new SteelBox(); b[4]=new LargeWoddenBox(); for(int i=1;i<5;i++) b[i].info(); } WoddenBox LargeWoddenBox Box SteelBox 85

JAVA - INHERITANCE. extends is the keyword used to inherit the properties of a class. Below given is the syntax of extends keyword.

JAVA - INHERITANCE. extends is the keyword used to inherit the properties of a class. Below given is the syntax of extends keyword. http://www.tutorialspoint.com/java/java_inheritance.htm JAVA - INHERITANCE Copyright tutorialspoint.com Inheritance can be defined as the process where one class acquires the properties methodsandfields

More information

CSCI 253. Object Oriented Programming (OOP) Overview. George Blankenship 1. Object Oriented Design: Java Review OOP George Blankenship.

CSCI 253. Object Oriented Programming (OOP) Overview. George Blankenship 1. Object Oriented Design: Java Review OOP George Blankenship. CSCI 253 Object Oriented Design: Java Review OOP George Blankenship George Blankenship 1 Object Oriented Programming (OOP) OO Principles Abstraction Encapsulation Abstract Data Type (ADT) Implementation

More information

Java Interview Questions and Answers

Java Interview Questions and Answers 1. What is the most important feature of Java? Java is a platform independent language. 2. What do you mean by platform independence? Platform independence means that we can write and compile the java

More information

History OOP languages Year Language 1967 Simula-67 1983 Smalltalk

History OOP languages Year Language 1967 Simula-67 1983 Smalltalk History OOP languages Intro 1 Year Language reported dates vary for some languages... design Vs delievered 1957 Fortran High level programming language 1958 Lisp 1959 Cobol 1960 Algol Structured Programming

More information

Java is an Object-Oriented Language. As a language that has the Object Oriented feature, Java supports the following fundamental concepts:

Java is an Object-Oriented Language. As a language that has the Object Oriented feature, Java supports the following fundamental concepts: JAVA OBJECTS JAVA OBJECTS AND CLASSES Java is an Object-Oriented Language. As a language that has the Object Oriented feature, Java supports the following fundamental concepts: Polymorphism Inheritance

More information

Java CPD (I) Frans Coenen Department of Computer Science

Java CPD (I) Frans Coenen Department of Computer Science Java CPD (I) Frans Coenen Department of Computer Science Content Session 1, 12:45-14:30 (First Java Programme, Inheritance, Arithmetic) Session 2, 14:45-16:45 (Input and Programme Constructs) Materials

More information

Yosemite National Park, California. CSE 114 Computer Science I Inheritance

Yosemite National Park, California. CSE 114 Computer Science I Inheritance Yosemite National Park, California CSE 114 Computer Science I Inheritance Containment A class contains another class if it instantiates an object of that class HAS-A also called aggregation PairOfDice

More information

Java Programming Language

Java Programming Language Lecture 1 Part II Java Programming Language Additional Features and Constructs Topics in Quantitative Finance: Numerical Solutions of Partial Differential Equations Instructor: Iraj Kani Subclasses and

More information

Fundamentals of Java Programming

Fundamentals of Java Programming Fundamentals of Java Programming This document is exclusive property of Cisco Systems, Inc. Permission is granted to print and copy this document for non-commercial distribution and exclusive use by instructors

More information

SE 360 Advances in Software Development Object Oriented Development in Java. Polymorphism. Dr. Senem Kumova Metin

SE 360 Advances in Software Development Object Oriented Development in Java. Polymorphism. Dr. Senem Kumova Metin SE 360 Advances in Software Development Object Oriented Development in Java Polymorphism Dr. Senem Kumova Metin Modified lecture notes of Dr. Hüseyin Akcan Inheritance Object oriented programming languages

More information

Advanced Data Structures

Advanced Data Structures C++ Advanced Data Structures Chapter 8: Advanced C++ Topics Zhijiang Dong Dept. of Computer Science Middle Tennessee State University Chapter 8: Advanced C++ Topics C++ 1 C++ Syntax of 2 Chapter 8: Advanced

More information

JAVA - OBJECT & CLASSES

JAVA - OBJECT & CLASSES JAVA - OBJECT & CLASSES http://www.tutorialspoint.com/java/java_object_classes.htm Copyright tutorialspoint.com Java is an Object-Oriented Language. As a language that has the Object Oriented feature,

More information

CS193j, Stanford Handout #10 OOP 3

CS193j, Stanford Handout #10 OOP 3 CS193j, Stanford Handout #10 Summer, 2003 Manu Kumar OOP 3 Abstract Superclass Factor Common Code Up Several related classes with overlapping code Factor common code up into a common superclass Examples

More information

Chapter 1 Fundamentals of Java Programming

Chapter 1 Fundamentals of Java Programming Chapter 1 Fundamentals of Java Programming Computers and Computer Programming Writing and Executing a Java Program Elements of a Java Program Features of Java Accessing the Classes and Class Members The

More information

Preet raj Core Java and Databases CS4PR. Time Allotted: 3 Hours. Final Exam: Total Possible Points 75

Preet raj Core Java and Databases CS4PR. Time Allotted: 3 Hours. Final Exam: Total Possible Points 75 Preet raj Core Java and Databases CS4PR Time Allotted: 3 Hours Final Exam: Total Possible Points 75 Q1. What is difference between overloading and overriding? 10 points a) In overloading, there is a relationship

More information

Chapter 13 - Inheritance

Chapter 13 - Inheritance Goals Chapter 13 - Inheritance To learn about inheritance To understand how to inherit and override superclass methods To be able to invoke superclass constructors To learn about protected and package

More information

Object-Oriented Programming in Java

Object-Oriented Programming in Java Object-Oriented Programming in Java Quiz 1 Jan 10, 2001 Problem 1: Who wants to be a Java developer? (with apologies to Regis) Fill in your answer in the space provided. Question 1: Which is these word-pairs

More information

First Java Programs. V. Paúl Pauca. CSC 111D Fall, 2015. Department of Computer Science Wake Forest University. Introduction to Computer Science

First Java Programs. V. Paúl Pauca. CSC 111D Fall, 2015. Department of Computer Science Wake Forest University. Introduction to Computer Science First Java Programs V. Paúl Pauca Department of Computer Science Wake Forest University CSC 111D Fall, 2015 Hello World revisited / 8/23/15 The f i r s t o b l i g a t o r y Java program @author Paul Pauca

More information

C++ INTERVIEW QUESTIONS

C++ INTERVIEW QUESTIONS C++ INTERVIEW QUESTIONS http://www.tutorialspoint.com/cplusplus/cpp_interview_questions.htm Copyright tutorialspoint.com Dear readers, these C++ Interview Questions have been designed specially to get

More information

AP Computer Science Java Subset

AP Computer Science Java Subset APPENDIX A AP Computer Science Java Subset The AP Java subset is intended to outline the features of Java that may appear on the AP Computer Science A Exam. The AP Java subset is NOT intended as an overall

More information

Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program

Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program Free Java textbook available online "Thinking in Java" by Bruce Eckel, 4th edition, 2006, ISBN 0131872486, Pearson Education Introduction to the Java programming language CS 4354 Summer II 2015 The third

More information

Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program

Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program Free Java textbook available online "Thinking in Java" by Bruce Eckel, 4th edition, 2006, ISBN 0131872486, Pearson Education Introduction to the Java programming language CS 4354 Summer II 2014 Jill Seaman

More information

JAVA - QUICK GUIDE. Java SE is freely available from the link Download Java. So you download a version based on your operating system.

JAVA - QUICK GUIDE. Java SE is freely available from the link Download Java. So you download a version based on your operating system. http://www.tutorialspoint.com/java/java_quick_guide.htm JAVA - QUICK GUIDE Copyright tutorialspoint.com What is Java? Java is: Object Oriented Platform independent: Simple Secure Architectural- neutral

More information

Agenda. What is and Why Polymorphism? Examples of Polymorphism in Java programs 3 forms of Polymorphism

Agenda. What is and Why Polymorphism? Examples of Polymorphism in Java programs 3 forms of Polymorphism Polymorphism 1 Agenda What is and Why Polymorphism? Examples of Polymorphism in Java programs 3 forms of Polymorphism 2 What is & Why Polymorphism? 3 What is Polymorphism? Generally, polymorphism refers

More information

Inheritance, overloading and overriding

Inheritance, overloading and overriding Inheritance, overloading and overriding Recall with inheritance the behavior and data associated with the child classes are always an extension of the behavior and data associated with the parent class

More information

Programmation 2. Introduction à la programmation Java

Programmation 2. Introduction à la programmation Java Programmation 2 Introduction à la programmation Java 1 Course information CM: 6 x 2 hours TP: 6 x 2 hours CM: Alexandru Costan alexandru.costan at inria.fr TP: Vincent Laporte vincent.laporte at irisa.fr

More information

Chapter 1 Java Program Design and Development

Chapter 1 Java Program Design and Development presentation slides for JAVA, JAVA, JAVA Object-Oriented Problem Solving Third Edition Ralph Morelli Ralph Walde Trinity College Hartford, CT published by Prentice Hall Java, Java, Java Object Oriented

More information

The Sun Certified Associate for the Java Platform, Standard Edition, Exam Version 1.0

The Sun Certified Associate for the Java Platform, Standard Edition, Exam Version 1.0 The following applies to all exams: Once exam vouchers are purchased you have up to one year from the date of purchase to use it. Each voucher is valid for one exam and may only be used at an Authorized

More information

The Java Series. Java Essentials I What is Java? Basic Language Constructs. Java Essentials I. What is Java?. Basic Language Constructs Slide 1

The Java Series. Java Essentials I What is Java? Basic Language Constructs. Java Essentials I. What is Java?. Basic Language Constructs Slide 1 The Java Series Java Essentials I What is Java? Basic Language Constructs Slide 1 What is Java? A general purpose Object Oriented programming language. Created by Sun Microsystems. It s a general purpose

More information

Cohort: BCA/07B/PT - BCA/06/PT - BCNS/06/FT - BCNS/05/FT - BIS/06/FT - BIS/05/FT - BSE/05/FT - BSE/04/PT-BSE/06/FT

Cohort: BCA/07B/PT - BCA/06/PT - BCNS/06/FT - BCNS/05/FT - BIS/06/FT - BIS/05/FT - BSE/05/FT - BSE/04/PT-BSE/06/FT BSc (Hons) in Computer Applications, BSc (Hons) Computer Science with Network Security, BSc (Hons) Business Information Systems & BSc (Hons) Software Engineering Cohort: BCA/07B/PT - BCA/06/PT - BCNS/06/FT

More information

Glossary of Object Oriented Terms

Glossary of Object Oriented Terms Appendix E Glossary of Object Oriented Terms abstract class: A class primarily intended to define an instance, but can not be instantiated without additional methods. abstract data type: An abstraction

More information

LAB4 Making Classes and Objects

LAB4 Making Classes and Objects LAB4 Making Classes and Objects Objective The main objective of this lab is class creation, how its constructer creation, object creation and instantiation of objects. We will use the definition pane to

More information

Java Application Developer Certificate Program Competencies

Java Application Developer Certificate Program Competencies Java Application Developer Certificate Program Competencies After completing the following units, you will be able to: Basic Programming Logic Explain the steps involved in the program development cycle

More information

The Interface Concept

The Interface Concept Multiple inheritance Interfaces Four often used Java interfaces Iterator Cloneable Serializable Comparable The Interface Concept OOP: The Interface Concept 1 Multiple Inheritance, Example Person name()

More information

Object-Oriented Programming: Polymorphism

Object-Oriented Programming: Polymorphism 1 10 Object-Oriented Programming: Polymorphism 10.3 Demonstrating Polymorphic Behavior 10.4 Abstract Classes and Methods 10.5 Case Study: Payroll System Using Polymorphism 10.6 final Methods and Classes

More information

Lecture 7 Notes: Object-Oriented Programming (OOP) and Inheritance

Lecture 7 Notes: Object-Oriented Programming (OOP) and Inheritance Introduction to C++ January 19, 2011 Massachusetts Institute of Technology 6.096 Lecture 7 Notes: Object-Oriented Programming (OOP) and Inheritance We ve already seen how to define composite datatypes

More information

Introduction to Object-Oriented Programming

Introduction to Object-Oriented Programming Introduction to Object-Oriented Programming Objects and classes Abstract Data Types (ADT) Encapsulation and information hiding Aggregation Inheritance and polymorphism OOP: Introduction 1 Pure Object-Oriented

More information

How To Write A Program In Java (Programming) On A Microsoft Macbook Or Ipad (For Pc) Or Ipa (For Mac) (For Microsoft) (Programmer) (Or Mac) Or Macbook (For

How To Write A Program In Java (Programming) On A Microsoft Macbook Or Ipad (For Pc) Or Ipa (For Mac) (For Microsoft) (Programmer) (Or Mac) Or Macbook (For Projet Java Responsables: Ocan Sankur, Guillaume Scerri (LSV, ENS Cachan) Objectives - Apprendre à programmer en Java - Travailler à plusieurs sur un gros projet qui a plusieurs aspects: graphisme, interface

More information

Debugging. Common Semantic Errors ESE112. Java Library. It is highly unlikely that you will write code that will work on the first go

Debugging. Common Semantic Errors ESE112. Java Library. It is highly unlikely that you will write code that will work on the first go Debugging ESE112 Java Programming: API, Psuedo-Code, Scope It is highly unlikely that you will write code that will work on the first go Bugs or errors Syntax Fixable if you learn to read compiler error

More information

CS1002: COMPUTER SCIENCE OO MODELLING & DESIGN: WEEK 5

CS1002: COMPUTER SCIENCE OO MODELLING & DESIGN: WEEK 5 This Week CS1002: COMPUTER SCIENCE OO MODELLING & DESIGN: WEEK 5 School of Computer Science University of St Andrews Graham Kirby Alan Dearle More on Java classes Constructors Modifiers cdn.videogum.com/img/thumbnails/photos/commenter.jpg

More information

D06 PROGRAMMING with JAVA

D06 PROGRAMMING with JAVA Cicles Formatius de Grau Superior Desenvolupament d Aplicacions Informàtiques D06 PROGRAMMING with JAVA Ch13 Inheritance PowerPoint presentation, created by Angel A. Juan - ajuanp(@)gmail.com, for accompanying

More information

CIS 190: C/C++ Programming. Polymorphism

CIS 190: C/C++ Programming. Polymorphism CIS 190: C/C++ Programming Polymorphism Outline Review of Inheritance Polymorphism Car Example Virtual Functions Virtual Function Types Virtual Table Pointers Virtual Constructors/Destructors Review of

More information

Konzepte objektorientierter Programmierung

Konzepte objektorientierter Programmierung Konzepte objektorientierter Programmierung Prof. Dr. Peter Müller Werner Dietl Software Component Technology Exercises 3: Some More OO Languages Wintersemester 04/05 Agenda for Today 2 Homework Finish

More information

Part I. Multiple Choice Questions (2 points each):

Part I. Multiple Choice Questions (2 points each): Part I. Multiple Choice Questions (2 points each): 1. Which of the following is NOT a key component of object oriented programming? (a) Inheritance (b) Encapsulation (c) Polymorphism (d) Parallelism ******

More information

Masters programmes in Computer Science and Information Systems. Object-Oriented Design and Programming. Sample module entry test xxth December 2013

Masters programmes in Computer Science and Information Systems. Object-Oriented Design and Programming. Sample module entry test xxth December 2013 Masters programmes in Computer Science and Information Systems Object-Oriented Design and Programming Sample module entry test xxth December 2013 This sample paper has more questions than the real paper

More information

Object-Oriented Design Lecture 4 CSU 370 Fall 2007 (Pucella) Tuesday, Sep 18, 2007

Object-Oriented Design Lecture 4 CSU 370 Fall 2007 (Pucella) Tuesday, Sep 18, 2007 Object-Oriented Design Lecture 4 CSU 370 Fall 2007 (Pucella) Tuesday, Sep 18, 2007 The Java Type System By now, you have seen a fair amount of Java. Time to study in more depth the foundations of the language,

More information

Multichoice Quetions 1. Atributes a. are listed in the second part of the class box b. its time is preceded by a colon. c. its default value is

Multichoice Quetions 1. Atributes a. are listed in the second part of the class box b. its time is preceded by a colon. c. its default value is Multichoice Quetions 1. Atributes a. are listed in the second part of the class box b. its time is preceded by a colon. c. its default value is preceded by an equal sign d. its name has undereline 2. Associations

More information

CS 111 Classes I 1. Software Organization View to this point:

CS 111 Classes I 1. Software Organization View to this point: CS 111 Classes I 1 Software Organization View to this point: Data Objects and primitive types Primitive types operators (+, /,,*, %). int, float, double, char, boolean Memory location holds the data Objects

More information

Java SE 8 Programming

Java SE 8 Programming Oracle University Contact Us: 1.800.529.0165 Java SE 8 Programming Duration: 5 Days What you will learn This Java SE 8 Programming training covers the core language features and Application Programming

More information

Java Classes. GEEN163 Introduction to Computer Programming

Java Classes. GEEN163 Introduction to Computer Programming Java Classes GEEN163 Introduction to Computer Programming Never interrupt someone doing what you said couldn't be done. Amelia Earhart Classes, Objects, & Methods Object-oriented programming uses classes,

More information

CSE 1020 Introduction to Computer Science I A sample nal exam

CSE 1020 Introduction to Computer Science I A sample nal exam 1 1 (8 marks) CSE 1020 Introduction to Computer Science I A sample nal exam For each of the following pairs of objects, determine whether they are related by aggregation or inheritance. Explain your answers.

More information

Compiling Object Oriented Languages. What is an Object-Oriented Programming Language? Implementation: Dynamic Binding

Compiling Object Oriented Languages. What is an Object-Oriented Programming Language? Implementation: Dynamic Binding Compiling Object Oriented Languages What is an Object-Oriented Programming Language? Last time Dynamic compilation Today Introduction to compiling object oriented languages What are the issues? Objects

More information

Advanced OOP Concepts in Java

Advanced OOP Concepts in Java Advanced OOP Concepts in Java Michael B. Spring Department of Information Science and Telecommunications University of Pittsburgh spring@imap.pitt.edu http://www.sis.pitt.edu/~spring 09/28/2001 1 Overview

More information

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner. Handout 1 CS603 Object-Oriented Programming Fall 15 Page 1 of 11 Handout 1 Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner. Java

More information

Java (12 Weeks) Introduction to Java Programming Language

Java (12 Weeks) Introduction to Java Programming Language Java (12 Weeks) Topic Lecture No. Introduction to Java Programming Language 1 An Introduction to Java o Java as a Programming Platform, The Java "White Paper" Buzzwords, Java and the Internet, A Short

More information

Compile-time type versus run-time type. Consider the parameter to this function:

Compile-time type versus run-time type. Consider the parameter to this function: CS107L Handout 07 Autumn 2007 November 16, 2007 Advanced Inheritance and Virtual Methods Employee.h class Employee public: Employee(const string& name, double attitude, double wage); virtual ~Employee();

More information

Tutorial on Writing Modular Programs in Scala

Tutorial on Writing Modular Programs in Scala Tutorial on Writing Modular Programs in Scala Martin Odersky and Gilles Dubochet 13 September 2006 Tutorial on Writing Modular Programs in Scala Martin Odersky and Gilles Dubochet 1 of 45 Welcome to the

More information

C++FA 5.1 PRACTICE MID-TERM EXAM

C++FA 5.1 PRACTICE MID-TERM EXAM C++FA 5.1 PRACTICE MID-TERM EXAM This practicemid-term exam covers sections C++FA 1.1 through C++FA 1.4 of C++ with Financial Applications by Ben Van Vliet, available at www.benvanvliet.net. 1.) A pointer

More information

qwertyuiopasdfghjklzxcvbnmqwerty uiopasdfghjklzxcvbnmqwertyuiopasd fghjklzxcvbnmqwertyuiopasdfghjklzx cvbnmqwertyuiopasdfghjklzxcvbnmq

qwertyuiopasdfghjklzxcvbnmqwerty uiopasdfghjklzxcvbnmqwertyuiopasd fghjklzxcvbnmqwertyuiopasdfghjklzx cvbnmqwertyuiopasdfghjklzxcvbnmq qwertyuiopasdfghjklzxcvbnmqwerty uiopasdfghjklzxcvbnmqwertyuiopasd fghjklzxcvbnmqwertyuiopasdfghjklzx cvbnmqwertyuiopasdfghjklzxcvbnmq Introduction to Programming using Java wertyuiopasdfghjklzxcvbnmqwertyui

More information

DIPLOMADO DE JAVA - OCA

DIPLOMADO DE JAVA - OCA DIPLOMADO DE JAVA - OCA TABLA DE CONTENIDO INTRODUCCION... 3 ESTRUCTURA DEL DIPLOMADO... 4 Nivel I:... 4 Fundamentals of the Java Programming Language Java SE 7... 4 Introducing the Java Technology...

More information

Chapter 2 Introduction to Java programming

Chapter 2 Introduction to Java programming Chapter 2 Introduction to Java programming 1 Keywords boolean if interface class true char else package volatile false byte final switch while throws float private case return native void protected break

More information

13 Classes & Objects with Constructors/Destructors

13 Classes & Objects with Constructors/Destructors 13 Classes & Objects with Constructors/Destructors 13.1 Introduction In object oriented programming, the emphasis is on data rather than function. Class is a way that binds the data & function together.

More information

Crash Course in Java

Crash Course in Java Crash Course in Java Based on notes from D. Hollinger Based in part on notes from J.J. Johns also: Java in a Nutshell Java Network Programming and Distributed Computing Netprog 2002 Java Intro 1 What is

More information

Building Java Programs

Building Java Programs Building Java Programs Chapter 9 Lecture 9-1: Inheritance reading: 9.1 The software crisis software engineering: The practice of developing, designing, documenting, testing large computer programs. Large-scale

More information

Polymorphism. Why use polymorphism Upcast revisited (and downcast) Static and dynamic type Dynamic binding. Polymorphism.

Polymorphism. Why use polymorphism Upcast revisited (and downcast) Static and dynamic type Dynamic binding. Polymorphism. Why use polymorphism Upcast revisited (and downcast) Static and dynamic type Dynamic binding Polymorphism Polymorphism A polymorphic field (the state design pattern) Abstract classes The composite design

More information

What is Java? Applications and Applets: Result of Sun s efforts to remedy bad software engineering practices

What is Java? Applications and Applets: Result of Sun s efforts to remedy bad software engineering practices What is Java? Result of Sun s efforts to remedy bad software engineering practices It is commonly thought of as a way to make Web pages cool. It has evolved into much more. It is fast becoming a computing

More information

Introduction: Abstract Data Types and Java Review

Introduction: Abstract Data Types and Java Review Introduction: Abstract Data Types and Java Review Computer Science E-119 Harvard Extension School Fall 2012 David G. Sullivan, Ph.D. Welcome to Computer Science E-119! We will study fundamental data structures.

More information

Java Programming Fundamentals

Java Programming Fundamentals Lecture 1 Part I Java Programming Fundamentals Topics in Quantitative Finance: Numerical Solutions of Partial Differential Equations Instructor: Iraj Kani Introduction to Java We start by making a few

More information

Abstract Class & Java Interface

Abstract Class & Java Interface Abstract Class & Java Interface 1 Agenda What is an Abstract method and an Abstract class? What is Interface? Why Interface? Interface as a Type Interface vs. Class Defining an Interface Implementing an

More information

KITES TECHNOLOGY COURSE MODULE (C, C++, DS)

KITES TECHNOLOGY COURSE MODULE (C, C++, DS) KITES TECHNOLOGY 360 Degree Solution www.kitestechnology.com/academy.php info@kitestechnology.com technologykites@gmail.com Contact: - 8961334776 9433759247 9830639522.NET JAVA WEB DESIGN PHP SQL, PL/SQL

More information

Java Programming. Binnur Kurt binnur.kurt@ieee.org. Istanbul Technical University Computer Engineering Department. Java Programming. Version 0.0.

Java Programming. Binnur Kurt binnur.kurt@ieee.org. Istanbul Technical University Computer Engineering Department. Java Programming. Version 0.0. Java Programming Binnur Kurt binnur.kurt@ieee.org Istanbul Technical University Computer Engineering Department Java Programming 1 Version 0.0.4 About the Lecturer BSc İTÜ, Computer Engineering Department,

More information

Polymorphism. Problems with switch statement. Solution - use virtual functions (polymorphism) Polymorphism

Polymorphism. Problems with switch statement. Solution - use virtual functions (polymorphism) Polymorphism Polymorphism Problems with switch statement Programmer may forget to test all possible cases in a switch. Tracking this down can be time consuming and error prone Solution - use virtual functions (polymorphism)

More information

Description of Class Mutation Mutation Operators for Java

Description of Class Mutation Mutation Operators for Java Description of Class Mutation Mutation Operators for Java Yu-Seung Ma Electronics and Telecommunications Research Institute, Korea ysma@etri.re.kr Jeff Offutt Software Engineering George Mason University

More information

Introduction to Java Applications. 2005 Pearson Education, Inc. All rights reserved.

Introduction to Java Applications. 2005 Pearson Education, Inc. All rights reserved. 1 2 Introduction to Java Applications 2.2 First Program in Java: Printing a Line of Text 2 Application Executes when you use the java command to launch the Java Virtual Machine (JVM) Sample program Displays

More information

Introduction to Programming Block Tutorial C/C++

Introduction to Programming Block Tutorial C/C++ Michael Bader Master s Program Computational Science and Engineering C/C++ Tutorial Overview From Maple to C Variables, Operators, Statements Functions: declaration, definition, parameters Arrays and Pointers

More information

Java SE 7 Programming

Java SE 7 Programming Java SE 7 Programming The second of two courses that cover the Java Standard Edition 7 (Java SE 7) Platform, this course covers the core Application Programming Interfaces (API) you will use to design

More information

In order to understand Perl objects, you first need to understand references in Perl. See perlref for details.

In order to understand Perl objects, you first need to understand references in Perl. See perlref for details. NAME DESCRIPTION perlobj - Perl object reference This document provides a reference for Perl's object orientation features. If you're looking for an introduction to object-oriented programming in Perl,

More information

Java How to Program, 5/e Test Item File 1 of 5

Java How to Program, 5/e Test Item File 1 of 5 Java How to Program, 5/e Test Item File 1 of 5 Chapter 8 Section 8.1 8.1 Q1: Object-Oriented Programming encapsulates: a.data and methods. b.information hiding. c.classes. d.adjectives ANS: a. Data and

More information

PART-A Questions. 2. How does an enumerated statement differ from a typedef statement?

PART-A Questions. 2. How does an enumerated statement differ from a typedef statement? 1. Distinguish & and && operators. PART-A Questions 2. How does an enumerated statement differ from a typedef statement? 3. What are the various members of a class? 4. Who can access the protected members

More information

www.virtualians.pk CS506 Web Design and Development Solved Online Quiz No. 01 www.virtualians.pk

www.virtualians.pk CS506 Web Design and Development Solved Online Quiz No. 01 www.virtualians.pk CS506 Web Design and Development Solved Online Quiz No. 01 Which of the following is a general purpose container? JFrame Dialog JPanel JApplet Which of the following package needs to be import while handling

More information

File class in Java. Scanner reminder. Files 10/19/2012. File Input and Output (Savitch, Chapter 10)

File class in Java. Scanner reminder. Files 10/19/2012. File Input and Output (Savitch, Chapter 10) File class in Java File Input and Output (Savitch, Chapter 10) TOPICS File Input Exception Handling File Output Programmers refer to input/output as "I/O". The File class represents files as objects. The

More information

JAVA INTERVIEW QUESTIONS

JAVA INTERVIEW QUESTIONS JAVA INTERVIEW QUESTIONS http://www.tutorialspoint.com/java/java_interview_questions.htm Copyright tutorialspoint.com Dear readers, these Java Interview Questions have been designed especially to get you

More information

Getting Started with the Internet Communications Engine

Getting Started with the Internet Communications Engine Getting Started with the Internet Communications Engine David Vriezen April 7, 2014 Contents 1 Introduction 2 2 About Ice 2 2.1 Proxies................................. 2 3 Setting Up ICE 2 4 Slices 2

More information

Storage Classes CS 110B - Rule Storage Classes Page 18-1 \handouts\storclas

Storage Classes CS 110B - Rule Storage Classes Page 18-1 \handouts\storclas CS 110B - Rule Storage Classes Page 18-1 Attributes are distinctive features of a variable. Data type, int or double for example, is an attribute. Storage class is another attribute. There are four storage

More information

Topics. Introduction. Java History CS 146. Introduction to Programming and Algorithms Module 1. Module Objectives

Topics. Introduction. Java History CS 146. Introduction to Programming and Algorithms Module 1. Module Objectives Introduction to Programming and Algorithms Module 1 CS 146 Sam Houston State University Dr. Tim McGuire Module Objectives To understand: the necessity of programming, differences between hardware and software,

More information

CEC225 COURSE COMPACT

CEC225 COURSE COMPACT CEC225 COURSE COMPACT Course GEC 225 Applied Computer Programming II(2 Units) Compulsory Course Duration Two hours per week for 15 weeks (30 hours) Lecturer Data Name of the lecturer: Dr. Oyelami Olufemi

More information

Exception Handling. Overloaded methods Interfaces Inheritance hierarchies Constructors. OOP: Exception Handling 1

Exception Handling. Overloaded methods Interfaces Inheritance hierarchies Constructors. OOP: Exception Handling 1 Exception Handling Error handling in general Java's exception handling mechanism The catch-or-specify priciple Checked and unchecked exceptions Exceptions impact/usage Overloaded methods Interfaces Inheritance

More information

PHP Object Oriented Classes and objects

PHP Object Oriented Classes and objects Web Development II Department of Software and Computing Systems PHP Object Oriented Classes and objects Sergio Luján Mora Jaume Aragonés Ferrero Department of Software and Computing Systems DLSI - Universidad

More information

Génie Logiciel et Gestion de Projets. Object-Oriented Programming An introduction to Java

Génie Logiciel et Gestion de Projets. Object-Oriented Programming An introduction to Java Génie Logiciel et Gestion de Projets Object-Oriented Programming An introduction to Java 1 Roadmap History of Abstraction Mechanisms Learning an OOPL Classes, Methods and Messages Inheritance Polymorphism

More information

Java Interfaces. Recall: A List Interface. Another Java Interface Example. Interface Notes. Why an interface construct? Interfaces & Java Types

Java Interfaces. Recall: A List Interface. Another Java Interface Example. Interface Notes. Why an interface construct? Interfaces & Java Types Interfaces & Java Types Lecture 10 CS211 Fall 2005 Java Interfaces So far, we have mostly talked about interfaces informally, in the English sense of the word An interface describes how a client interacts

More information

Java from a C perspective. Plan

Java from a C perspective. Plan Java from a C perspective Cristian Bogdan 2D2052/ingint04 Plan Objectives and Book Packages and Classes Types and memory allocation Syntax and C-like Statements Object Orientation (minimal intro) Exceptions,

More information

INTRODUCTION TO COMPUTER PROGRAMMING. Richard Pierse. Class 7: Object-Oriented Programming. Introduction

INTRODUCTION TO COMPUTER PROGRAMMING. Richard Pierse. Class 7: Object-Oriented Programming. Introduction INTRODUCTION TO COMPUTER PROGRAMMING Richard Pierse Class 7: Object-Oriented Programming Introduction One of the key issues in programming is the reusability of code. Suppose that you have written a program

More information

Java Crash Course Part I

Java Crash Course Part I Java Crash Course Part I School of Business and Economics Institute of Information Systems HU-Berlin WS 2005 Sebastian Kolbe skolbe@wiwi.hu-berlin.de Overview (Short) introduction to the environment Linux

More information

11 November 2015. www.isbe.tue.nl. www.isbe.tue.nl

11 November 2015. www.isbe.tue.nl. www.isbe.tue.nl UML Class Diagrams 11 November 2015 UML Class Diagrams The class diagram provides a static structure of all the classes that exist within the system. Classes are arranged in hierarchies sharing common

More information

www.sahajsolns.com Chapter 4 OOPS WITH C++ Sahaj Computer Solutions

www.sahajsolns.com Chapter 4 OOPS WITH C++ Sahaj Computer Solutions Chapter 4 OOPS WITH C++ Sahaj Computer Solutions 1 Session Objectives Classes and Objects Class Declaration Class Members Data Constructors Destructors Member Functions Class Member Visibility Private,

More information

Habanero Extreme Scale Software Research Project

Habanero Extreme Scale Software Research Project Habanero Extreme Scale Software Research Project Comp215: Java Method Dispatch Zoran Budimlić (Rice University) Always remember that you are absolutely unique. Just like everyone else. - Margaret Mead

More information

INTRODUCTION TO OBJECTIVE-C CSCI 4448/5448: OBJECT-ORIENTED ANALYSIS & DESIGN LECTURE 12 09/29/2011

INTRODUCTION TO OBJECTIVE-C CSCI 4448/5448: OBJECT-ORIENTED ANALYSIS & DESIGN LECTURE 12 09/29/2011 INTRODUCTION TO OBJECTIVE-C CSCI 4448/5448: OBJECT-ORIENTED ANALYSIS & DESIGN LECTURE 12 09/29/2011 1 Goals of the Lecture Present an introduction to Objective-C 2.0 Coverage of the language will be INCOMPLETE

More information

JAVA - METHODS. Method definition consists of a method header and a method body. The same is shown below:

JAVA - METHODS. Method definition consists of a method header and a method body. The same is shown below: http://www.tutorialspoint.com/java/java_methods.htm JAVA - METHODS Copyright tutorialspoint.com A Java method is a collection of statements that are grouped together to perform an operation. When you call

More information

Java SE 7 Programming

Java SE 7 Programming Oracle University Contact Us: 1.800.529.0165 Java SE 7 Programming Duration: 5 Days What you will learn This Java SE 7 Programming training explores the core Application Programming Interfaces (API) you'll

More information