Professional Documents
Culture Documents
TEXT BOOKS :
Java; the complete reference, 7th edition, Herbert schildt, TMH. Understanding OOP with Java, updated edition, T. Budd, pearson education.
Unit-I
Object-Oriented thinking
Need of oop paradigm / model : Object-oriented programming is a new programming model. A model helps you understand how the system works. For example, the Newton model of physics explains why apples fall to the ground. In computer science , a model explains how the elements that go into a program are organized and how they interact with one another.
Contd..
Gardeners Sally Grower Me Delivery person Flora Sallys Florist Flower Arranger Wholesaler
Contd..
The specific receiver for any given message will not be known until run time. There is a late biding between the message and code fragment( method ) used to respond to the message. In a function or procedure call, binding name to code fragment will be done at compile time only. There is an early binding.
Class Hierarchies-Inheritance
The principle that knowledge of more general category is also applicable to a more specific category is called inheritance.
Employee name salary hire_date
Professor bonus
Programmer
contract_period
Classes can be organized into a hierarchical inheritance structure. A child class (or subclass) will inherit attributes from a parent class higher in the tree. An abstract class is a class for which there are no direct instances; it is used only to create subclass.
Animal
Plant
Mammal
Flower
Dog
Florist
Potter
Flash
Flora
Elizabeth
Kenneth
Phyl
Sallys flowers
Contd..
Material Object
Animal
Flora
The search for a method to invoke in response to a given message starts with the class of the receiver. If no appropriate method is found, the search continues up the parent class chain until either a method is found or the parent class chain is exhausted.
All objects that are instances of the same class can perform the same actions. Classes are organized into a single rooted tree structure, called the inheritance hierarchy. Properties of super class are automatically available to subclasses.
Interconnectedness, the dependence of one portion of code on another portion, is responsible for this situation. Abstraction mechanisms are used to deal with this complexity and abstraction layers in object oriented software design provides some assistance to reduce complexity.
Abstraction
Abstraction is the purposeful suppression or hiding of some details of a process in order to bring out more clearly other aspects.
For example, data is stored in 512B blocks on a disk but users are presented with the higher level file abstraction. We are given variables to enter the data, but actually data will be stored in the form of 1s and 0s. Similarly header files, ex- math.h in c
polymorphism
Increases readability of the code.
Inheritance
It reduces the code size .
Contd..
Contd..
The next level of abstraction deals with the interaction between 2 individual objects where one uses services from the other. The last level of abstraction considers a single task in isolation i.e. what are the steps required to implement a single method.
Week 2 : a) Write a Java program that prompts the user for an integer and then prints out all prime numbers up to that integer. b) Write a Java program to multiply two given matrices. c) Write a Java Program that reads a line of integers, and then displays each integer, and the sum of all the integers (Use StringTokenizer class of java.util)
StringTokenizer
StringTokenizer is a class . It converts the input string into a set of tokens. To use StringTokenizer, you should specify an input string and a string that contains delimiters. Delimiters are characters that separate tokens. The default set of delimiters consists of the whitespace characters:
The StringTokenizer constructors are shown below: StringTokenizer(String str) StringTokenizer(String str, String delimiters)
Method
boolean hasMoreTokens( )
Description
Returns true if one or more tokens remain in the string and returns false if there are none. Returns the next token as a String.
String nextToken( )
Arrays
One-Dimensional Arrays :General form
type array-var[ ] = new type[size]; Ex:- int a=new int[10]; Two-Dimensional Arrays :General form
Ex:- int
a[ ][ ]=new int[3][3];