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
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