Review Of Fundamental Concepts (Drinking from a Fire hose 101) Object Oriented Programming and Java
|
|
- Charlotte Stafford
- 5 years ago
- Views:
Transcription
1 Review Of Fundamental Concepts (Drinking from a Fire hose 101) 1 Object Oriented Programming and Java 2 1
2 Java OOP Review Topics 3 Object resuability Inheritance Composition Aggregation Encapsulation Public/Private/Protected member variables and methods Public/Package Protected classes Polymorphism (late/runtime binding) Upcasting *** Abstract classes and Interfaces (no multiple inheritance in Java) Method overloading Java constructor life cycle Java Packages and the classpath Java Object Reuse 4 public class Shape { BASE CLASS // mv1 is available to everyone public data-type mv1; // mv2 is available only to this class private data-type mv2; // mv3 is available only to this class // and its children (see inheritance) protected data-type mv3; // mv4 is available to this class and any // other in the same package (see Java // packages) data-type membervariable4; public void draw() { //statements for implementation public void erase() { // statements for implementation public void move() { // statements for implementation public void area() { // statements for implementation OVERRIDES FUNCTIONALITY public class Circle extends Shape { public void draw() { //statements for implementation public void erase() { // statements for implementation public void move() { // statements for implementation public void area() { // statements for implementation public class Rectangle extends Shape { EXTENDS FUNCTIONALITY public class Triangle extends Shape { public void fliphorizontal() { // statements for implementation public void flipvertical() { // statements for implementation 2
3 Upcasting Any derived class from a base class may be treated as if it is of type base class. Derived class has the interface of the base class (and possibly other methods as well) If upcasting will only recognize interface of base class (additional methods will not be recognized) Shape[] shapes = new Shape[3]; shapes[1] = new Circle(radius); shapes[2] = new Rectangle(width, height); shapes[3] = new Triangle(base, height); For (int i = 0; i < 3; i++) { System.out.println( Area of shape + i + is + shapes[i].area()); 5 Abstract Classes and Interfaces Abstract class is a base class that presents an interface for derived classes Compiler prevents direct implementation of class Implemented by uniqued subclasses which can be referenced by upcasting to common type abstract methods define stubs for methods in abstract classes that require implementations in subclasses In java, abstract class has at least one method that has not been implemented Interface extends the idea of abstract classes Defines only method stubs and implements NO code Objects that implement interfaces must provide code for EVERY method stub Implementing methods may be upcasted to interface type 6 3
4 Abstract Classes and Interfaces public abstract class Shape { private Color color; public abstract void draw(); public abstract void resize(float s); public Color getcolor() { return color; public class Circle extends Shape { // implementation required public void draw() { // implementation here // implementation required public void resize(double scale) { // implementation here // other methods and variables 7 public interface IShape { // Stubs only public void draw(); public void resize(float s); Public class Circle2 implements IShape { // implementation required public void draw() { // implementation here // implementation required public void resize(double scale) { // implementation here // other methods and variables Multiple Inheritance Any java class can only extend one base class public class derclass extends class1, class2 COMPILER ERROR!!!! Java classes can implement numerous interfaces public class derclass extends class1 implements i1, i2 ACCEPTABLE Use interfaces to inherit multiple java types 8 4
5 Inherited constructors and super(...) When you instantiate an object of a subclass, the system will automatically call the superclass constructor first By default, the zero-argument superclass constructor is called unless a different constructor is specified Access the constructor in the superclass through super(args) If super( ) is used in a subclass constructor, then super( ) must be the first statement in the constructor Constructor life-cycle Each constructor has three phases 1. Invoke the constructor of the superclass 2. Initialize all instance variables based on their initialization statements 3. Execute the body of the constructor 9 Java Packages 10 A collection of related classes and interfaces providing access protection and namespace management Package protection of variables and methods Class name resolution across packages (avoid name conflicts) Creating a package Create a subdirectory with the same name as the desired package and place the source files in that directory Java source file must begin with package keyword and name of package (first statement), then any classes/interfaces in file will be in that package Source file package packagename; public class classname { class nextclassname { 5
6 Java Packages (cont) 11 Using packaged classes Only public members of a packaged class are universally available outside of its package Explicitly protected members (user defined) of a packaged class are available outside its package only to subclasses Accessing packaged classes/objects from an object outside the class Refer to member in code by qualified name Qualified name = packagename.classname Example java.sql.date d = new java.sql.date(); Import member or package containing member import statement * = all classes in package (not a wildcard) package packagename; import otherpackagename1.classname; import otherpackagename2.*; public class classname { Java Packages (cont) If a package statement is omitted from a file, then the code is part of the default package that has no name The package hierarchy reflects the file system directory structure Package java.math The root of any package must be accessible through a Java system default directory or through the CLASSPATH environment variable 12 6
7 Java Built In Packages java javax applet awt io lang event font image sql swing xml border event plaf table namespace parsers transform validation tree math net util Note java.lang.* included in code by default. Others must be explicitly imported 13 CLASSPATH Environment variable and/or switch to inform java compiler and runtime where to find classes, packages, etc. Default = current directory and system libraries Setting the CLASSPATH Environment variable Windows set CLASSPATH =.;C\java;D\cwp\echoserver.jar Unix setenv CLASSPATH.~/java/home/cwp/classes/ Command line switch Compiler javac classpath.;c\java;d\cwp\code.jar client.java Interpreter java classpath.;c\java;d\cwp\code.jar client 14 7
8 CLASSPATH (cont) Default classpath includes current directory and java.lang package CLASSPATH and packages Package naming convention period delimited package.subpackage.sub-subpackage jhuapl jhuapl.edu jhuapl.edu.graphics Qualified class name maps to path to source/class file jhuapl.edu.graphics.myobject located in jhuapl/edu/graphics directory CLASSPATH must point to directory containing the package root, or to the jar file containing the package 15 Java Getting Started and Basic Syntax
9 Basic Java Highlights Immutable objects and the java String class Short circuit evaluation in conditional expressions Java Containers Collections Maps Upcasting Generics in Java Handling Exceptions In Java 17 Strings 18 java.lang.string is a real class in Java, not an array of characters as in C and C++. The String class has a shortcut method to create a new object just use double quotes String s = This is a string ; This differs from normal objects, where you use the new construct to build an object Java String objects are immutable Once initialized they cannot be changed Reassignment of Strings actually creates new objects and throws out originals Inefficient use java StringBuffer objects to create modifiable strings and convert to String as needed StringBuffer sb = new StringBuffer(String s1); sb.append(string s2).append(string s3); String result = sb.tostring(); // result = s1 + s2 + s3 9
10 Java Containers 19 Hold references to objects, no primitives Collection A group of elements with some rule applied to them One item in each location Map A group of key-value object pairs Containers can be accessed via java.util.iterator objects Objects that enable you to move through the objects in a container, select and/or remove each object without information about the details of the stored objects or structure of the sequence java.util.collection Store references to elements as java.lang.objects For primitives (int, boolean, float, etc) must use object wrapper classes java.lang.integer, java.lang.boolean, etc. Variable length, can grow or shrink public void add(java.lang.object) public void remove(java.lang.object) public int size() public Iterator iterator() Java 1.4 and earlier - type information of elements is not preserved, objects must be cast to type upon retrieval from collection public java.lang.object get(int) java.lang.object o = list.get(i); MyClass mc = (MyClass)list.get(j); Java 1.5 uses generics to do type checking at compile time Set HashSet SortedSet TreeSet Collection List ArrayList LinkedList Vector 20 10
11 Collection Hierarchy 21 Collection Interface for holding groups of objects Set Group of objects containing no duplicates Ordering of elements is governed internally HashSet fast lookup LinkedHashSet fast lookup and maintains insertion order SortedSet Set of objects (no duplicates) stored in ascending order Order is determined by a Comparator TreeSet backed by tree structure for ordered access List Physically (versus logically) ordered sequence of objects (ordered as input) ArrayList fast access but slow insert/delete LinkedList fast sequential access (insert/delete) but slow random access java.util.map Stores references in key-value pairs of java.lang.object references public Object put(object key, Object val) public Object get(object key) public int size() public Collection values() public Set keyset() Iterators for walking through collection or map Map HashMap Hashtable SortedMap TreeMap 22 11
12 Map Interfaces Map Stores objects (unordered) identified by unique keys HashMap constant performance for insertion and lookup LinkedHashMap maintains insertion order SortedMap Objects stored in ascending order based on their key value Neither duplicate or null keys are permitted TreeMap backed by trees for keys and values 23 java.util.iterator 24 Objects that enable you to move through the objects in a container, select and/or remove each object without information about the details of the stored objects or structure of the sequence Walking through a Collection or Map Import java.util.*; List l = getlist(); for (Iterator i = list.iterator(); i.hasnext();) { Float f = (Float)i.next(); System.out.println(3 * f.floatvalue()); i.remove(); For Maps, use values() or keyset() method to convert to Collection (Set) and then user iterator() to get Iterator object 12
13 25 Collections & Generics Overview Traditionally compiler can only guarantee that an Object will be returned by Collections API accessors Left to programmer to ensure specific types through casting that is not checked until runtime Generics provides way for programmer to communicate types so compiler will not permit alternatives Generics are usually more restrictive to eliminate ANY possibility of unexpected types Generics syntax results in more readable code without casts Collections & Generics Syntax Designate a collection of type TYPE Collection<TYPE> cvar = new Collection<TYPE>(); for (int i = 0; i < cvar.size(); i++) { TYPE tvar = cvar.get(i); // no casting Example List<String> cvar = new ArrayList<String>(); for (int i = 0; i < cvar.size(); i++) { String tvar = cvar.get(i); // no casting!!! 26 13
14 Collections & Generics Pitfalls Generics forces programmer to be more aware of type relationships. Example Is a List of String also a List of Object??? Since Strings are children of Objects, one would think so, however following example WILL NOT compile List<String> ls = new ArrayList<String>(); List<Object> lo = ls; If permitted then we could add an Object to lo and retrieveit through ls as a String. 27 lo.add(new Object()); String s = ls.get(0); Collections and Generics More Definitions More general types <?> wildcard representing UNKOWN type <? Extends ParentClass> An UNKNOWN type that is a child of ParentClass Restrictions Can access elements as Object using <?> since all java objects subclass Object void printcollection(collection<?> c) { for (Object e c) { System.out.println(e); Cannot assign elements the type or subtype of element is unknown by definition Collection<?> c = new ArrayList<String>(); c.add(new Object()); compile time error 28 14
15 Exceptions An event that occurs during the execution of a program that disrupts its normal flow Access elements of an array beyond its range Attempt to access an object that is null (does not exist) Invalid input Memory exhausted Disk crash Java stores relevant information in a Throwable object and finds code to handle it Searches through the method call stack Default handler provided by Java Runtime Outputs description of exception Outputs hierarchy of methods where exception occurred Terminates program IOException Throwable Exception Error RuntimeException 29 When an Exception Occurs 30 When an exception occurs in a method, that method creates an exception object and hands it to the Java runtime The method throws an exception Object includes information about the error that occurred Runtime searches the call stack (hierarchy of methods) until it finds method with an appropriate exception handler, and passes exception object to that hander If no such handler is found, runtime uses default hander 15
16 Why handle exceptions? Separation of error-handling code from the normal flow of instructions Propogate errors up the stack Group and distinguish different types of exceptions by cause 31 Throwable Types Error A non-recoverable problem occurring outside the standard java libraries or your own code that should not be caught (OutOfMemoryError, StackOverflowError, ) Exception An abnormal condition that should be caught and handled by the programmer RuntimeException Special case; does not have to be caught Usually the result of a poorly written program (integer division by zero, array out-of-bounds, etc.) A RuntimeException is considered a bug 32 16
17 Handling Exceptions 33 Java methods can catch and handle exceptions locally Catches should be ordered from subclass (more specific) to superclass (less specific) Code in Finally is always excecuted regardless of program flow try { catch (SpecificException e1) { catch (LessSpecificException e2) { catch (Exception e3) { finally { Throwing Exceptions Java methods can throw exceptions up the call stack public int divide(int a, int b) throws DivideByZeroException { if (b == 0) { throw new DivideByZeroException( divide by 0 error ); else return a/b; Calling code catches the exception and handles it or passes it further try { int x = object.divide(a, b); catch (DivideByZeroException d) { System.out.println( Exception caught + d.getmessage()); 34 17
18 Multiple Catch Clauses A single try can have more that one catch clause try {... catch (ExceptionType1 var1) { // Do something catch (ExceptionType2 var2) { // Do something else If multiple catch clauses are used, order them from the most specific to the least specific If no appropriate catch is found, the exception is handed to any outer try blocks If no catch clause is found within the method, then the exception is thrown by the method 35 Try-Catch, Example... BufferedReader in = null; String linein; try { in = new BufferedReader(new FileReader("book.txt")); while((linein = in.readline())!= null) { System.out.println(lineIn); in.close(); catch (FileNotFoundException fnfe ) { System.out.println("File not found."); catch (EOFException eofe) { System.out.println("Unexpected End of File."); catch (IOException ioe) { System.out.println("IOError reading input " + ioe); ioe.printstacktrace(); // Show stack dump 36 18
19 The finally Clause After the final catch clause, an optional finally clause may be defined The finally clause is always executed, even if the try or catch blocks are exited through a break, continue, or return try {... catch (SomeException somevar) { // Do something finally { // Always executed 37 Questions? 38 19
20 Further Reading Core Web Programming, Hall and Brown Chapters 6 and 7 Core Java 2, Volume 1 Fundamentals, Horstmann and Cornell Free Resources Thinking In Java Eckel http// The Java Tutorial http//java.sun.com/docs/books/tutorial/index.html 39 Further Reading Thinking In Java, Eckel Chapters 9 and 11 http// Core Web Programming, Hall and Brown Chapters 6 and 8 Effective Java, Bloch Core Java 2, Volume 1 Fundamentals, Horstmann and Cornell Ant The Definitive Guide, Tilly and Burke Free Resources The Java Tutorial http//java.sun.com/docs/books/tutorial/index.html Generics in the Java Programming Language http//java.sun.com/j2se/1.5/pdf/generics-tutorial.pdf 40 20
core programming Basic Java Syntax Marty Hall, Larry Brown:
core programming Basic Java Syntax 1 2001-2003 Marty Hall, Larry Brown: http:// Agenda Creating, compiling, and executing simple Java programs Accessing arrays Looping Using if statements Comparing strings
More informationJava: exceptions and genericity
Chair of Software Engineering Carlo A. Furia, Marco Piccioni, Bertrand Meyer Java: exceptions and genericity Chair of Software Engineering Carlo A. Furia, Marco Piccioni, Bertrand Meyer Exceptions Exceptions
More information15CS45 : OBJECT ORIENTED CONCEPTS
15CS45 : OBJECT ORIENTED CONCEPTS QUESTION BANK: What do you know about Java? What are the supported platforms by Java Programming Language? List any five features of Java? Why is Java Architectural Neutral?
More informationSyllabus & Curriculum for Certificate Course in Java. CALL: , for Queries
1 CONTENTS 1. Introduction to Java 2. Holding Data 3. Controllin g the f l o w 4. Object Oriented Programming Concepts 5. Inheritance & Packaging 6. Handling Error/Exceptions 7. Handling Strings 8. Threads
More informationCore Java SYLLABUS COVERAGE SYLLABUS IN DETAILS
Core Java SYLLABUS COVERAGE Introduction. OOPS Package Exception Handling. Multithreading Applet, AWT, Event Handling Using NetBean, Ecllipse. Input Output Streams, Serialization Networking Collection
More informationIntroduction to Programming Using Java (98-388)
Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;
More informationWeiss Chapter 1 terminology (parenthesized numbers are page numbers)
Weiss Chapter 1 terminology (parenthesized numbers are page numbers) assignment operators In Java, used to alter the value of a variable. These operators include =, +=, -=, *=, and /=. (9) autoincrement
More informationComputational Applications in Nuclear Astrophysics using Java Java course Lecture 6
Computational Applications in Nuclear Astrophysics using Java Java course Lecture 6 Prepared for course 160410/411 Michael C. Kunkel m.kunkel@fz-juelich.de Materials taken from; docs.oracle.com Teach Yourself
More informationCS Programming Language Java. Fall 2004 Sept. 29
CS3101-3 Programming Language Java Fall 2004 Sept. 29 Road Map today Java review Homework review Exception revisited Containers I/O What is Java A programming language A virtual machine JVM A runtime environment
More informationDOWNLOAD PDF CORE JAVA APTITUDE QUESTIONS AND ANSWERS
Chapter 1 : Chapter-wise Java Multiple Choice Questions and Answers Interview MCQs Java Programming questions and answers with explanation for interview, competitive examination and entrance test. Fully
More informationCore Java Contents. Duration: 25 Hours (1 Month)
Duration: 25 Hours (1 Month) Core Java Contents Java Introduction Java Versions Java Features Downloading and Installing Java Setup Java Environment Developing a Java Application at command prompt Java
More informationINHERITANCE & POLYMORPHISM. INTRODUCTION IB DP Computer science Standard Level ICS3U. INTRODUCTION IB DP Computer science Standard Level ICS3U
C A N A D I A N I N T E R N A T I O N A L S C H O O L O F H O N G K O N G INHERITANCE & POLYMORPHISM P2 LESSON 12 P2 LESSON 12.1 INTRODUCTION inheritance: OOP allows a programmer to define new classes
More informationCS 11 java track: lecture 3
CS 11 java track: lecture 3 This week: documentation (javadoc) exception handling more on object-oriented programming (OOP) inheritance and polymorphism abstract classes and interfaces graphical user interfaces
More informationContents. I. Classes, Superclasses, and Subclasses. Topic 04 - Inheritance
Contents Topic 04 - Inheritance I. Classes, Superclasses, and Subclasses - Inheritance Hierarchies Controlling Access to Members (public, no modifier, private, protected) Calling constructors of superclass
More information6.Introducing Classes 9. Exceptions
6.Introducing Classes 9. Exceptions Sisoft Technologies Pvt Ltd SRC E7, Shipra Riviera Bazar, Gyan Khand-3, Indirapuram, Ghaziabad Website: www.sisoft.in Email:info@sisoft.in Phone: +91-9999-283-283 Learning
More informationCMSC 132: Object-Oriented Programming II
CMSC 132: Object-Oriented Programming II Java Support for OOP Department of Computer Science University of Maryland, College Park Object Oriented Programming (OOP) OO Principles Abstraction Encapsulation
More information5/23/2015. Core Java Syllabus. VikRam ShaRma
5/23/2015 Core Java Syllabus VikRam ShaRma Basic Concepts of Core Java 1 Introduction to Java 1.1 Need of java i.e. History 1.2 What is java? 1.3 Java Buzzwords 1.4 JDK JRE JVM JIT - Java Compiler 1.5
More informationCH. 2 OBJECT-ORIENTED PROGRAMMING
CH. 2 OBJECT-ORIENTED PROGRAMMING ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN JAVA, GOODRICH, TAMASSIA AND GOLDWASSER (WILEY 2016) OBJECT-ORIENTED
More informationCSC System Development with Java. Exception Handling. Department of Statistics and Computer Science. Budditha Hettige
CSC 308 2.0 System Development with Java Exception Handling Department of Statistics and Computer Science 1 2 Errors Errors can be categorized as several ways; Syntax Errors Logical Errors Runtime Errors
More informationAgenda. Objects and classes Encapsulation and information hiding Documentation Packages
Preliminaries II 1 Agenda Objects and classes Encapsulation and information hiding Documentation Packages Inheritance Polymorphism Implementation of inheritance in Java Abstract classes Interfaces Generics
More informationExceptions. CSE 142, Summer 2002 Computer Programming 1.
Exceptions CSE 142, Summer 2002 Computer Programming 1 http://www.cs.washington.edu/education/courses/142/02su/ 12-Aug-2002 cse142-19-exceptions 2002 University of Washington 1 Reading Readings and References»
More informationExceptions. Readings and References. Exceptions. Exceptional Conditions. Reading. CSE 142, Summer 2002 Computer Programming 1.
Readings and References Exceptions CSE 142, Summer 2002 Computer Programming 1 http://www.cs.washington.edu/education/courses/142/02su/ Reading» Chapter 18, An Introduction to Programming and Object Oriented
More informationJAVA. Duration: 2 Months
JAVA Introduction to JAVA History of Java Working of Java Features of Java Download and install JDK JDK tools- javac, java, appletviewer Set path and how to run Java Program in Command Prompt JVM Byte
More informationJava Object Oriented Design. CSC207 Fall 2014
Java Object Oriented Design CSC207 Fall 2014 Design Problem Design an application where the user can draw different shapes Lines Circles Rectangles Just high level design, don t write any detailed code
More informationA Quick Tour p. 1 Getting Started p. 1 Variables p. 3 Comments in Code p. 6 Named Constants p. 6 Unicode Characters p. 8 Flow of Control p.
A Quick Tour p. 1 Getting Started p. 1 Variables p. 3 Comments in Code p. 6 Named Constants p. 6 Unicode Characters p. 8 Flow of Control p. 9 Classes and Objects p. 11 Creating Objects p. 12 Static or
More informationApplication Development in JAVA. Data Types, Variable, Comments & Operators. Part I: Core Java (J2SE) Getting Started
Application Development in JAVA Duration Lecture: Specialization x Hours Core Java (J2SE) & Advance Java (J2EE) Detailed Module Part I: Core Java (J2SE) Getting Started What is Java all about? Features
More informationJava Primer. CITS2200 Data Structures and Algorithms. Topic 2
CITS2200 Data Structures and Algorithms Topic 2 Java Primer Review of Java basics Primitive vs Reference Types Classes and Objects Class Hierarchies Interfaces Exceptions Reading: Lambert and Osborne,
More informationBuilding Java Programs
Building Java Programs A Back to Basics Approach Stuart Reges I Marty Stepp University ofwashington Preface 3 Chapter 1 Introduction to Java Programming 25 1.1 Basic Computing Concepts 26 Why Programming?
More informationAP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS
AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS PAUL L. BAILEY Abstract. This documents amalgamates various descriptions found on the internet, mostly from Oracle or Wikipedia. Very little of this
More informationFull file at Chapter 2 - Inheritance and Exception Handling
Chapter 2 - Inheritance and Exception Handling TRUE/FALSE 1. The superclass inherits all its properties from the subclass. ANS: F PTS: 1 REF: 76 2. Private members of a superclass can be accessed by a
More informationContents. Figures. Tables. Examples. Foreword. Preface. 1 Basics of Java Programming 1. xix. xxi. xxiii. xxvii. xxix
PGJC4_JSE8_OCA.book Page ix Monday, June 20, 2016 2:31 PM Contents Figures Tables Examples Foreword Preface xix xxi xxiii xxvii xxix 1 Basics of Java Programming 1 1.1 Introduction 2 1.2 Classes 2 Declaring
More informationAnnouncements. Java Graphics. Exceptions. Java Odds & Ends
Java Odds & Ends Lecture 25 CS211 Fall 2005 Final Exam Wednesday, 12/14 9:00-11:30am Uris Aud Review Session Sunday, 12/11 1:00-2:30pm Kimball B11 Check your final exam schedule! Announcements For exam
More informationLe L c e t c ur u e e 5 To T p o i p c i s c t o o b e b e co c v o e v r e ed e Exception Handling
Course Name: Advanced Java Lecture 5 Topics to be covered Exception Handling Exception HandlingHandlingIntroduction An exception is an abnormal condition that arises in a code sequence at run time A Java
More information1 Shyam sir JAVA Notes
1 Shyam sir JAVA Notes 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
More informationBrief Summary of Java
Brief Summary of Java Java programs are compiled into an intermediate format, known as bytecode, and then run through an interpreter that executes in a Java Virtual Machine (JVM). The basic syntax of Java
More informationIndex COPYRIGHTED MATERIAL
Index COPYRIGHTED MATERIAL Note to the Reader: Throughout this index boldfaced page numbers indicate primary discussions of a topic. Italicized page numbers indicate illustrations. A abstract classes
More information1.1. Annotations History Lesson - C/C++
1. Additions Thanks to Dr. James Heliotis. He started it all :) See also here: and see also here: and here: You need to use the tools from the Java release candidate 1 % bash % export PATH=/usr/local/j2sdk1.5.0-rc1/bin:$PATH
More informationLecture 20. Java Exceptional Event Handling. Dr. Martin O Connor CA166
Lecture 20 Java Exceptional Event Handling Dr. Martin O Connor CA166 www.computing.dcu.ie/~moconnor Topics What is an Exception? Exception Handler Catch or Specify Requirement Three Kinds of Exceptions
More informationCS 61B Data Structures and Programming Methodology. July 7, 2008 David Sun
CS 61B Data Structures and Programming Methodology July 7, 2008 David Sun Announcements You ve started (or finished) project 1, right? Package Visibility public declarations represent specifications what
More information40) Class can be inherited and instantiated with the package 41) Can be accessible anywhere in the package and only up to sub classes outside the
Answers 1) B 2) C 3) A 4) D 5) Non-static members 6) Static members 7) Default 8) abstract 9) Local variables 10) Data type default value 11) Data type default value 12) No 13) No 14) Yes 15) No 16) No
More informationCONTAİNERS COLLECTİONS
CONTAİNERS Some programs create too many objects and deal with them. In such a program, it is not feasible to declare a separate variable to hold reference to each of these objects. The proper way of keeping
More informationFOR BEGINNERS 3 MONTHS
JAVA FOR BEGINNERS 3 MONTHS INTRODUCTION TO JAVA Why Java was Developed Application Areas of Java History of Java Platform Independency in Java USP of Java: Java Features Sun-Oracle Deal Different Java
More informationComputer Science II (20073) Week 1: Review and Inheritance
Computer Science II 4003-232-01 (20073) Week 1: Review and Inheritance Richard Zanibbi Rochester Institute of Technology Review of CS-I Hardware and Software Hardware Physical devices in a computer system
More informationProgrammieren II. Polymorphism. Alexander Fraser. June 4, (Based on material from T. Bögel)
Programmieren II Polymorphism Alexander Fraser fraser@cl.uni-heidelberg.de (Based on material from T. Bögel) June 4, 2014 1 / 50 Outline 1 Recap - Collections 2 Advanced OOP: Polymorphism Polymorphism
More informationECE 122. Engineering Problem Solving with Java
ECE 122 Engineering Problem Solving with Java Lecture 24 Exceptions Overview Problem: Can we detect run-time errors and take corrective action? Try-catch Test for a variety of different program situations
More informationGraphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub
Lebanese University Faculty of Science Computer Science BS Degree Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub 2 Crash Course in JAVA Classes A Java
More informationCore Java - SCJP. Q2Technologies, Rajajinagar. Course content
Core Java - SCJP Course content NOTE: For exam objectives refer to the SCJP 1.6 objectives. 1. Declarations and Access Control Java Refresher Identifiers & JavaBeans Legal Identifiers. Sun's Java Code
More informationInheritance. SOTE notebook. November 06, n Unidirectional association. Inheritance ("extends") Use relationship
Inheritance 1..n Unidirectional association Inheritance ("extends") Use relationship Implementation ("implements") What is inherited public, protected methods public, proteced attributes What is not inherited
More informationCore Java Syllabus. Overview
Core Java Syllabus Overview Java programming language was originally developed by Sun Microsystems which was initiated by James Gosling and released in 1995 as core component of Sun Microsystems' Java
More informationExceptions. References. Exceptions. Exceptional Conditions. CSE 413, Autumn 2005 Programming Languages
References Exceptions "Handling Errors with Exceptions", Java tutorial http://java.sun.com/docs/books/tutorial/essential/exceptions/index.html CSE 413, Autumn 2005 Programming Languages http://www.cs.washington.edu/education/courses/413/05au/
More informationMore on Objects in JAVA TM
More on Objects in JAVA TM Inheritance : Definition: A subclass is a class that extends another class. A subclass inherits state and behavior from all of its ancestors. The term superclass refers to a
More informationBBM 102 Introduction to Programming II Spring Exceptions
BBM 102 Introduction to Programming II Spring 2018 Exceptions 1 Today What is an exception? What is exception handling? Keywords of exception handling try catch finally Throwing exceptions throw Custom
More informationcore Advanced Object-Oriented Programming in Java
core Web programming Advanced Object-Oriented Programming in Java 1 2001-2003 Marty Hall, Larry Brown http:// Agenda Overloading Designing real classes Inheritance Advanced topics Abstract classes Interfaces
More informationFundamental language mechanisms
Java Fundamentals Fundamental language mechanisms The exception mechanism What are exceptions? Exceptions are exceptional events in the execution of a program Depending on how grave the event is, the program
More informationF I N A L E X A M I N A T I O N
Faculty Of Computer Studies M257 Putting Java to Work F I N A L E X A M I N A T I O N Number of Exam Pages: (including this cover sheet( Spring 2011 April 4, 2011 ( 5 ) Time Allowed: ( 1.5 ) Hours Student
More informationPeers Techno log ies Pv t. L td. Core Java & Core Java &Adv Adv Java Java
Page 1 Peers Techno log ies Pv t. L td. Course Brochure Core Java & Core Java &Adv Adv Java Java Overview Core Java training course is intended for students without an extensive programming background.
More informationAbstract Classes, Exceptions
CISC 370: Inheritance, Abstract Classes, Exceptions June 15, 1 2006 1 Review Quizzes Grades on CPM Conventions Class names are capitalized Object names/variables are lower case String.doStuff dostuff();
More informationProgramming II (CS300)
1 Programming II (CS300) Chapter 05: Inheritance and Interfaces MOUNA KACEM mouna@cs.wisc.edu Spring 2018 Inheritance and Interfaces 2 Introduction Inheritance and Class Hierarchy Polymorphism Abstract
More information11-1. Collections. CSE 143 Java. Java 2 Collection Interfaces. Goals for Next Several Lectures
Collections CSE 143 Java Collections Most programs need to store and access collections of data Collections are worth studying because... They are widely useful in programming They provide examples of
More informationSelected Java Topics
Selected Java Topics Introduction Basic Types, Objects and Pointers Modifiers Abstract Classes and Interfaces Exceptions and Runtime Exceptions Static Variables and Static Methods Type Safe Constants Swings
More informationJava Intro 3. Java Intro 3. Class Libraries and the Java API. Outline
Java Intro 3 9/7/2007 1 Java Intro 3 Outline Java API Packages Access Rules, Class Visibility Strings as Objects Wrapper classes Static Attributes & Methods Hello World details 9/7/2007 2 Class Libraries
More informationThis page intentionally left blank
This page intentionally left blank Absolute Java, Global Edition Table of Contents Cover Title Page Copyright Page Preface Acknowledgments Brief Contents Contents Chapter 1 Getting Started 1.1 INTRODUCTION
More informationPESIT Bangalore South Campus
PESIT Bangalore South Campus 15CS45 : OBJECT ORIENTED CONCEPTS Faculty : Prof. Sajeevan K, Prof. Hanumanth Pujar Course Description: No of Sessions: 56 This course introduces computer programming using
More informationCMSC 331 Second Midterm Exam
1 20/ 2 80/ 331 First Midterm Exam 11 November 2003 3 20/ 4 40/ 5 10/ CMSC 331 Second Midterm Exam 6 15/ 7 15/ Name: Student ID#: 200/ You will have seventy-five (75) minutes to complete this closed book
More informationException-Handling Overview
م.عبد الغني أبوجبل Exception Handling No matter how good a programmer you are, you cannot control everything. Things can go wrong. Very wrong. When you write a risky method, you need code to handle the
More information1 OBJECT-ORIENTED PROGRAMMING 1
PREFACE xvii 1 OBJECT-ORIENTED PROGRAMMING 1 1.1 Object-Oriented and Procedural Programming 2 Top-Down Design and Procedural Programming, 3 Problems with Top-Down Design, 3 Classes and Objects, 4 Fields
More informationCore Java Interview Questions and Answers.
Core Java Interview Questions and Answers. Q: What is the difference between an Interface and an Abstract class? A: An abstract class can have instance methods that implement a default behavior. An Interface
More informationA Short Summary of Javali
A Short Summary of Javali October 15, 2015 1 Introduction Javali is a simple language based on ideas found in languages like C++ or Java. Its purpose is to serve as the source language for a simple compiler
More informationJava 1.8 Programming
One Introduction to Java 2 Usage of Java 3 Structure of Java 4 Flexibility of Java Programming 5 Two Running Java in Dos 6 Using the DOS Window 7 DOS Operating System Commands 8 Compiling and Executing
More informationJava Programming Training for Experienced Programmers (5 Days)
www.peaklearningllc.com Java Programming Training for Experienced Programmers (5 Days) This Java training course is intended for students with experience in a procedural or objectoriented language. It
More informationBBM 102 Introduction to Programming II Spring 2017
BBM 102 Introduction to Programming II Spring 2017 Exceptions Instructors: Ayça Tarhan, Fuat Akal, Gönenç Ercan, Vahid Garousi Today What is an exception? What is exception handling? Keywords of exception
More informationAdvanced Object-Oriented. Oriented Programming in Java. Agenda. Overloading (Continued)
Advanced Object-Oriented Oriented Programming in Java Agenda Overloading Designing real classes Inheritance Advanced topics Abstract classes Interfaces Understanding polymorphism Setting a CLASSPATH and
More informationChapter 9. Exception Handling. Copyright 2016 Pearson Inc. All rights reserved.
Chapter 9 Exception Handling Copyright 2016 Pearson Inc. All rights reserved. Last modified 2015-10-02 by C Hoang 9-2 Introduction to Exception Handling Sometimes the best outcome can be when nothing unusual
More information20 Most Important Java Programming Interview Questions. Powered by
20 Most Important Java Programming Interview Questions Powered by 1. What's the difference between an interface and an abstract class? An abstract class is a class that is only partially implemented by
More informationabstract binary class composition diamond Error Exception executable extends friend generic hash implementation implements
CS365 Midterm 1) This exam is open-note, open book. 2) You must answer all of the questions. 3) Answer all the questions on a separate sheet of paper. 4) You must use Java to implement the coding questions.
More informationExceptions and Libraries
Exceptions and Libraries RS 9.3, 6.4 Some slides created by Marty Stepp http://www.cs.washington.edu/143/ Edited by Sarah Heckman 1 Exceptions exception: An object representing an error or unusual condition.
More informationObject Oriented Design. Object-Oriented Design. Inheritance & Polymorphism. Class Hierarchy. Goals Robustness Adaptability Flexible code reuse
Object-Oriented Design Object Oriented Design Goals Robustness Adaptability Flexible code reuse Principles Abstraction Encapsulation Modularity March 2005 Object Oriented Design 1 March 2005 Object Oriented
More informationData Structure. Recitation IV
Data Structure Recitation IV Topic Java Generics Java error handling Stack Lab 2 Java Generics The following code snippet without generics requires casting: List list = new ArrayList(); list.add("hello");
More informationF1 A Java program. Ch 1 in PPIJ. Introduction to the course. The computer and its workings The algorithm concept
F1 A Java program Ch 1 in PPIJ Introduction to the course The computer and its workings The algorithm concept The structure of a Java program Classes and methods Variables Program statements Comments Naming
More informationTraining topic: OCPJP (Oracle certified professional Java programmer) or SCJP (Sun certified Java programmer) Content and Objectives
Training topic: OCPJP (Oracle certified professional Java programmer) or SCJP (Sun certified Java programmer) Content and Objectives 1 Table of content TABLE OF CONTENT... 2 1. ABOUT OCPJP SCJP... 4 2.
More informationInternal Classes and Exceptions
Internal Classes and Exceptions Object Orientated Programming in Java Benjamin Kenwright Outline Exceptions and Internal Classes Why exception handling makes your code more manageable and reliable Today
More information36. Collections. Java. Summer 2008 Instructor: Dr. Masoud Yaghini
36. Collections Java Summer 2008 Instructor: Dr. Masoud Yaghini Outline Introduction Arrays Class Interface Collection and Class Collections ArrayList Class Generics LinkedList Class Collections Algorithms
More informationCourse Description. Learn To: : Intro to JAVA SE7 and Programming using JAVA SE7. Course Outline ::
Module Title Duration : Intro to JAVA SE7 and Programming using JAVA SE7 : 9 days Course Description The Java SE 7 Fundamentals course was designed to enable students with little or no programming experience
More informationJava Interview Questions
Java Interview Questions Dear readers, these Java Interview Questions have been designed specially to get you acquainted with the nature of questions you may encounter during your interview for the subject
More informationCMSC131. Inheritance. Object. When we talked about Object, I mentioned that all Java classes are "built" on top of that.
CMSC131 Inheritance Object When we talked about Object, I mentioned that all Java classes are "built" on top of that. This came up when talking about the Java standard equals operator: boolean equals(object
More informationCSCE3193: Programming Paradigms
CSCE3193: Programming Paradigms Nilanjan Banerjee University of Arkansas Fayetteville, AR nilanb@uark.edu http://www.csce.uark.edu/~nilanb/3193/s10/ Programming Paradigms 1 Java Packages Application programmer
More informationOVERRIDING. 7/11/2015 Budditha Hettige 82
OVERRIDING 7/11/2015 (budditha@yahoo.com) 82 What is Overriding Is a language feature Allows a subclass or child class to provide a specific implementation of a method that is already provided by one of
More informationProgrammieren II. Collections. Alexander Fraser. May 28, (Based on material from T. Bögel)
Programmieren II Collections Alexander Fraser fraser@cl.uni-heidelberg.de (Based on material from T. Bögel) May 28, 2014 1 / 46 Outline 1 Recap Paths and Files Exceptions 2 Collections Collection Interfaces
More informationBasic Principles of OO. Example: Ice/Water Dispenser. Systems Thinking. Interfaces: Describing Behavior. People's Roles wrt Systems
Basics of OO Programming with Java/C# Basic Principles of OO Abstraction Encapsulation Modularity Breaking up something into smaller, more manageable pieces Hierarchy Refining through levels of abstraction
More informationObject-Oriented Design. March 2005 Object Oriented Design 1
Object-Oriented Design March 2005 Object Oriented Design 1 Object Oriented Design Goals Robustness Adaptability Flexible code reuse Principles Abstraction Encapsulation Modularity March 2005 Object Oriented
More informationTeenCoder : Java Programming (ISBN )
TeenCoder : Java Programming (ISBN 978-0-9887070-2-3) and the AP * Computer Science A Exam Requirements (Alignment to Tennessee AP CS A course code 3635) Updated March, 2015 Contains the new 2014-2015+
More informationJAVA SYLLABUS FOR 6 WEEKS
JAVA SYLLABUS FOR 6 WEEKS Java 6-Weeks INTRODUCTION TO JAVA History and Features of Java Comparison of C, C++, and Java Java Versions and its domain areas Life cycle of Java program Writing first Java
More informationJava Programming Course Overview. Duration: 35 hours. Price: $900
978.256.9077 admissions@brightstarinstitute.com Java Programming Duration: 35 hours Price: $900 Prerequisites: Basic programming skills in a structured language. Knowledge and experience with Object- Oriented
More informationFundamentals of Object Oriented Programming
INDIAN INSTITUTE OF TECHNOLOGY ROORKEE Fundamentals of Object Oriented Programming CSN- 103 Dr. R. Balasubramanian Associate Professor Department of Computer Science and Engineering Indian Institute of
More informationCOP 3330: Object Oriented Programming FALL 2017 STUDY UNION REVIEW CREDIT TO DR. GLINOS AND PROFESSOR WHITING FOR COURSE CONTENT
COP 3330: Object Oriented Programming FALL 2017 STUDY UNION REVIEW CREDIT TO DR. GLINOS AND PROFESSOR WHITING FOR COURSE CONTENT Object-Oriented Structure Program Structure Main structural elements of
More informationCS-202 Introduction to Object Oriented Programming
CS-202 Introduction to Object Oriented Programming California State University, Los Angeles Computer Science Department Lecture III Inheritance and Polymorphism Introduction to Inheritance Introduction
More informationObject Oriented Java
Object Oriented Java I. Object based programming II. Object oriented programing M. Carmen Fernández Panadero Raquel M. Crespo García Contents Polymorphism Dynamic binding Casting.
More informationTopic #9: Collections. Readings and References. Collections. Collection Interface. Java Collections CSE142 A-1
Topic #9: Collections CSE 413, Autumn 2004 Programming Languages http://www.cs.washington.edu/education/courses/413/04au/ If S is a subtype of T, what is S permitted to do with the methods of T? Typing
More informationData Structures. 02 Exception Handling
David Drohan Data Structures 02 Exception Handling JAVA: An Introduction to Problem Solving & Programming, 6 th Ed. By Walter Savitch ISBN 0132162709 2012 Pearson Education, Inc., Upper Saddle River, NJ.
More informationJava Classes. Produced by. Introduction to the Java Programming Language. Eamonn de Leastar
Java Classes Introduction to the Java Programming Language Produced by Eamonn de Leastar edeleastar@wit.ie Department of Computing, Maths & Physics Waterford Institute of Technology http://www.wit.ie http://elearning.wit.ie
More information