SlideShare a Scribd company logo
School of Computing
COMP 155: Object Oriented Programming
Dr Ziaul Hossain
Introduction to JAVA
Date School of Computing Slide 2
Recap of COMP 150
• Try to remember the commands and practice
them on the next sets of questions
• Topics to cover:
• Simple Program (printing name)
• Conditional/Selection Statement
• Iterative Statements (Loop)
• Functions
• Array
Date School of Computing Slide 3
Basic Program
• Print your name and university name
• Print the addition of 3 and 4
• Write a program to find the final value for the
expression 8 + 2 x 3 - 5
Date School of Computing Slide 4
Some more Basic Programs . . .
Write a program that takes 2 integer inputs from
user and prints the product of those integers
Write a program that will take the radius of a
circle as floating point input and will print the
area of that circle.
4
Date School of Computing Slide 5
Programs with conditional statements
Write a program that will take two integer inputs
and find the larger no among them.
Write a program that will take an integer from
keyboard and will determine whether the
number is even or odd.
5
Date School of Computing Slide 6
Programs with loops
• Write a program that will print your name 10 times.
• Write a program that will find the sum of integers between 11 and 20.
• Write a program that will take 10 integer inputs from keyboard and print
the sum, average and maximum number.
• Write a program to find whether a given integer input is prime or not.
6
Date School of Computing Slide 7
Functions
Write a program that contains a function named findArea() which takes the radius of a
circle and prints its area.
Write a program that contains the a function checkPrime() which takes an integer as
parameter and prints whether the parameter is prime or not
Write a program that finds the total number of prime numbers within a given range;
you have to use a function to check primes. The program will take the range
boundaries from user.
7
Date School of Computing Slide 8
Arrays
Write a program that declares an array of 5 floating point
numbers and takes those floating point numbers from keyboard
input. Then it will print the square of each elements.
Write a program to declare a 3 by 3 matrix. Take input for all the
elements of that matrix and print the matrix. Finally find the sum
of all elements.
8
Date School of Computing Slide 9
Recap...
9
● Finish all programs yourself
● Revise the previous lectures and practice the logic of
programming
Date School of Computing Slide 10
Short History of Java
• Java was originally developed by Sun Microsystems
starting in 1991
– James Gosling
– Patrick Naughton
– Chris Warth
– Ed Frank
– Mike Sheridan
• This language was initially called Oak
• Renamed Java in 1995 after the coffee from Indonesia
Date School of Computing Slide 11
JAVA …
• A simple, object oriented, distributed,
‐
interpreted, robust, secure, architecture neutral,
portable, high performance, multithreaded, and
‐
dynamic language ‐‐ Sun Microsystems
• Object Oriented
‐
– No free functions
– All code belong to some class
– Classes arranged in a hierarchy or package structure
Date School of Computing Slide 12
JAVA …
• Distributed
– Fully supports IPv4, with structures to support IPv6
– Includes support for Applets: small programs
embedded in HTML documents
• Interpreted
– The program are compiled into Java Virtual Machine
(JVM) code called bytecode
– Each bytecode instruction is translated into machine
code at the time of execution
Date School of Computing Slide 13
JAVA . . .
• Robust
– Java is simple : no pointers/stack concerns
– Exception handling
• try/catch/finally series allows for simplified error recovery
– Strongly typed language
• many errors caught during compilation
• Architecture Neutral
– Runs in both Windows and Linux based machines
– Runs in all configurations
Date School of Computing Slide 14
Java: Platform Neutral
Date School of Computing Slide 15
Installing Java
• First, download and install Java Development
Kit (JDK)
• Second, download and install Eclipse for Java
IDE
Date School of Computing Slide 16
Creating the Environment
• Create a Project
– New -> Project -> Java Project
– Give a name say JavaWorks
• Create a Package
– Right click on the Project and select
New -> Package
- Give a name for example Week01 (No spaces in package name)
- Create a class
- Right click on the package and select new -> class
- Give a name, say Example
Date School of Computing Slide 17
First Program
Date School of Computing Slide 18
Second Program
Date School of Computing Slide 19
If Example
Date School of Computing Slide 20
For Example
Date School of Computing Slide 21
Primitive Data Types
• int
• float
• double
• char
• boolean
Date School of Computing Slide 22
Integers
byte b, c; short s;
short t;
int a;
int totalNum; long lightspeed;
Date School of Computing Slide 23
Floating Point Types
Date School of Computing Slide 24
Character Type
16 bit sized
char letter;
Date School of Computing Slide 25
Example in Character
Date School of Computing Slide 26
Boolean Example
Date School of Computing Slide 27
Variable Declaration
Date School of Computing Slide 28
Scope & Lifetime of a Variable
Date School of Computing Slide 29
Scope & Lifetime of a variable
Date School of Computing Slide 30
Practicing
• Try the programs mentioned in the slides
previously now in Java
• Complete the “Week_01_Lab1” file tasks
Date School of Computing Slide 31
• End of Week 1

More Related Content

Similar to intro to java object oreinted programming school of computing (20)

PPT
Programming with Java - Essentials to program
leaderHilali1
 
PPTX
Java basics
Hoang Nguyen
 
DOC
java handout.doc
SOMOSCO1
 
PDF
Computational Problem Solving 004 (1).pptx (1).pdf
SadhikaPolamarasetti1
 
PPTX
JAVA CLASS PPT FOR ENGINEERING STUDENTS BBBBBBBBBBBBBBBBBBB
NagarathnaRajur2
 
PPTX
Modern_2.pptx for java
MayaTofik
 
PPTX
Learning core java
Abhay Bharti
 
PPTX
Unit No. 1 Introduction to Java.pptx
DrYogeshDeshmukh1
 
PPT
CSL101_Ch1.ppt
kavitamittal18
 
PPT
CSL101_Ch1.ppt
DrPriyaChittibabu
 
PPTX
CSL101_Ch1.pptx
shivanka2
 
PPTX
CSL101_Ch1.pptx
Ashwani Kumar
 
PPT
Unit I Advanced Java Programming Course
parveen837153
 
PPT
java introduction
Kunal Sunesara
 
PPT
2.ppt
ssuser99ca78
 
PPT
Topic2JavaBasics.ppt
MENACE4
 
PPT
hallleuah_java.ppt
Rahul201258
 
PPT
Lecture_1_Java_Programming_2023tttttttttt.ppt
ssuser68353e
 
PPTX
Introduction to java Programming Language
rubyjeyamani1
 
PPTX
OOP Introduction Part 2 In Java Language.pptx
habibansar098
 
Programming with Java - Essentials to program
leaderHilali1
 
Java basics
Hoang Nguyen
 
java handout.doc
SOMOSCO1
 
Computational Problem Solving 004 (1).pptx (1).pdf
SadhikaPolamarasetti1
 
JAVA CLASS PPT FOR ENGINEERING STUDENTS BBBBBBBBBBBBBBBBBBB
NagarathnaRajur2
 
Modern_2.pptx for java
MayaTofik
 
Learning core java
Abhay Bharti
 
Unit No. 1 Introduction to Java.pptx
DrYogeshDeshmukh1
 
CSL101_Ch1.ppt
kavitamittal18
 
CSL101_Ch1.ppt
DrPriyaChittibabu
 
CSL101_Ch1.pptx
shivanka2
 
CSL101_Ch1.pptx
Ashwani Kumar
 
Unit I Advanced Java Programming Course
parveen837153
 
java introduction
Kunal Sunesara
 
Topic2JavaBasics.ppt
MENACE4
 
hallleuah_java.ppt
Rahul201258
 
Lecture_1_Java_Programming_2023tttttttttt.ppt
ssuser68353e
 
Introduction to java Programming Language
rubyjeyamani1
 
OOP Introduction Part 2 In Java Language.pptx
habibansar098
 

Recently uploaded (20)

PPTX
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
PDF
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
PDF
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
PPTX
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
PDF
The dynastic history of the Chahmana.pdf
PrachiSontakke5
 
PDF
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
PPTX
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
PPTX
2025 Winter SWAYAM NPTEL & A Student.pptx
Utsav Yagnik
 
PPTX
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
PDF
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
PDF
The-Ever-Evolving-World-of-Science (1).pdf/7TH CLASS CURIOSITY /1ST CHAPTER/B...
Sandeep Swamy
 
PDF
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
PDF
community health nursing question paper 2.pdf
Prince kumar
 
PPTX
How to Handle Salesperson Commision in Odoo 18 Sales
Celine George
 
PPTX
SPINA BIFIDA: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
PPTX
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
PDF
The Different Types of Non-Experimental Research
Thelma Villaflores
 
PPTX
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
PDF
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
PDF
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
The dynastic history of the Chahmana.pdf
PrachiSontakke5
 
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
2025 Winter SWAYAM NPTEL & A Student.pptx
Utsav Yagnik
 
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
The-Ever-Evolving-World-of-Science (1).pdf/7TH CLASS CURIOSITY /1ST CHAPTER/B...
Sandeep Swamy
 
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
community health nursing question paper 2.pdf
Prince kumar
 
How to Handle Salesperson Commision in Odoo 18 Sales
Celine George
 
SPINA BIFIDA: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
The Different Types of Non-Experimental Research
Thelma Villaflores
 
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
Ad

intro to java object oreinted programming school of computing

  • 1. School of Computing COMP 155: Object Oriented Programming Dr Ziaul Hossain Introduction to JAVA
  • 2. Date School of Computing Slide 2 Recap of COMP 150 • Try to remember the commands and practice them on the next sets of questions • Topics to cover: • Simple Program (printing name) • Conditional/Selection Statement • Iterative Statements (Loop) • Functions • Array
  • 3. Date School of Computing Slide 3 Basic Program • Print your name and university name • Print the addition of 3 and 4 • Write a program to find the final value for the expression 8 + 2 x 3 - 5
  • 4. Date School of Computing Slide 4 Some more Basic Programs . . . Write a program that takes 2 integer inputs from user and prints the product of those integers Write a program that will take the radius of a circle as floating point input and will print the area of that circle. 4
  • 5. Date School of Computing Slide 5 Programs with conditional statements Write a program that will take two integer inputs and find the larger no among them. Write a program that will take an integer from keyboard and will determine whether the number is even or odd. 5
  • 6. Date School of Computing Slide 6 Programs with loops • Write a program that will print your name 10 times. • Write a program that will find the sum of integers between 11 and 20. • Write a program that will take 10 integer inputs from keyboard and print the sum, average and maximum number. • Write a program to find whether a given integer input is prime or not. 6
  • 7. Date School of Computing Slide 7 Functions Write a program that contains a function named findArea() which takes the radius of a circle and prints its area. Write a program that contains the a function checkPrime() which takes an integer as parameter and prints whether the parameter is prime or not Write a program that finds the total number of prime numbers within a given range; you have to use a function to check primes. The program will take the range boundaries from user. 7
  • 8. Date School of Computing Slide 8 Arrays Write a program that declares an array of 5 floating point numbers and takes those floating point numbers from keyboard input. Then it will print the square of each elements. Write a program to declare a 3 by 3 matrix. Take input for all the elements of that matrix and print the matrix. Finally find the sum of all elements. 8
  • 9. Date School of Computing Slide 9 Recap... 9 ● Finish all programs yourself ● Revise the previous lectures and practice the logic of programming
  • 10. Date School of Computing Slide 10 Short History of Java • Java was originally developed by Sun Microsystems starting in 1991 – James Gosling – Patrick Naughton – Chris Warth – Ed Frank – Mike Sheridan • This language was initially called Oak • Renamed Java in 1995 after the coffee from Indonesia
  • 11. Date School of Computing Slide 11 JAVA … • A simple, object oriented, distributed, ‐ interpreted, robust, secure, architecture neutral, portable, high performance, multithreaded, and ‐ dynamic language ‐‐ Sun Microsystems • Object Oriented ‐ – No free functions – All code belong to some class – Classes arranged in a hierarchy or package structure
  • 12. Date School of Computing Slide 12 JAVA … • Distributed – Fully supports IPv4, with structures to support IPv6 – Includes support for Applets: small programs embedded in HTML documents • Interpreted – The program are compiled into Java Virtual Machine (JVM) code called bytecode – Each bytecode instruction is translated into machine code at the time of execution
  • 13. Date School of Computing Slide 13 JAVA . . . • Robust – Java is simple : no pointers/stack concerns – Exception handling • try/catch/finally series allows for simplified error recovery – Strongly typed language • many errors caught during compilation • Architecture Neutral – Runs in both Windows and Linux based machines – Runs in all configurations
  • 14. Date School of Computing Slide 14 Java: Platform Neutral
  • 15. Date School of Computing Slide 15 Installing Java • First, download and install Java Development Kit (JDK) • Second, download and install Eclipse for Java IDE
  • 16. Date School of Computing Slide 16 Creating the Environment • Create a Project – New -> Project -> Java Project – Give a name say JavaWorks • Create a Package – Right click on the Project and select New -> Package - Give a name for example Week01 (No spaces in package name) - Create a class - Right click on the package and select new -> class - Give a name, say Example
  • 17. Date School of Computing Slide 17 First Program
  • 18. Date School of Computing Slide 18 Second Program
  • 19. Date School of Computing Slide 19 If Example
  • 20. Date School of Computing Slide 20 For Example
  • 21. Date School of Computing Slide 21 Primitive Data Types • int • float • double • char • boolean
  • 22. Date School of Computing Slide 22 Integers byte b, c; short s; short t; int a; int totalNum; long lightspeed;
  • 23. Date School of Computing Slide 23 Floating Point Types
  • 24. Date School of Computing Slide 24 Character Type 16 bit sized char letter;
  • 25. Date School of Computing Slide 25 Example in Character
  • 26. Date School of Computing Slide 26 Boolean Example
  • 27. Date School of Computing Slide 27 Variable Declaration
  • 28. Date School of Computing Slide 28 Scope & Lifetime of a Variable
  • 29. Date School of Computing Slide 29 Scope & Lifetime of a variable
  • 30. Date School of Computing Slide 30 Practicing • Try the programs mentioned in the slides previously now in Java • Complete the “Week_01_Lab1” file tasks
  • 31. Date School of Computing Slide 31 • End of Week 1