Lecture 1: Introduction to Computers and Java - PowerPoint PPT Presentation

1 / 30
About This Presentation
Title:

Lecture 1: Introduction to Computers and Java

Description:

The processor processes a program's instructions. It can process only ... Java is an object oriented high level language, invented by James Gosling in 90s. ... – PowerPoint PPT presentation

Number of Views:76
Avg rating:3.0/5.0
Slides: 31
Provided by: rober855
Category:

less

Transcript and Presenter's Notes

Title: Lecture 1: Introduction to Computers and Java


1
Lecture 1 Introduction to Computers and Java
  • Dr. Hairong Zhao
  • hairong_at_calumet.purdue.edu
  • Purdue University Calumet

2
Outline
  • Computer Basics
  • Hardware
  • Software
  • A Sip of Java

3
Outline
  • Computer Basics
  • Hardware
  • Software
  • A Sip of Java

4
Computer Basics - Hardware
Computer Organization
5
Central Processing Unit (CPU)
  • The processor processes a programs instructions.
  • It can process only very simple instructions.
  • The power of computing comes from speed and
    program intricacy.

6
Memory
  • Memory holds
  • programs
  • data for the computer to process
  • the results of intermediate processing.
  • Two kinds of memory
  • main memory
  • auxiliary memory

7
Main memory
  • used to store
  • the current program
  • the data the program is using
  • the results of intermediate calculations
  • usually measured in megabytes (e.g. 256 megabytes
    of RAM)
  • RAM is short for random access memory
  • a byte is a quantity of memory

8
Bits, Bytes, and Addresses
  • A bit is a digit with a value of either 0 or 1.
  • A byte consists of 8 bits.
  • Each byte in main memory resides at a numbered
    location called its address.
  • Data of all kinds (numbers, letters, strings of
    characters, audio, video, even programs) are
    encoded and stored using 1s and 0s.
  • When more than a single byte is needed, several
    adjacent bytes are used.
  • The address of the first byte is the address of
    the unit of bytes.

9
Main Memory Addresses
10
Auxiliary Memory
  • also called secondary memory
  • disk drives, diskettes, CDs, etc.
  • more or less permanent (nonvolatile)

11
Auxiliary Memory, cont.
  • Large groups of bytes in auxiliary memory are
    organized into files.
  • Files are organized into groups called
    directories or folders.
  • Java programs are stored in files.
  • Programs files are copied from auxiliary memory
    to main memory in order to be run.

12
Computer Basics - Software
  • Program
  • Operating System
  • Programming Language Compiler
  • Java Compiler
  • Class Loader

13
Programs
  • A program is a set of instructions for a computer
    to follow.
  • We use programs almost daily (email, word
    processors, video games, bank ATMs, etc.).
  • Following the instructions is called running or
    executing the program.

14
The Operating System
  • The operating system is a supervisory program
    that oversees the operation of the computer.
  • The operating system retrieves and starts program
    for you.
  • Well-known operating systems include DOS,
    Microsoft Windows, Apples Mac OS, Linux, and
    UNIX.

15
Programming Languages
  • Example Java, Pascal, FORTRAN, C, C, BASIC,
    Visual Basic
  • They are relatively easy to write and to
    understand they are all high-level languages
  • Java is an object oriented high level language,
    invented by James Gosling in 90s.
  • a program as a collection of objects that
    interact by means of actions.
  • Actions are called methods.
  • Objects of the same kind have the same type and
    belong to the same class.
  • Objects within a class have a common set of
    methods and the same kinds of data
  • but each object can have its own data values.

16
Compilers
  • Unfortunately, computer hardware does not
    understand high-level languages.
  • Therefore, a high-level language program must be
    translated into a low-level language.
  • A compiler translates a program from a high-level
    language to a low-level language the computer can
    run.
  • You compile a program by running the compiler on
    the high-level-language version of the program
    called the source program.
  • Compilers produce machine- or assembly-language
    programs called object programs.

17
Compilers, cont.
  • Most high-level languages need a different
    compiler for each type of computer and for each
    operating system.
  • Most compilers are very large programs that are
    expensive to produce.

18
Java Compiler
  • The Java compiler does not translate a Java
    program into assembly language or machine
    language for a particular computer.
  • Instead, it translates a Java program into
    byte-code.
  • Byte-code is the machine language for a
    hypothetical computer (or interpreter) called the
    Java Virtual Machine
  • A byte-code program is easy to translate into
    machine language for any particular computer

19
Java Compiler, cont.
  • Byte-code can be used on any computer with a
    byte-code interpreter and without a need to
    recompile.
  • This makes Java suitable for Internet
    applications
  • A program called an interpreter translates each
    byte-code instruction, executing the resulting
    machine-language instructions on the particular
    computer before translating the next byte-code
    instruction.

20
(No Transcript)
21
Outline
  • Computer Basics
  • Hardware
  • Software
  • A Sip of Java

22
A Sip of Java Outline
  • Application and Applets
  • A First Java Application
  • Compiling a Java Program or Class
  • Running a Java Program
  • Testing and debugging

23
Applications and Applets
  • Two kinds of Java programs applications and
    applets
  • Applications
  • regular programs
  • meant to be run on your computer
  • Applets
  • little applications
  • meant to be sent to another location on the
    Internet and run there

24
A First Java Application
  • Task display the following on the screen
  • Hello, everybody!
  • Welcome to CS 123!

25
A First Java Application
  • // Author Hairong Zhao
  • // Purpose display a welcome message in a
    console window
  • // NameHello.java
  • public class Hello
  • // method main() application entry point
  • public static void main(String args)
  • System.out.println(" Hello, everybody!
    ")
  • System.out.println(" Welcome to CS
    123!")

26
Compiling and Running
  • Compile a program using command line
  • javac Hello.java
  • After compiling the byte-code version of the
    program is generated it has the same name as the
    source file, but the ending is changed from
    .java to .class.
  • Run a program using command line
  • java Hello

27
(No Transcript)
28
A First Java Application
  • // Author Hairong Zhao
  • // Purpose display a welcome message in a
    console window
  • // NameHello.java
  • public class Hello
  • // method main() application entry point
  • public static void main(String args)
  • System.out.println(" Hello, everybody!
    ")
  • System.out.println(" Welcome to CS
    123!")

// indicates rest of the line is a
comment Comments are used to document authors,
purpose, and program elements
29
A First Java Application
  • // Authors Hairong Zhao
  • // Purpose display a welcome message in a
    console window
  • // NameHello.java
  • public class Hello
  • // method main() application entry point
  • public static void main(String args)
  • System.out.println(" Hello, everybody!
    ")
  • System.out.println(" Welcome to CS
    123!")

The word "class" indicates a class definition
follows. A class defines an object form. An
object can have methods and attributes
The class has a name " Hello"
30
A First Java Application
  • // Authors Hairong Zhao
  • // Purpose display a welcome message in a
    console window
  • // NameHello.java
  • public class Hello
  • // method main() application entry point
  • public static void main(String args)
  • System.out.println(" Hello, everybody!
    ")
  • System.out.println(" Welcome to CS
    123!")

A method is a named piece of code that performs
some action or implements a behavior
Write a Comment
User Comments (0)
About PowerShow.com