Introduction To Computers and Java
Introduction To Computers and Java
Introduction
■ Computer Basics
■ Programming Basics
■ Graphics Supplement
■ Composed of …
■ Input devices (keyboards, mouse, camera, mic,…)
■ Output devices (monitor, printer, speaker, …)
■ Storages (HDD, SSD, flash memory, CD/DVD, …)
■ CPU, main memory, controller, …
■ Execution of program
■ Program is executed by computer (+ OS)
■ Program takes input and produces output
■ Link
■ Integrating objects and library modules required to execute
Notice! a program can be distributed in multiple source files.
Source 1 Object 1
… Linki Executable
Source n Object n ng
Library
Modules
(printf, scanf,…)
JVM
OS
H/W
■ Applet
■ Sent to another location on the Internet and run there.
□ H/W + OS + VM + Web browser
■ Computer Basics
■ Programming Basics
■ Graphics Supplement
import java.util.Scanner;
public class FirstProgram
{
public static void main (String [] args)
{
System.out.println ("Hello out there.");
System.out.println ("I will add two numbers for you.");
System.out.println ("Enter two whole numbers on a line:");
int n1, n2;
Scanner keyboard = new Scanner (System.in);
n1 = keyboard.nextInt ();
n2 = keyboard.nextInt ();
System.out.println ("The sum of those two numbers is");
System.out.println (n1 + n2);
}
}
■ Result
■ import java.util.Scanner;
■ Tells the compiler that this program uses the class Scanner.
■ class FirstProgram
public class FirstProgram
{
...
}
■ System.out.println()
■ Displays what is shown in parentheses
■ System.out is an object used to send output to the screen
■ println is the method that performs this action for the object
System.out.
■ n1 = keyboard.nextInt();
■ n2 = keyboard.nextInt();
■ Reads integer numbers from the keyboard
■ Computer Basics
■ Programming Basics
■ Graphics Supplement
Description of
class Scanner
Package names
Class names