Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
248 views

Computational Thinking For Object Oriented Design (CTOOD)

The document discusses computational thinking for object oriented design and the Java programming language. It provides an overview of object oriented programming concepts like objects, classes, abstraction, encapsulation, inheritance, and polymorphism. It also describes key features of Java like being platform independent, portable, robust with exception handling, secure, distributed, and high performance. The document contains examples and definitions for each concept.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
248 views

Computational Thinking For Object Oriented Design (CTOOD)

The document discusses computational thinking for object oriented design and the Java programming language. It provides an overview of object oriented programming concepts like objects, classes, abstraction, encapsulation, inheritance, and polymorphism. It also describes key features of Java like being platform independent, portable, robust with exception handling, secure, distributed, and high performance. The document contains examples and definitions for each concept.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 17

Computational Thinking for Object Oriented Design (CTOOD)

Java Programming Language

Procedure Oriented Programming VS Object Oriented Programming


Procedure oriented programming belongs to Procedure oriented paradigm
C is a procedure oriented programming language
C is oriented around procedures(functions)
Object oriented Programming belongs to Object Oriented Programming
paradigm
Java is one of the Object Oriented Programming language.
The others are Python,C++,and small talk
Java implements all of the Object Oriented Programming features strictly

Object Oriented Programming System (OOPS)

 Objects
 Classes
 Abstraction
 Encapsulation
 Inheritance
 Polymorphism

Objects: An Object is a Real World entity.In other words Object is a tangible


entity which is having physical existence
An Object is an instance of a class .Instance means copy or clone
Some of the Objects
Pen,Computer,Chair,Basket,Television etc.

Classes: A Class is a Logical Entity.Classes are not having physical existence.


A Class is a Blue print or template of a set of objects
Some of the classes are
Animal,Vehicle,Employee etc.

Abstraction: Humans manage complexity of objects by using Abstraction


Abstraction hides the data(Complexity of data) of objects to simplify an
interface
Example is The outer details of Car object such as Brake and Accelerator are
revealed to the User in the name of the interfaces,But The internal Details such
as Working of Brake and Accelerator has been hidden to the User.
In Other words Abstraction focuses on the Essentials and hides the Irrelevant
or unnecessary details(data) from the user

Encapsulation:
Is a OOP Concept by which binds the data(Variables and Constants) and Code
together.
Encapsulation lays a wrapper around the data and code to restrict the
unauthorized access
Encapsulation hides data to protect it from the outside interference and
misuse.
It is also called “Data Hiding”
Encapsulation in Java can be implemented by Access Modifiers such as
“Private”
Example of Encapsulation:
A Bank Clerk can have access rights to operations of
Depositing,Withdrawal,transferring of money.
He does not having access rights to data of Staff salaries and Profit and losses
of Bank.
That means The Internal data of bank is encapsulated from the Clerk.

Inheritance:
Is a mechanism in which A Class can get the properties of another class.
In other words, an Object can get the properties another Object
Inheritance facilitates the creation of class hierarchies
Example of Inheritance
Vehicle class contains two child classes such as Motor Driven and Pulled
Vehicles
Again Motor Driven Vehicles classified into Car,Bus,Truck etc.
Pulled Vehicles again classified into Cart and Rickshaw etc.

Polymorphism:
Is a one of the OOP Concepts Polymorphism facilitates the design of a single
interface for a group of a related activities.
Polymorphism is a Greek Word,Poly means many and morphs means forms
A Single interface can be used to handle multiple forms.
Example of Polymorphism
Real Time
Dog Actions are polymorphic
If you think of Dog as a Interface.
Dog actions are different for different situations
If a Dog smells its food, it runs around it
If a Dog identifies a new person He will bark and try to attack

Programmatic:
It is possible to design a single class(single interface) for implementing stack for
various data types
It is possible to design a single interface for implementing various arithmetic
operations such as Addition,Subtraction,Multiplication and Division.

Java Features (Java Buzzwords):

Simple and Familiar


Compiled and Interpreted
Platform In
dependent
Portable
Architecture Neutral
Object Oriented
Robust
Secure
Distributed
Multithreaded and Interactive
High Performance

Dynamic and Extensible


Simple and Familiar:
Java’s Coding style is clean,that means all the complex concepts of C Language
has been withdrawn in the Java such as Pointers,Storage
Classes,Preprocessors,Operator Overloading,Multiple Inheritance and Goto
statements.
In addition there is a “Äutomatic Garbage Collection” to remove the
unreferenced objects from the memory.
Familiar means if any user knows the C or C++ then with little efforts He can
learn the Java
Again This is possible because of elimination of Complex concepts of C such as
Pointers,Storage classes,Preprocessors,Multiple Inheritance etc.

Compiled and Interpreted:


Java is both a compiled and interpreted language.Java is going to generate
the .class file(Byte Code). After compilation of a Java Source Program(.java file).
The .class file contains Byte Code,which is the platform independent code.
The Byte code can be interpreted or executed on any platform provided the
Appropriate JVM is installed on those Systems without modifying the source
program or without recompiling the source program.
Java Combines the power of Compilation and Flexibility of Interpretation.

Platform Independent:
Java is a Platform Independent Programming Language. Java is going to
generate the .class file(Byte Code). After compilation of a Java Source
Program(.java file).
The .class file contains Byte Code,which is the platform independent code.
The Byte code can be interpreted or executed on any platform provided the
Appropriate JVM is installed on those Systems without modifying the source
program or without recompiling the source program.
Portable:
Java programs are portable in the sense that the Java programs runs on any
Hardware provided the appropriate JVM has installed on those machines.
It is not the case with C/C++.These languages needs slight chages in the code
for different hardwares.
Java is having fixed memory size for its Data types for all of the Hardware
Architectures.
In C/C++ the memory size of the data types are different for different
hardware architectures.
Architectural Neutral:
The meaning of this feature of Java is program written for a platform or OS is
independent of other platforms or environments and can run on any other
operating system without recomplinig them.
In other words it is based on the “Write Once and Run Anywhere(WORA)”
approach.
Byte code is not dependent on any machine architecture and Java Virtual
Machine can easily translate bytecode into a machine specific code
This feature is very useful when we develop applets or download applications
from the Internet.

Object Oriented:
Java is a Object Oriented Programming Language.Java implements all the
features of Object Oriented Programming System(OOPS) such as
Abstraction,Encapsulation,Inheritance and Polymorphism.
Java does not create a Executable program without creation of a Class.
This means that Java Strictly follows the concept of Encapsulation.

Robust:
Java is a Robust(Trustable) Programming Language.Many of the Programming
Languages fails in the two situations .They are Memory Management and
Exception(Error) Handling.
Java handles these two situations very Efficitently
First.Java is having Efficient Memory Management such as “Automatic Garbage
Collection”,Which destroys the unreferenced Objects Automatically.
Complex Concept of C such as Pointers has been removed in the Java.
Java provides the built in support for Exception(Error) Handling.
Java handles the Exceptions(Run time errors) by using built in program
constructs such as try,catch,throw and throws

Secure:
Java provides Security for its programs as well as underlying System.
Java provides access modifiers to check memory access and also ensure that
no viruses enters a application or applet.
Java programs runs with in a Java Virtual Machine.The JVM does not allow a
Java program to access the unnecessary parts of the Memory.
Java does not allow a programmer to crate the Pointers explicitly.

Distributed:
Java programs can be distributed over the network.
The different classes of a Java program can be distributed on different systems
in a network.The communication between these different parts of a single
program is possible through a Concept of Java called Remote Method
Invocation(RMI).
Java also supports applets which are Distributed programs.The applets can be
distributed over the Internet.
Multithreded and Interactive:
Java Supports Multithreding.A Thread is a independent path of Execution of a
Program .In other words A thread is a part of program.The Different thread of
a single Java program can run simultaneously to save the processing time.
Java programs are Interactive means Java supports Commandline user
interface(CUI) and Graphical User Interface(GUI).
Command Prompt is the Command Line User Interface and AWT and Swing
provides support for Graphical User Interface.

High Performance:
The performance of Java is impressive for an Interpreted Language because of
its Byte code.Byte code generated by the Java compiler are highly optimized
So Java Virtual Machine can execute them much faster.

Dynamic and Extensible.


Java is Dynamic and Extensible means with the help of OOPS we can add
classes and new methods to classes creating new classes through sub classes.
This makes it easier for us to expand our own classes and even modify them,
All the methods of Java can be evaluated at run time dynamically.
Java also have capability of invoking the native functions(Functions of C/C++)
This is possible by using the Java Native Development Interface(JNDI).

Arrays
1. One Dimensional Arrays
2. Two Dimensional Arrays

C Language

Data type arr_name[size]; Data type name_array1[rows][cols];

Java

Syntax
One Dimensional Array:

Data type arr[]= new Data type[size];

Example: int a[]= new int[3];

Two Dimensional Array

Data type arr_name[][]= new Data type[rows][cols];


Data type[][] arr_name= new Data type[rows][cols];
Data type [][]arr_name=new Data type[rows][cols];
Data type []arr_name[]= new Data type[rows][cols];

Example:
Int arr[][]=new int[3][3];

Note : Refer the programs posted in the Group

Access Specifiers:

There are Four Access Specifiers in Java


1. Public
2. Private
3. Protected
4. Default(No Modifier)

1. Public : This Access specifier is having global access.Any class or any


programming construct can access the public methods and variables.
2. Private: This Access specifier is having limited access.only the class which is
holding the private members can access the same.
3. Protected: These members can be accessed only by the classes of the
same package and sub classes of the other packages.
4. Default: These members are accessed only by the members of the same
package (classes and sub classes

Control Statements:
There are various Control Statements available in Java
They are classified into two types

1. Selection statements
2. Iterative statements

1. Selection statement
a). If Statement
b). Switch statement

a) If statement

Four types
 Simple if
 If-else
 If-else if ladder
 Nested if
Syntax:
If(condition){
// statements
}

If(condition){
//statements
}
else{
//statements
}
If(condition){
//statements
}
else if(condition){
//statements
}
else if(condition){
//statements
}
else if(condition){
//statements
}
.
.
.

else{
//statements
}

If(condition){
If(condition){
//statements
}
else{
//statements
}
}
else{
//statements
}

Switch Statement

Syntax:
switch(condition){
case 0: //statements
break;
case 1: //statements
break;
case 2: //statements
break
.
.
.
case N: //statements
break;

default:
//statements
}
 Iterative statements

1. While loop
2. Do-while loop
3. For loop
4. For each loop
Syntax:

while(condition){
//statements
}
do{
//statements
}while(condition);

for(Initialization;Condition;Iteration){
//statements
}

for(data type loop-var: programming-construct){


//statements
}

Note : Refer the programs posted in the group

Wrapper Classes
int a;
long b=2345;
a=(int)b;

Conversion of primary data types(int ,float etc) to Wrapper classes is called as


Autoboxing
Conversion of Wrapper classes to primary types is called as Unboxing
Note: See the program shared in the Group

Classes and Methods

class class-name{
data type var1 =val1;
data type var2=val2;
data type var3=val3;
.
.
.
return type method_name1(param1,param2,param3… paramN){
//Statements
}
Return type method_name2(param1,param2,param3,… paramN){
//Statements
}
.
.

.
Return type method_nameN(param1,param2,param3…paramN){
//Statements
}
}
Note: See the program shared in the group

You might also like