short notes of oop with java

Post on 06-Jan-2017

537 Views

Category:

Education

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Object Oriented Programming with Java

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

Course Content

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

Good knowledge with two things

what will developer interact with ..?

How I will deal with it…?

Developer basic skills

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

Brief history of java.

Java principles.

Java features.

Memory Management in java.

Introduction to 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

Java is used in Desktop applications.

Wed applications.

Mobile applications.

Embedded applications.

Brief history of 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

Java is easy to learnSyntax of C++.

Dynamic memory management(garbage collection).

No pointers.

Java features

Machine and platform independent.

Java features cont’d

Java is compiled and interpreted

Source Code Intermediate Code RunCompiling

one time onlyInterpreted JVM

File.java file. Class

Java depends on dynamic linking of libraries.

Java features cont’d

JVM Libraries

Compiler

Java is fully Object Oriented

Map up of classes.

No multiple inheritance.

Java features cont’d

Java is multithreaded language

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

Java features cont’d

Memory management before java (manual management)

Memory Management in java

Pointers

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

Inheritance

abstraction

Encapsulation

Polymorphism

Object Oriented Programming(OOP)

Superclass and subclass. Overloading. Overriding. Polymorphism. Encapsulation

Inheritance …

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

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

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

• Difference among exception and error• Why should handling exception

Exceptions

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

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

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

When exception occurs …?

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

top related