0% found this document useful (0 votes)
59 views

Lecture 1 PDF

Uploaded by

basit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
59 views

Lecture 1 PDF

Uploaded by

basit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 42

OP

OBJECT ORIENTED PROGRAMMING


Lecture 1
Books
Recommended Book:
• Introduction to Java Programming, Comprehensive Version, 10th
Edition
• By Y. Daniel Liang

Reference Books:
• Java How to Program 9th Edition
• By Deitel and Deitel

• Java The Complete Reference Ninth Edition


• By Herbert Schildt

5/12/2018 Object Oriented Programming 2


Courses and Labs

Schoology link
▪ https://app.schoology.com/course
/1533081529/materials

▪ Access Code is J9R5D-QGFS9

5/12/2018 Object Oriented Programming 3


Programming Paradigm

• Non-structured Programming
• Function/Structured Programming
• Object Oriented Programming
Programming Paradigm-Introduction

• Fundamental style of computer programming used to solve


computational problems
• Paradigm may differ in concepts and representation of elements
• Paradigm
i. Non-structured
ii. Structured
iii. Object Oriented
Non-Structured Programming Paradigm

• In this paradigm, code is used to written in a single continuous


program
• Lines in a program may be numbered or labelled
i. Allows the control flow to jump to any line
ii. This free flow of control will lead to spaghetti code resulting in lack of clarity
and difficulty in maintenance.

• Example: Basic programming language


Non-Structured Programming Limitations

• Difficult to maintain code as size of program will increase


• Difficult to test code
Function Oriented Programming
• FOP is a top down modular approach
• We can take the example of creating marks report. We can dissect
this task into subtask of
1. Reading data
2. Finding total marks
3. Finding average marks
4. Print details.
• FOP is just like breaking a large stone into small stone and then act
upon these small stone individually
• In simple words, if we write a program by using function is called FOP
Object Oriented Programming

• In OOP paradigm we write a program by using a classes and objects


• OOP has several advantages which we will come to know with
passage of time
why OOP?
• We can solve many programming problems using selections, loops,
methods, and arrays.
• However, these Java features are not sufficient for developing graphical
user interfaces and large-scale software systems.
• Suppose you want to develop a graphical user interface (GUI, pronounced
goo-ee) as shown in Figure. How would you program it?

• object-oriented programming, which you can use to develop GUI and large-
scale software systems.

5/12/2018 Object Oriented Programming 10


Class

• We can create object by using class. So first we will create class and
then we will create object.
Using C++ to create
class and its
corresponding object
Class Syntax

class ClassName
{

DataType MemberVariable;
ReturnType MemberFunction();

};
Example
class Student
{
int rollNo;
char name;
float CGPA; Member variables
char address;

Member Functions

void setName(char newName);
void setRollNo(int newRollNo);

};
Declaring class variables
• Variables of classes (objects) are declared just like variables of built-in data types

TypeName VaraibaleName;
int var;
Accessing members

• Members of an object can be accessed using


• dot operator (.) to access via the variable name
• Member variables and member functions are accessed in a similar
fashion
Example
class Student{
int rollNo;
void setRollNo(int aNo);
};

Student aStudent;
aStudent.setRollNo(5);
#include <iostream>
using namespace std;
class smallobj //define a class
{
private:
int somedata; //class data
public:

void setdata(int d) //member function to set data


{
somedata = d; }

void showdata() //member function to display data


{ cout << “Data is “ << somedata << endl; }
};
5/12/2018 Object Oriented Programming 18
int main()
{
smallobj s1; //declaring objects of class smallobj
smallobj s2;
s1.setdata(1066); //call member function to set data
s2.setdata(1776);
s1.showdata(); //call member function to display data
s2.showdata();
return 0;
}

5/12/2018 Object Oriented Programming 19


Fundamentals of Java

5/12/2018 Object Oriented Programming 20


History of Java
• Sun Microsystem started “The Green Project” in 1991. Purpose of that
project was to develop a portable language with a characteristic of write
once, run anywhere.
• Original language name: Oak
• Name changed to Java
• Java was developed by C and C++ developer
• First public release in 1995
• Write Once, Run Anywhere: To write a program that could run at any
operating system(for which there is a Java Virtual Machine) without having
to recompile the program.
• In 2010, Oracle bought Sun microsystems i.e. all the assets of Sun
microsystems including the java programming language became a part of
oracle. And now Oracle corporation manages Java long with

5/12/2018 Object Oriented Programming 21


Programming Languages
• Machine Language: A computer’s native language, which differs among
different types of computers, is its machine language. For example, to add
two numbers, you might have to write an instruction in binary code, like
this:
1101101010011010
• Assembly Language: Assembly language uses a short descriptive word,
known as a mnemonic, to represent each of the machine-language
instructions. For example, the mnemonic add typically means to add
numbers and sub means to subtract numbers. To add the numbers 2 and 3
and get the result, you might write an instruction in assembly code like this
add 2, 3, result
• Assembly language is referred to as a low-level language. An assembler
translates assembly-language instructions into machine code.
5/12/2018 Object Oriented Programming 22
Assembler

• Assembly Language:

5/12/2018 Object Oriented Programming 23


Programming Languages

• High-Level Language: are platform independent, which means that


you can write a program in a high level language and run it in
different types of machines. High-level languages are English-like and
easy to learn and use. The instructions in a high-level programming
language are called statements. Here, for example, is a high-level
language statement that computes the area of a circle with a radius of
5.
area = 5 * 5 * 3.14159;

5/12/2018 Object Oriented Programming 24


Interpreter

• An interpreter reads one statement from the source code, translates


it to the machine code or virtual machine code, and then executes it
right away

5/12/2018 Object Oriented Programming 25


Compiler

• A compiler translates the entire source code into a machine-code file,


and the machine-code file is then executed

5/12/2018 Object Oriented Programming 26


Interpreter and Compiler

• Difference Between Interpreter and Compiler

5/12/2018 Object Oriented Programming 27


Java
• Java is a “C Style” language
• Programmers of these languages will recognize the basic syntax
i. C
ii. C++
iii. C#
iv. JavaScript
v. PHP

• Java looks really different from


i. Visual Basic
ii. ColdFusion Markup Language
iii. VB.net
iv. Assembly

5/12/2018 Object Oriented Programming 28


C++ Vs Java

C++ Java

Compatible with C Not compatible with previous languages

Compiled to native machine language Compiled to bytecode

Write once, compile anywhere Write once, run anywhere

Explicit memory management and pointers. Managed memory access. In Java memory is
C++ applications can have memory leaks. managed for us. JVM automatically de-
allocates the memory for us.
Multiple inheritance Limited to single inheritance

5/12/2018 Object Oriented Programming 29


Setting up the
Environment
INSTALLING THE PREREQUISITE

30
The Java Language Specification, API, JDK, and IDE

• Read Section 1.6 of recommended book.


• This book uses Java SE to introduce Java programming.
• There are many versions of Java SE. The latest, Java SE 8, is used in
this book. Oracle releases each version with a Java Development
Toolkit (JDK). For Java SE 8, the Java Development Toolkit is called JDK
1.8 (also known as Java 8 or JDK 8).

5/12/2018 Object Oriented Programming 31


Installing JDK

• Visit the Java JDK downloads page at http://www.oracle.com/


technetwork/java/javase/downloads/jdk8-downloads-2133151.html.

32
33
Installing JDK

• In the folder where you've downloaded the JDK, right-click on the jdk-
8u51- windows-x64.exe file and select Run as administrator.

34
35
36
37
38
39

Click
Setting up the path for windows:

• Assuming you have installed Java in c:\Program


Files\java\jdk directory
• Right-click on 'My Computer' and select 'Properties'.
• Click on the 'Environment variables' button under the 'Advanced'
tab.
• Now, alter the 'Path' variable so that it also contains the path to
the Java executable. Example, if the path is currently set to
'C:\WINDOWS\SYSTEM32', then change your path to read
'C:\WINDOWS\SYSTEM32;c:\Program Files\java\jdk\bin'.

© Lethbridge/Laganière 2005 Chapter 2: Review of Object Orientation 40


Popular Java Editors

• Download and install NetBeans IDE from the link


https://netbeans.org/index.html

© Lethbridge/Laganière 2005 Chapter 2: Review of Object Orientation 41


Thank You!
All done, time for Lunch!

You might also like