COP 4331 OODP Lecture 3 TYJ Day 5

  • Slides: 11
Download presentation
COP 4331 – OOD&P Lecture 3

COP 4331 – OOD&P Lecture 3

TYJ Day 5 – Creating Classes • General structure of classes – The Class

TYJ Day 5 – Creating Classes • General structure of classes – The Class Declaration – The Class Body – Constructors • this and super – Declaring Member Variables • Method Declaration , Parameters, Method Body – Implementing Methods – Access Control

Some Classes • • Index of all classes class Object class Integer class String

Some Classes • • Index of all classes class Object class Integer class String

TYJ Day 6 – Packages • Package – Collection of related classes – Default

TYJ Day 6 – Packages • Package – Collection of related classes – Default access privilege – In a single directory • Import eliminates need for full package qualification – import java. util. Vector; – import java. awt. *;

TYJ Day 6 – Interfaces • Interface – Workaround for multiple inheritance – Specifies

TYJ Day 6 – Interfaces • Interface – Workaround for multiple inheritance – Specifies functions that must be defined in an implementing class – A class implements an interface

TYJ Day 6 – Inner Classes • Inner class – Defined inside another class

TYJ Day 6 – Inner Classes • Inner class – Defined inside another class – Can only be used inside that class

TYJ Day 7 – Exceptions. 1 • Mechanism to handle – Errors – Unusual

TYJ Day 7 – Exceptions. 1 • Mechanism to handle – Errors – Unusual situations • Exception classes – Error (major errors) – Exception (less serious) • Runtime exceptions • Other exceptions

TYJ Day 7 – Exceptions. 2 • classs Throwable – class Error – class

TYJ Day 7 – Exceptions. 2 • classs Throwable – class Error – class Exception • Exception handling – try … catch • Methods that throw exceptions – The throws clause documents that a method may throw a specified exception that must be caught or specified further

TYJ Day 7 – Exceptions. 3 • Throwing and defining exceptions – The throw

TYJ Day 7 – Exceptions. 3 • Throwing and defining exceptions – The throw statement – Creating exception subclasses

TYJ Day 7 – Threads. 1 • Threads allow several portions of a program

TYJ Day 7 – Threads. 1 • Threads allow several portions of a program to run concurrently • Designing effective threaded programs can be quite complex – Beyond the scope of this course – But some Java programs use threads in a set way

TYJ Day 7 – Threads. 2 • Threads are implemented in class Thread –

TYJ Day 7 – Threads. 2 • Threads are implemented in class Thread – Method start() starts thread – Method sleep() • Classes using threads implement the Runnable interface – Must have run() method