26
Object Oriented Programming with Java

Short notes of oop with java

Embed Size (px)

Citation preview

Page 1: Short notes of oop with java

Object Oriented Programming with Java

Page 2: Short notes of oop with java

What is computer. Developer basic skills. Memory management in computer. Introduction to java. What is OOP. Why OOP.

Course Content

Page 3: Short notes of oop with java

an electronic device that stores and processes data.

A computer includes both hardware and software.

In general, hardware is the physical aspect of the computer that can be seen, and software is the invisible instructions that control the hardware and make it perform specific tasks.

Meaning of computer

Page 4: Short notes of oop with java

Good knowledge with two things

what will developer interact with ..?

How I will deal with it…?

Developer basic skills

Page 5: Short notes of oop with java

Computers use zeros and ones because digital devices have two stable states, referred to as zero and one by convention.

Data of various kinds, such as numbers, characters, and strings, are encoded as a series of bits (binary digits: zeros and ones).

A memory unit is an ordered sequence of bytes, each holding eight bits.

Memory management in computer

Page 6: Short notes of oop with java

Brief history of java.

Java principles.

Java features.

Memory Management in java.

Introduction to java

Page 7: Short notes of oop with java

Java was created by sun microsystems in may 1995.

Idea was to create a language to control any hardware.

Team who achieved java was green team. Leader of team was James Gosling.

Brief history of java

Page 8: Short notes of oop with java

Java is used in Desktop applications.

Wed applications.

Mobile applications.

Embedded applications.

Brief history of java

Page 9: Short notes of oop with java

Simple object oriented and easy to learn. Secure. Architecture neutral and portable. Compiled and interpreted. Execute with high performance. Treaded and dynamic.

Java Principles

Page 10: Short notes of oop with java

Java is easy to learnSyntax of C++.

Dynamic memory management(garbage collection).

No pointers.

Java features

Page 11: Short notes of oop with java

Machine and platform independent.

Java features cont’d

Page 12: Short notes of oop with java

Java is compiled and interpreted

Source Code Intermediate Code RunCompiling

one time onlyInterpreted JVM

File.java file. Class

Page 13: Short notes of oop with java

Java depends on dynamic linking of libraries.

Java features cont’d

JVM Libraries

Compiler

Page 14: Short notes of oop with java

Java is fully Object Oriented

Map up of classes.

No multiple inheritance.

Java features cont’d

Page 15: Short notes of oop with java

Java is multithreaded language

you can create programs that run multiple threads of execution in parallel.

Java features cont’d

Page 16: Short notes of oop with java

Memory management before java (manual management)

Memory Management in java

Pointers

Page 17: Short notes of oop with java

Ex: Person p = new Person();

Memory Management in java

Variables

Primitives

Objects(p)

Stack Heap

Garbage collection checks device memory every time unit (as JVM decided) and remove not usable objects and it’s contents.

new Person();

C

Page 18: Short notes of oop with java

Inheritance

abstraction

Encapsulation

Polymorphism

Object Oriented Programming(OOP)

Page 19: Short notes of oop with java

Superclass and subclass. Overloading. Overriding. Polymorphism. Encapsulation

Inheritance …

Page 20: Short notes of oop with java

The whole idea behind encapsulation is to hide the implementation details from users. If a data member is private it means it can only be accessed within the same class.

Encapsulation also known as data hiding.

Encapsulation

Page 21: Short notes of oop with java

Ex:public class A{

private int age;private String name;public void setAge(int newAge){Age = newAge;}

public int getAge(){Return age;}}Public class MainClass{Public static void main(String[]args){A a = new A();a.setAge(10);a.getAge();}}

Encapsulation cont’d

Page 22: Short notes of oop with java

• What is an exception?Definition of exceptionreasons of exceptionswhen exceptions occur

• Difference among exception and error• Why should handling exception

Exceptions

Page 23: Short notes of oop with java

An Exception can be anything which interrupts the normal flow of the program. When an exception occurs program processing gets terminated and doesn’t continue further.

In such cases we get a system generated error message. The good thing about exceptions is that they can be handled. We will cover the handling part later in this same tutorial.

Exception definition

Page 24: Short notes of oop with java

There can be several reasons for an exception. For example, following situations can cause an exception - Opening a non-existing file, Network connection problem, Operands being manipulated are out of prescribed ranges, class file missing which was supposed to be loaded and so on.

Reasons of exception

Page 25: Short notes of oop with java

Exception can occur at runtime (known as runtime exceptions) as well as at compile-time (known Compile-time exceptions).

When exception occurs …?

Page 26: Short notes of oop with java

Errors indicate serious problems and abnormal conditions that most applications should not try to handle. Error defines problems that are not expected to be caught under normal circumstances by our program. For example memory error, hardware error, JVM error etc.Exceptions are conditions within the code. A developer can handle such conditions and take necessary corrective actions. Few examples -

DivideByZero exception NullPointerException ArithmeticException ArrayIndexOutOfBoundsException

Difference among exception and error