SlideShare a Scribd company logo
1 of 57
10/30/2015 COMSATS Institute of Information Technology, Abbottabad OOPS 1
CSC 241: Object Oriented Programming
Instructor Mr.Sharifullah Durrani
(durranisharifullah@gmail.com)
 Text books and notes1. Java How to Program, by Deitel & Deitel, 9th
edition.
2.Class Slides
 Additional books
 Absolute Java fifth Edition by Walter Savitch
 Beginning Java 2 by Ivor Horton
 Thinking in Java, by Bruce Eckel
 Java The complete reference, by Herbert Schildt, 8th edition
 Object Oriented Programming, by Ebalagurusammy
10/30/2015 COMSATS Institute of Information Technology, Abbottabad OOPS 2
10/30/2015 COMSATS Institute of Information Technology, Abbottabad OOPS 3
Course objectives
The ultimate objective of this course is to make students
familiar with the concepts of object-oriented
programming, analysis, and software development. These
concepts will be reinforced by their implementation in
Java programming language.
10/30/2015 COMSATS Institute of Information Technology, Abbottabad OOPS 4
Assignments/Lab Tasks
 Please check the CU Online subject page every day, for
notification of assignments, projects and updated information.
 Assignments may be written assignments OR programming
assignments.
 There will be a total of around 6 assignments.
 The deadline for the submission of assignment will be given with
the assignment.
 Assignments submitted after the deadline will not be accepted and
will carry ZERO MARKS.
 Cheated assignments will get ZERO MARKS.
10/30/2015 COMSATS Institute of Information Technology, Abbottabad Digital Image Processing CSC650 5
Class Project
 Projects will have ~? % weight in the total marks ( later we can
discuss).
 Projects may be conducted in groups of two-three students.
 Project topics should be selected and approved within the first few
weeks of the course.
 Project presentation date will be announced and projects will not
be accepted after the presentation date.
 Projects consisting of Downloaded codes or presentations will not
be accepted and will carry ZERO MARKS.
 Introduction
 Language Components
 Object Modeling
 Object Oriented Programming Basics
 Methods
 Arrays and Strings
 Encapsulation
 Inheritance
 Polymorphism
 Abstract Classes, Interfaces , and Inner Classes
 Exception Handling
 File Handling
 Graphics and GUI Programming
 Database Programming (JDBC)
1-6
 Java is the world’s most widely used computer
programming language.
 You’ll learn to write instructions commanding
computers to perform tasks.
 Software (i.e., the instructions you write) controls
hardware (i.e., computers).
 You’ll learn object-oriented programming—today’s
key programming methodology.
 Java Editions: SE, EE and ME
◦ Covers Java Standard Edition 8
◦ Used for developing cross-platform, general-purpose
applications.
◦ Java is used in such a broad spectrum of applications that it has
two other editions.
◦ The Java Enterprise Edition (Java EE)
◦ Geared toward developing large-scale, distributed networking
applications and web-based applications.
◦ Java Micro Edition (Java ME)
◦ geared toward developing applications for small, memory-
constrained devices, such as BlackBerry smartphones.
◦ Google’s Android operating system
1-
10
 Hardware
◦ the physical, tangible parts of a computer
◦ keyboard, monitor, disks, wires, chips, etc.
 Software
◦ programs and data
◦ a program is a series of instructions
 A computer requires both hardware and
software
 Each is essentially useless without the other
1-
11
1-
12
Central
Processing
Unit
Main
Memory
Chip that executes
program commands
Intel Pentium 4
Sun ultraSPARC III
Primary storage area
for programs and data
that are in active use
Synonymous with
RAM
1-
13
Central
Processing
Unit
Main
Memory
Floppy Disk
Hard Disk
Secondary memory
devices provide
long-term storage
Information is moved
between main memory
and secondary memory
as needed
Hard disks
Floppy disks
ZIP disks
Writable CDs
Writable DVDs
Tapes
1-
14
Central
Processing
Unit
Main
Memory
Floppy Disk
Hard Disk
Monitor
Keyboard
I/O devices facilitate
user interaction
Monitor screen
Keyboard
Mouse
Joystick
Bar code scanner
Touch screen
 Operating System
◦ controls all machine activities
◦ provides the user interface to the computer
◦ manages resources such as the CPU and memory
◦ Windows XP, Unix, Linux, Mac OS
 Application program
◦ generic term for any other kind of software
◦ word processors, missile control systems, games
 Most operating systems and application
programs have a graphical user interface (GUI)
1-
15
 Programmers write instructions in various
programming languages,
◦ directly understandable
◦ some requiring intermediate translation steps.
 These may be divided into three general types:
◦ Machine languages
◦ Assembly languages
◦ High-level languages
 Any computer can directly understand only its own machine
language, defined by its hardware design.
◦ Generally consist of strings of numbers (ultimately reduced to 1s and 0s)
that instruct computers to perform their most elementary operations one
at a time.
◦ Machine dependent—a particular machine language can be used on
only one type of computer.
 English-like abbreviations that represent elementary operations
formed the basis of assembly languages.
 Translator programs called assemblers convert early assembly-
language programs to machine language.
 High-level languages
 Allow you to write instructions that look almost like everyday English and
contain commonly used mathematical notations.
◦ Compilers convert high-level language programs into machine language.
◦ grossPay = basePay + overTimePay
 Compiling a high-level language program into machine language
can take a considerable amount of computer time.
 Interpreter programs execute high-level language programs directly,
although slower than compiled programs run.
Object-oriented programming (OOP) is a way to
organize and conceptualize a program as a set of
interacting objects.
 The programmer defines the types of objects that will
exist.
 The programmer creates object instances as they are
needed.
 The programmer specifies how these various object
will communicate and interact with each other.
Real-world objects have attributes and behaviors.
Examples:
 Dog
◦ Attributes: breed, color, hungry, tired, etc.
◦ Behaviors: eating, sleeping, etc.
 Bank Account
◦ Attributes: account number, owner, balance
◦ Behaviors: withdraw, deposit
 Writing software often involves creating a
computational model of real-world objects and
processes.
 Object-oriented programming is a methodology that
gives programmers tools to make this modeling process
easier.
 Software objects, like real-world objects, have attributes
and behaviors.
 In object-oriented languages,
they are defined together.
◦ An object is a
collection of attributes
and the behaviors that
operate on them.
 Variables in an object are
called attributes.
 Procedures associated with
an object are called methods.
In traditional programming languages (Fortran, Cobol, C, etc)
data structures and procedures are defined separately.
Account
Account
Account
balance:
number:
Bank
deposit()
withdraw()
The definitions of the attributes and methods of an object are
organized into a class. Thus, a class is the generic definition
for a set of similar objects (i.e. Person as a generic definition
for Ali, Ahmed and Sulman)
 A class can be thought of as a template used to create a set of
objects.
 A class is a static definition; a piece of code written in a
programming language.
 One or more objects described by the class are instantiated at
runtime.
 The objects are called instances of the class.
 Each instance will have its own distinct set of
attributes.
 Every instance of the same class will have the same set
of attributes;
◦ every object has the same attributes but,
◦ each instance will have its own distinct values for those
attributes.
 The "account" class
describes the attributes
and behaviors of bank
accounts.
 The “account” class
defines two state variables
(account number and
balance) and two methods
(deposit and withdraw).
class: Account
deposit()
withdraw()
balance:
number:
 When the program runs
there will be many
instances of the account
class.
 Each instance will have its
own account number and
balance (object state)
 Methods can only be
invoked .
balance: $240
number: 712
balance: $941
number: 036
balance: $19
number: 054
Instance #1
Instance #2
Instance #3
 Messages and Methods Calls
◦ When you drive a car, pressing its gas pedal sends a message
to the car to perform a task—that is, to go faster.
◦ Similarly, you send messages to an object.
◦ Each message is implemented as a method call that tells a
method of the object to perform its task.
 Reuse
◦ Reuse of existing classes when building new classes and
programs saves time and effort.
◦ Reuse also helps you build more reliable and effective systems,
because existing classes and components often have gone
through extensive testing, debugging and performance tuning.
◦ How will you create the code (i.e., the program instructions)
for your programs?
◦ Follow a detailed analysis process for determining your
project’s requirements (i.e., defining what the system is
supposed to do)
◦ Develop a design that satisfies them (i.e., deciding how the
system should do it).
◦ Carefully review the design (and have your design reviewed by
other software professionals) before writing any code.
◦ Analyzing and designing your system from an object-oriented
point of view is called an object-oriented analysis and design
(OOAD) process.
◦ Languages like Java are object oriented.
◦ Object-oriented programming (OOP) allows you to implement
an object-oriented design as a working system.
 The UML (Unified Modeling Language)
◦ The Unified Modeling Language (UML) is the most widely
used graphical scheme for modeling object-oriented systems.
 1991
◦ Sun Microsystems funded an internal corporate research
project led by James Gosling, which resulted in a C++-based
object-oriented programming language Sun called Java.
◦ Key goal of Java is to be able to write programs that will run
on a great variety of computer systems and computer-control
devices.
◦ This is sometimes called “write once, run anywhere.”
 Sun Microsystems was acquired by Oracle in 2009.
 As of 2010 97% of enterprise desktops, three billion
handsets, and 80 million television devices run Java.
 Java is the most widely used software development
language in the world.
 Java Class Libraries
◦ Rich collections of existing classes and methods
◦ Also known as the Java APIs (Application Programming
Interfaces).
 Java programs normally go through five
phases
◦ edit
◦ compile
◦ load
◦ verify
◦ Execute.
 Phase 1 consists of editing a file
◦ Type a Java program (source code) using the editor.
◦ Make any necessary corrections.
◦ Save the program.
◦ A file name ending with the .java extension indicates that the
file contains Java source code.
 Integrated development environments (IDEs)
Provide tools that support the software development process,
including editors for writing and editing programs and
debuggers for locating logic errors—errors that cause
programs to execute incorrectly.
Popular IDEs
Eclipse (www.eclipse.org)
NetBeans (www.netbeans.org).
jGRASP™ IDE (www.jgrasp.org)
DrJava IDE (www.drjava.org/download.shtml)
BlueJ IDE (www.bluej.org/)
TextPad® Text Editor for Windows®
(www.textpad.com/)
 Phase 2: Compiling a Java Program into Bytecodes
◦ Use the command javac (the Java compiler) to compile a
program.
◦ For example, to compile a program called Welcome.java
 javac Welcome.java
◦ If the program compiles, the compiler produces a .class file
called Welcome.class that contains the compiled version
of the program.
 Java compiler translates Java source code into bytecodes
that represent the tasks to execute.
 Bytecodes are executed by the Java Virtual Machine (JVM)
◦ a part of the JDK and the foundation of the Java platform.
 Virtual machine (VM)—a software application that
simulates a computer
◦ Hides the underlying operating system and hardware from the
programs that interact with it.
 Bytecodes are platform independent
◦ They do not depend on a particular hardware platform.
 Bytecodes are portable
◦ The same bytecodes can execute on any platform containing a JVM
that understands the version of Java in which the bytecodes were
compiled.
 The JVM is invoked by the java command. For example, to
execute a Java application called Welcome, you’d type the
command
 java Welcome
 Phase 3: Loading a Program into Memory
◦ The JVM places the program in memory to execute it—this is
known as loading.
◦ Class loader takes the .class files containing the program’s
bytecodes and transfers them to primary memory.
◦ Also loads any of the .class files provided by Java that your
program uses.
 Phase 4: Bytecode Verification
◦ As the classes are loaded, the bytecode verifier examines their
bytecodes
◦ Ensures that they’re valid and do not violate Java’s security
restrictions.
 Java enforces strong security to make sure that Java
programs arriving over the network do not damage
your files or your system (as computer viruses and
worms might).
 Phase 5: Execution
◦ The JVM executes the program’s bytecodes.
◦ JVMs typically execute bytecodes using a combination of
interpretation and so-called just-in-time (JIT) compilation.
◦ A just-in-time (JIT) compiler—known as the Java HotSpot
compiler—translates the bytecodes into the underlying computer’s
machine language.
◦ When the JVM encounters these compiled parts again, the
faster machine-language code executes.
 Java programs go through two compilation phases
1- Source code is translated into bytecodes
2- during execution, the bytecodes are translated into machine
language for the actual computer on which the program
executes.
 In the Java programming language:
◦ A program is made up of one or more classes
◦ A class contains one or more methods
◦ A method contains program statements
 A Java application always contains a method called
main
1-
44
1-
45
public class MyProgram
{
}
// comments about the class
class header
class body
Comments can be placed almost anywhere
1-
46
public class MyProgram
{
}
// comments about the class
public static void main (String[] args)
{
}
// comments about the method
method header
method body
 Comments in a program are called inline
documentation
 They should be included to explain the purpose of
the program and describe processing steps
 They do not affect how a program works
 Java comments can take three forms:
1-
47
// this comment runs to the end of the line
/* this comment runs to the terminating
symbol, even across line breaks */
/** this is a javadoc comment */
 Identifiers are the words a programmer uses in a program
 An identifier can be made up of letters, digits, the
underscore character ( _ ), and the dollar sign
 Identifiers cannot begin with a digit
 Java is case sensitive - Total, total, and TOTAL are different
identifiers
 By convention, programmers use different case styles for
different types of identifiers, such as
◦ title case for class names - MyClass
◦ upper case for constants - MAXIMUM
1-
48
 Sometimes we choose identifiers ourselves when
writing a program (such as MyClass)
 Sometimes we are using another programmer's
code, so we use the identifiers that he or she
chose (such as println)
 Often we use special identifiers called reserved
words that already have a predefined meaning in
the language
 A reserved word cannot be used in any other way
1-
49
 The Java reserved words:
1-
50
abstract
boolean
break
byte
case
catch
char
class
const
continue
default
do
double
else
enum
extends
false
final
finally
float
for
goto
if
implements
import
instanceof
int
interface
long
native
new
null
package
private
protected
public
return
short
static
strictfp
super
switch
synchronized
this
throw
throws
transient
true
try
void
volatile
while
 Spaces, blank lines, and tabs are called
white space
 White space is used to separate words and
symbols in a program
 Extra white space is ignored
 A valid Java program can be formatted many
ways
 Programs should be formatted to enhance
readability, using consistent indentation
1-
51
 The syntax rules of a language define how we
can put together symbols, reserved words, and
identifiers to make a valid program
 The semantics of a program statement define
what that statement means (its purpose or role in
a program)
 A program that is syntactically correct is not
necessarily logically (semantically) correct
 A program will always do what we tell it to do,
not what we meant to tell it to do
1-
52
 A program can have three types of errors
 The compiler will find syntax errors and other basic
problems (compile-time errors)
◦ If compile-time errors exist, an executable version of the
program is not created
 A problem can occur during program execution, such
as trying to divide by zero, which causes a program
to terminate abnormally (run-time errors)
 A program may run, but produce incorrect results,
perhaps using an incorrect formula (logical errors)
1-
53
import java.util.Scanner;
/**
*
* @author jadoon
*/
public class HelloWorldApp {
public static void main(String[] args) {
Scanner reader = new Scanner(System.in); //is used to take input
// TODO code application logic here
System.out.println("Welcome to my first java program");
System.out.println("Please Enter In Your First Name: ");
String firstName = reader.nextLine();
1-
54
System.out.println("Please Enter In The Year You Were Born: ");
String bornYear = reader.nextLine();
System.out.println("Please Enter In The Current Year: ");
String thisYear = reader.nextLine();
int bYear = Integer.parseInt(bornYear);//convert data type
int tYear = Integer.parseInt(thisYear);
int yold=tYear-bYear;
System.out.println("Hello "+ firstName +" your age is " + yold);
}//main method
}//class
1-
55
 public class HelloWorld {
 public static void main(String[] args) {
 // Display the string.
 System.out.println("Hello World!");
 System.out.println("My first java program");
 }
 }
 Save HelloWorld.java
 Open cmd
 SET PATH=%PATH%;C:JDK1.2BIN
 Javac HelloWorld.java
 Java HelloWorld
COMSATS OOPS Course Overview

More Related Content

What's hot

Generations of programming language
Generations of programming languageGenerations of programming language
Generations of programming languageJAIDEVPAUL
 
So you want to be a programmer
So you want to be a programmerSo you want to be a programmer
So you want to be a programmerBusayo Oyebisi
 
Lang generations 7557_syed_ghazanfarnaqvi_saturday
Lang generations 7557_syed_ghazanfarnaqvi_saturdayLang generations 7557_syed_ghazanfarnaqvi_saturday
Lang generations 7557_syed_ghazanfarnaqvi_saturdaySyed Naqvi
 
Types of Programming Languages
Types of Programming LanguagesTypes of Programming Languages
Types of Programming LanguagesJuhi Bhoyar
 
Programming Languages and Program Develompent
Programming Languages and Program DevelompentProgramming Languages and Program Develompent
Programming Languages and Program DevelompentSamudin Kassan
 
Programming languages
Programming languagesProgramming languages
Programming languagesAkash Varaiya
 
What is Coding
What is CodingWhat is Coding
What is CodingRoboGarden
 
Lecture 5 - Structured Programming Language
Lecture 5 - Structured Programming Language Lecture 5 - Structured Programming Language
Lecture 5 - Structured Programming Language Md. Imran Hossain Showrov
 
Object Oriented Programming in Java
Object Oriented Programming in JavaObject Oriented Programming in Java
Object Oriented Programming in JavaHimanshiSingh71
 
Computer programming
Computer programmingComputer programming
Computer programmingSuneel Dogra
 
Computer programming language concept
Computer programming language conceptComputer programming language concept
Computer programming language conceptAfiq Sajuri
 

What's hot (20)

Generations of programming language
Generations of programming languageGenerations of programming language
Generations of programming language
 
So you want to be a programmer
So you want to be a programmerSo you want to be a programmer
So you want to be a programmer
 
Lang generations 7557_syed_ghazanfarnaqvi_saturday
Lang generations 7557_syed_ghazanfarnaqvi_saturdayLang generations 7557_syed_ghazanfarnaqvi_saturday
Lang generations 7557_syed_ghazanfarnaqvi_saturday
 
Basic Meaning of Computer languages
Basic Meaning of Computer languagesBasic Meaning of Computer languages
Basic Meaning of Computer languages
 
Types of Programming Languages
Types of Programming LanguagesTypes of Programming Languages
Types of Programming Languages
 
Programming Languages
Programming LanguagesProgramming Languages
Programming Languages
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
 
Programming Languages and Program Develompent
Programming Languages and Program DevelompentProgramming Languages and Program Develompent
Programming Languages and Program Develompent
 
Programming languages
Programming languagesProgramming languages
Programming languages
 
Programming Language
Programming LanguageProgramming Language
Programming Language
 
What is Coding
What is CodingWhat is Coding
What is Coding
 
Lecture 5 - Structured Programming Language
Lecture 5 - Structured Programming Language Lecture 5 - Structured Programming Language
Lecture 5 - Structured Programming Language
 
La5 programming
La5  programmingLa5  programming
La5 programming
 
Chapter 5
Chapter 5Chapter 5
Chapter 5
 
Lecture 21 - Preprocessor and Header File
Lecture 21 - Preprocessor and Header FileLecture 21 - Preprocessor and Header File
Lecture 21 - Preprocessor and Header File
 
SYSTEM DEVELOPMENT
SYSTEM DEVELOPMENTSYSTEM DEVELOPMENT
SYSTEM DEVELOPMENT
 
Object Oriented Programming in Java
Object Oriented Programming in JavaObject Oriented Programming in Java
Object Oriented Programming in Java
 
Computer programming
Computer programmingComputer programming
Computer programming
 
Computer programming language concept
Computer programming language conceptComputer programming language concept
Computer programming language concept
 
Abhinav ca ppt
Abhinav ca pptAbhinav ca ppt
Abhinav ca ppt
 

Viewers also liked

Computer science study material
Computer science study materialComputer science study material
Computer science study materialSwarup Kumar Boro
 
Revision notes for exam 2011 computer science with C++
Revision notes for exam 2011 computer science with C++Revision notes for exam 2011 computer science with C++
Revision notes for exam 2011 computer science with C++Deepak Singh
 
AI and Python: Developing a Conversational Interface using Python
AI and Python: Developing a Conversational Interface using PythonAI and Python: Developing a Conversational Interface using Python
AI and Python: Developing a Conversational Interface using Pythonamyiris
 
+2 Computer Science - Volume II Notes
+2 Computer Science - Volume II Notes+2 Computer Science - Volume II Notes
+2 Computer Science - Volume II NotesAndrew Raj
 
C++ Notes by Hisham Ahmed Rizvi for Class 12th Board Exams
C++ Notes by Hisham Ahmed Rizvi for Class 12th Board ExamsC++ Notes by Hisham Ahmed Rizvi for Class 12th Board Exams
C++ Notes by Hisham Ahmed Rizvi for Class 12th Board Examshishamrizvi
 
Introduction to Python
Introduction to Python Introduction to Python
Introduction to Python amiable_indian
 
Intro. to prog. c++
Intro. to prog. c++Intro. to prog. c++
Intro. to prog. c++KurdGul
 
Python入門 : 4日間コース社内トレーニング
Python入門 : 4日間コース社内トレーニングPython入門 : 4日間コース社内トレーニング
Python入門 : 4日間コース社内トレーニングYuichi Ito
 
AI Agent and Chatbot Trends For Enterprises
AI Agent and Chatbot Trends For EnterprisesAI Agent and Chatbot Trends For Enterprises
AI Agent and Chatbot Trends For EnterprisesTeewee Ang
 

Viewers also liked (11)

Savitch Ch 04
Savitch Ch 04Savitch Ch 04
Savitch Ch 04
 
Savitch Ch 05
Savitch Ch 05Savitch Ch 05
Savitch Ch 05
 
Computer science study material
Computer science study materialComputer science study material
Computer science study material
 
Revision notes for exam 2011 computer science with C++
Revision notes for exam 2011 computer science with C++Revision notes for exam 2011 computer science with C++
Revision notes for exam 2011 computer science with C++
 
AI and Python: Developing a Conversational Interface using Python
AI and Python: Developing a Conversational Interface using PythonAI and Python: Developing a Conversational Interface using Python
AI and Python: Developing a Conversational Interface using Python
 
+2 Computer Science - Volume II Notes
+2 Computer Science - Volume II Notes+2 Computer Science - Volume II Notes
+2 Computer Science - Volume II Notes
 
C++ Notes by Hisham Ahmed Rizvi for Class 12th Board Exams
C++ Notes by Hisham Ahmed Rizvi for Class 12th Board ExamsC++ Notes by Hisham Ahmed Rizvi for Class 12th Board Exams
C++ Notes by Hisham Ahmed Rizvi for Class 12th Board Exams
 
Introduction to Python
Introduction to Python Introduction to Python
Introduction to Python
 
Intro. to prog. c++
Intro. to prog. c++Intro. to prog. c++
Intro. to prog. c++
 
Python入門 : 4日間コース社内トレーニング
Python入門 : 4日間コース社内トレーニングPython入門 : 4日間コース社内トレーニング
Python入門 : 4日間コース社内トレーニング
 
AI Agent and Chatbot Trends For Enterprises
AI Agent and Chatbot Trends For EnterprisesAI Agent and Chatbot Trends For Enterprises
AI Agent and Chatbot Trends For Enterprises
 

Similar to COMSATS OOPS Course Overview

Similar to COMSATS OOPS Course Overview (20)

Chapter 1
Chapter 1Chapter 1
Chapter 1
 
The Concept Of Abstract Data Types
The Concept Of Abstract Data TypesThe Concept Of Abstract Data Types
The Concept Of Abstract Data Types
 
Lecture 1.pptx
Lecture 1.pptxLecture 1.pptx
Lecture 1.pptx
 
Unit 1
Unit 1Unit 1
Unit 1
 
10tait
10tait10tait
10tait
 
Chapter 10
Chapter 10 Chapter 10
Chapter 10
 
ICT-DBA4 -05-0811-Apply-Object-Oriented-Programming-Language-Skills.doc
ICT-DBA4 -05-0811-Apply-Object-Oriented-Programming-Language-Skills.docICT-DBA4 -05-0811-Apply-Object-Oriented-Programming-Language-Skills.doc
ICT-DBA4 -05-0811-Apply-Object-Oriented-Programming-Language-Skills.doc
 
Unit 1 introduction to c++.pptx
Unit 1 introduction to c++.pptxUnit 1 introduction to c++.pptx
Unit 1 introduction to c++.pptx
 
Programming using C++ - slides.pptx
Programming using C++ - slides.pptxProgramming using C++ - slides.pptx
Programming using C++ - slides.pptx
 
PCCF Unit 2.pptx
PCCF Unit 2.pptxPCCF Unit 2.pptx
PCCF Unit 2.pptx
 
Introduction to java
Introduction to  javaIntroduction to  java
Introduction to java
 
Intro1
Intro1Intro1
Intro1
 
Programming Paradigm & Languages
Programming Paradigm & LanguagesProgramming Paradigm & Languages
Programming Paradigm & Languages
 
Programming Paradigm & Languages
Programming Paradigm & LanguagesProgramming Paradigm & Languages
Programming Paradigm & Languages
 
DivyaVenkatesh_CV
DivyaVenkatesh_CVDivyaVenkatesh_CV
DivyaVenkatesh_CV
 
Java Is A Programming Dialect And Registering Stage Essay
Java Is A Programming Dialect And Registering Stage EssayJava Is A Programming Dialect And Registering Stage Essay
Java Is A Programming Dialect And Registering Stage Essay
 
Introduction to object oriented language
Introduction to object oriented languageIntroduction to object oriented language
Introduction to object oriented language
 
SE-IT JAVA LAB OOP CONCEPT
SE-IT JAVA LAB OOP CONCEPTSE-IT JAVA LAB OOP CONCEPT
SE-IT JAVA LAB OOP CONCEPT
 
Ic lecture8
Ic lecture8 Ic lecture8
Ic lecture8
 
Java
JavaJava
Java
 

Recently uploaded

Understanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM ArchitectureUnderstanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM Architecturerahul_net
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsSafe Software
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Rob Geurden
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...OnePlan Solutions
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxAndreas Kunz
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfStefano Stabellini
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Developmentvyaparkranti
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringHironori Washizaki
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsChristian Birchler
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxReal-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxRTS corp
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfMarharyta Nedzelska
 

Recently uploaded (20)

2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva
 
Understanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM ArchitectureUnderstanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM Architecture
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data Streams
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdf
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Development
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their Engineering
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxReal-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdf
 

COMSATS OOPS Course Overview

  • 1. 10/30/2015 COMSATS Institute of Information Technology, Abbottabad OOPS 1 CSC 241: Object Oriented Programming Instructor Mr.Sharifullah Durrani (durranisharifullah@gmail.com)  Text books and notes1. Java How to Program, by Deitel & Deitel, 9th edition. 2.Class Slides  Additional books  Absolute Java fifth Edition by Walter Savitch  Beginning Java 2 by Ivor Horton  Thinking in Java, by Bruce Eckel  Java The complete reference, by Herbert Schildt, 8th edition  Object Oriented Programming, by Ebalagurusammy
  • 2. 10/30/2015 COMSATS Institute of Information Technology, Abbottabad OOPS 2
  • 3. 10/30/2015 COMSATS Institute of Information Technology, Abbottabad OOPS 3 Course objectives The ultimate objective of this course is to make students familiar with the concepts of object-oriented programming, analysis, and software development. These concepts will be reinforced by their implementation in Java programming language.
  • 4. 10/30/2015 COMSATS Institute of Information Technology, Abbottabad OOPS 4 Assignments/Lab Tasks  Please check the CU Online subject page every day, for notification of assignments, projects and updated information.  Assignments may be written assignments OR programming assignments.  There will be a total of around 6 assignments.  The deadline for the submission of assignment will be given with the assignment.  Assignments submitted after the deadline will not be accepted and will carry ZERO MARKS.  Cheated assignments will get ZERO MARKS.
  • 5. 10/30/2015 COMSATS Institute of Information Technology, Abbottabad Digital Image Processing CSC650 5 Class Project  Projects will have ~? % weight in the total marks ( later we can discuss).  Projects may be conducted in groups of two-three students.  Project topics should be selected and approved within the first few weeks of the course.  Project presentation date will be announced and projects will not be accepted after the presentation date.  Projects consisting of Downloaded codes or presentations will not be accepted and will carry ZERO MARKS.
  • 6.  Introduction  Language Components  Object Modeling  Object Oriented Programming Basics  Methods  Arrays and Strings  Encapsulation  Inheritance  Polymorphism  Abstract Classes, Interfaces , and Inner Classes  Exception Handling  File Handling  Graphics and GUI Programming  Database Programming (JDBC) 1-6
  • 7.  Java is the world’s most widely used computer programming language.  You’ll learn to write instructions commanding computers to perform tasks.  Software (i.e., the instructions you write) controls hardware (i.e., computers).  You’ll learn object-oriented programming—today’s key programming methodology.
  • 8.  Java Editions: SE, EE and ME ◦ Covers Java Standard Edition 8 ◦ Used for developing cross-platform, general-purpose applications. ◦ Java is used in such a broad spectrum of applications that it has two other editions. ◦ The Java Enterprise Edition (Java EE) ◦ Geared toward developing large-scale, distributed networking applications and web-based applications.
  • 9. ◦ Java Micro Edition (Java ME) ◦ geared toward developing applications for small, memory- constrained devices, such as BlackBerry smartphones. ◦ Google’s Android operating system
  • 10. 1- 10
  • 11.  Hardware ◦ the physical, tangible parts of a computer ◦ keyboard, monitor, disks, wires, chips, etc.  Software ◦ programs and data ◦ a program is a series of instructions  A computer requires both hardware and software  Each is essentially useless without the other 1- 11
  • 12. 1- 12 Central Processing Unit Main Memory Chip that executes program commands Intel Pentium 4 Sun ultraSPARC III Primary storage area for programs and data that are in active use Synonymous with RAM
  • 13. 1- 13 Central Processing Unit Main Memory Floppy Disk Hard Disk Secondary memory devices provide long-term storage Information is moved between main memory and secondary memory as needed Hard disks Floppy disks ZIP disks Writable CDs Writable DVDs Tapes
  • 14. 1- 14 Central Processing Unit Main Memory Floppy Disk Hard Disk Monitor Keyboard I/O devices facilitate user interaction Monitor screen Keyboard Mouse Joystick Bar code scanner Touch screen
  • 15.  Operating System ◦ controls all machine activities ◦ provides the user interface to the computer ◦ manages resources such as the CPU and memory ◦ Windows XP, Unix, Linux, Mac OS  Application program ◦ generic term for any other kind of software ◦ word processors, missile control systems, games  Most operating systems and application programs have a graphical user interface (GUI) 1- 15
  • 16.  Programmers write instructions in various programming languages, ◦ directly understandable ◦ some requiring intermediate translation steps.  These may be divided into three general types: ◦ Machine languages ◦ Assembly languages ◦ High-level languages
  • 17.  Any computer can directly understand only its own machine language, defined by its hardware design. ◦ Generally consist of strings of numbers (ultimately reduced to 1s and 0s) that instruct computers to perform their most elementary operations one at a time. ◦ Machine dependent—a particular machine language can be used on only one type of computer.  English-like abbreviations that represent elementary operations formed the basis of assembly languages.  Translator programs called assemblers convert early assembly- language programs to machine language.
  • 18.  High-level languages  Allow you to write instructions that look almost like everyday English and contain commonly used mathematical notations. ◦ Compilers convert high-level language programs into machine language. ◦ grossPay = basePay + overTimePay  Compiling a high-level language program into machine language can take a considerable amount of computer time.  Interpreter programs execute high-level language programs directly, although slower than compiled programs run.
  • 19. Object-oriented programming (OOP) is a way to organize and conceptualize a program as a set of interacting objects.  The programmer defines the types of objects that will exist.  The programmer creates object instances as they are needed.  The programmer specifies how these various object will communicate and interact with each other.
  • 20. Real-world objects have attributes and behaviors. Examples:  Dog ◦ Attributes: breed, color, hungry, tired, etc. ◦ Behaviors: eating, sleeping, etc.  Bank Account ◦ Attributes: account number, owner, balance ◦ Behaviors: withdraw, deposit
  • 21.  Writing software often involves creating a computational model of real-world objects and processes.  Object-oriented programming is a methodology that gives programmers tools to make this modeling process easier.  Software objects, like real-world objects, have attributes and behaviors.
  • 22.  In object-oriented languages, they are defined together. ◦ An object is a collection of attributes and the behaviors that operate on them.  Variables in an object are called attributes.  Procedures associated with an object are called methods. In traditional programming languages (Fortran, Cobol, C, etc) data structures and procedures are defined separately. Account Account Account balance: number: Bank deposit() withdraw()
  • 23. The definitions of the attributes and methods of an object are organized into a class. Thus, a class is the generic definition for a set of similar objects (i.e. Person as a generic definition for Ali, Ahmed and Sulman)  A class can be thought of as a template used to create a set of objects.  A class is a static definition; a piece of code written in a programming language.  One or more objects described by the class are instantiated at runtime.  The objects are called instances of the class.
  • 24.  Each instance will have its own distinct set of attributes.  Every instance of the same class will have the same set of attributes; ◦ every object has the same attributes but, ◦ each instance will have its own distinct values for those attributes.
  • 25.  The "account" class describes the attributes and behaviors of bank accounts.  The “account” class defines two state variables (account number and balance) and two methods (deposit and withdraw). class: Account deposit() withdraw() balance: number:
  • 26.  When the program runs there will be many instances of the account class.  Each instance will have its own account number and balance (object state)  Methods can only be invoked . balance: $240 number: 712 balance: $941 number: 036 balance: $19 number: 054 Instance #1 Instance #2 Instance #3
  • 27.  Messages and Methods Calls ◦ When you drive a car, pressing its gas pedal sends a message to the car to perform a task—that is, to go faster. ◦ Similarly, you send messages to an object. ◦ Each message is implemented as a method call that tells a method of the object to perform its task.  Reuse ◦ Reuse of existing classes when building new classes and programs saves time and effort. ◦ Reuse also helps you build more reliable and effective systems, because existing classes and components often have gone through extensive testing, debugging and performance tuning.
  • 28. ◦ How will you create the code (i.e., the program instructions) for your programs? ◦ Follow a detailed analysis process for determining your project’s requirements (i.e., defining what the system is supposed to do) ◦ Develop a design that satisfies them (i.e., deciding how the system should do it). ◦ Carefully review the design (and have your design reviewed by other software professionals) before writing any code.
  • 29. ◦ Analyzing and designing your system from an object-oriented point of view is called an object-oriented analysis and design (OOAD) process. ◦ Languages like Java are object oriented. ◦ Object-oriented programming (OOP) allows you to implement an object-oriented design as a working system.  The UML (Unified Modeling Language) ◦ The Unified Modeling Language (UML) is the most widely used graphical scheme for modeling object-oriented systems.
  • 30.  1991 ◦ Sun Microsystems funded an internal corporate research project led by James Gosling, which resulted in a C++-based object-oriented programming language Sun called Java. ◦ Key goal of Java is to be able to write programs that will run on a great variety of computer systems and computer-control devices. ◦ This is sometimes called “write once, run anywhere.”
  • 31.  Sun Microsystems was acquired by Oracle in 2009.  As of 2010 97% of enterprise desktops, three billion handsets, and 80 million television devices run Java.  Java is the most widely used software development language in the world.  Java Class Libraries ◦ Rich collections of existing classes and methods ◦ Also known as the Java APIs (Application Programming Interfaces).
  • 32.  Java programs normally go through five phases ◦ edit ◦ compile ◦ load ◦ verify ◦ Execute.
  • 33.  Phase 1 consists of editing a file ◦ Type a Java program (source code) using the editor. ◦ Make any necessary corrections. ◦ Save the program. ◦ A file name ending with the .java extension indicates that the file contains Java source code.
  • 34.  Integrated development environments (IDEs) Provide tools that support the software development process, including editors for writing and editing programs and debuggers for locating logic errors—errors that cause programs to execute incorrectly. Popular IDEs Eclipse (www.eclipse.org) NetBeans (www.netbeans.org). jGRASP™ IDE (www.jgrasp.org) DrJava IDE (www.drjava.org/download.shtml) BlueJ IDE (www.bluej.org/) TextPad® Text Editor for Windows® (www.textpad.com/)
  • 35.  Phase 2: Compiling a Java Program into Bytecodes ◦ Use the command javac (the Java compiler) to compile a program. ◦ For example, to compile a program called Welcome.java  javac Welcome.java ◦ If the program compiles, the compiler produces a .class file called Welcome.class that contains the compiled version of the program.
  • 36.  Java compiler translates Java source code into bytecodes that represent the tasks to execute.  Bytecodes are executed by the Java Virtual Machine (JVM) ◦ a part of the JDK and the foundation of the Java platform.  Virtual machine (VM)—a software application that simulates a computer ◦ Hides the underlying operating system and hardware from the programs that interact with it.
  • 37.  Bytecodes are platform independent ◦ They do not depend on a particular hardware platform.  Bytecodes are portable ◦ The same bytecodes can execute on any platform containing a JVM that understands the version of Java in which the bytecodes were compiled.  The JVM is invoked by the java command. For example, to execute a Java application called Welcome, you’d type the command  java Welcome
  • 38.  Phase 3: Loading a Program into Memory ◦ The JVM places the program in memory to execute it—this is known as loading. ◦ Class loader takes the .class files containing the program’s bytecodes and transfers them to primary memory. ◦ Also loads any of the .class files provided by Java that your program uses.
  • 39.
  • 40.  Phase 4: Bytecode Verification ◦ As the classes are loaded, the bytecode verifier examines their bytecodes ◦ Ensures that they’re valid and do not violate Java’s security restrictions.  Java enforces strong security to make sure that Java programs arriving over the network do not damage your files or your system (as computer viruses and worms might).
  • 41.
  • 42.  Phase 5: Execution ◦ The JVM executes the program’s bytecodes. ◦ JVMs typically execute bytecodes using a combination of interpretation and so-called just-in-time (JIT) compilation. ◦ A just-in-time (JIT) compiler—known as the Java HotSpot compiler—translates the bytecodes into the underlying computer’s machine language.
  • 43. ◦ When the JVM encounters these compiled parts again, the faster machine-language code executes.  Java programs go through two compilation phases 1- Source code is translated into bytecodes 2- during execution, the bytecodes are translated into machine language for the actual computer on which the program executes.
  • 44.  In the Java programming language: ◦ A program is made up of one or more classes ◦ A class contains one or more methods ◦ A method contains program statements  A Java application always contains a method called main 1- 44
  • 45. 1- 45 public class MyProgram { } // comments about the class class header class body Comments can be placed almost anywhere
  • 46. 1- 46 public class MyProgram { } // comments about the class public static void main (String[] args) { } // comments about the method method header method body
  • 47.  Comments in a program are called inline documentation  They should be included to explain the purpose of the program and describe processing steps  They do not affect how a program works  Java comments can take three forms: 1- 47 // this comment runs to the end of the line /* this comment runs to the terminating symbol, even across line breaks */ /** this is a javadoc comment */
  • 48.  Identifiers are the words a programmer uses in a program  An identifier can be made up of letters, digits, the underscore character ( _ ), and the dollar sign  Identifiers cannot begin with a digit  Java is case sensitive - Total, total, and TOTAL are different identifiers  By convention, programmers use different case styles for different types of identifiers, such as ◦ title case for class names - MyClass ◦ upper case for constants - MAXIMUM 1- 48
  • 49.  Sometimes we choose identifiers ourselves when writing a program (such as MyClass)  Sometimes we are using another programmer's code, so we use the identifiers that he or she chose (such as println)  Often we use special identifiers called reserved words that already have a predefined meaning in the language  A reserved word cannot be used in any other way 1- 49
  • 50.  The Java reserved words: 1- 50 abstract boolean break byte case catch char class const continue default do double else enum extends false final finally float for goto if implements import instanceof int interface long native new null package private protected public return short static strictfp super switch synchronized this throw throws transient true try void volatile while
  • 51.  Spaces, blank lines, and tabs are called white space  White space is used to separate words and symbols in a program  Extra white space is ignored  A valid Java program can be formatted many ways  Programs should be formatted to enhance readability, using consistent indentation 1- 51
  • 52.  The syntax rules of a language define how we can put together symbols, reserved words, and identifiers to make a valid program  The semantics of a program statement define what that statement means (its purpose or role in a program)  A program that is syntactically correct is not necessarily logically (semantically) correct  A program will always do what we tell it to do, not what we meant to tell it to do 1- 52
  • 53.  A program can have three types of errors  The compiler will find syntax errors and other basic problems (compile-time errors) ◦ If compile-time errors exist, an executable version of the program is not created  A problem can occur during program execution, such as trying to divide by zero, which causes a program to terminate abnormally (run-time errors)  A program may run, but produce incorrect results, perhaps using an incorrect formula (logical errors) 1- 53
  • 54. import java.util.Scanner; /** * * @author jadoon */ public class HelloWorldApp { public static void main(String[] args) { Scanner reader = new Scanner(System.in); //is used to take input // TODO code application logic here System.out.println("Welcome to my first java program"); System.out.println("Please Enter In Your First Name: "); String firstName = reader.nextLine(); 1- 54
  • 55. System.out.println("Please Enter In The Year You Were Born: "); String bornYear = reader.nextLine(); System.out.println("Please Enter In The Current Year: "); String thisYear = reader.nextLine(); int bYear = Integer.parseInt(bornYear);//convert data type int tYear = Integer.parseInt(thisYear); int yold=tYear-bYear; System.out.println("Hello "+ firstName +" your age is " + yold); }//main method }//class 1- 55
  • 56.  public class HelloWorld {  public static void main(String[] args) {  // Display the string.  System.out.println("Hello World!");  System.out.println("My first java program");  }  }  Save HelloWorld.java  Open cmd  SET PATH=%PATH%;C:JDK1.2BIN  Javac HelloWorld.java  Java HelloWorld