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

intro to java object oreinted programming school of computing

  • 1.
    School of Computing COMP155: Object Oriented Programming Dr Ziaul Hossain Introduction to JAVA
  • 2.
    Date School ofComputing 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 ofComputing 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 ofComputing 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 ofComputing 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 ofComputing 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 ofComputing 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 ofComputing 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 ofComputing Slide 9 Recap... 9 ● Finish all programs yourself ● Revise the previous lectures and practice the logic of programming
  • 10.
    Date School ofComputing 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 ofComputing 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 ofComputing 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 ofComputing 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 ofComputing Slide 14 Java: Platform Neutral
  • 15.
    Date School ofComputing Slide 15 Installing Java • First, download and install Java Development Kit (JDK) • Second, download and install Eclipse for Java IDE
  • 16.
    Date School ofComputing 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 ofComputing Slide 17 First Program
  • 18.
    Date School ofComputing Slide 18 Second Program
  • 19.
    Date School ofComputing Slide 19 If Example
  • 20.
    Date School ofComputing Slide 20 For Example
  • 21.
    Date School ofComputing Slide 21 Primitive Data Types • int • float • double • char • boolean
  • 22.
    Date School ofComputing Slide 22 Integers byte b, c; short s; short t; int a; int totalNum; long lightspeed;
  • 23.
    Date School ofComputing Slide 23 Floating Point Types
  • 24.
    Date School ofComputing Slide 24 Character Type 16 bit sized char letter;
  • 25.
    Date School ofComputing Slide 25 Example in Character
  • 26.
    Date School ofComputing Slide 26 Boolean Example
  • 27.
    Date School ofComputing Slide 27 Variable Declaration
  • 28.
    Date School ofComputing Slide 28 Scope & Lifetime of a Variable
  • 29.
    Date School ofComputing Slide 29 Scope & Lifetime of a variable
  • 30.
    Date School ofComputing Slide 30 Practicing • Try the programs mentioned in the slides previously now in Java • Complete the “Week_01_Lab1” file tasks
  • 31.
    Date School ofComputing Slide 31 • End of Week 1