Intro to Computers _amp; Java

Document Sample
Intro to Computers _amp; Java Powered By Docstoc
					 The University of Akron
    Summit College

            2440: 160
        Java Programming
Introduction to Computers & Java
   Professor: Enoch E. Damson
Parts of an Information System

   Hardware
   Software
   Procedures
   Data
   People

                 Introduction to Computers & Java   2

   Physical components of a computer
   Consists of:
       Input devices
       Processor or Central Processing Unit (CPU)
       Main memory
       Secondary storage devices
       Output devices

                    Introduction to Computers & Java   3
                  Input Devices

   Collects data for the computer
       Common devices include:
         Keyboard
         Mouse

         Scanner

         Digital camera

                     Introduction to Computers & Java   4
    Central Processing Unit (CPU)
   Fetches instructions, follow the instructions, and
    produce some resulting data
   Measured in terms of its speed in hertz (MHz,
   Consists of two parts:
       Control Unit – coordinates all of the computer’s
       Arithmetic & Logic Unit (ALU) – performs
        mathematical operations

                      Introduction to Computers & Java     5
                  Main Memory
   Commonly known as the random-access memory
   Measured in terms of its size in bytes (KB, MB, GB)
   RAM is usually a volatile type of memory for temporary
   Divided into sections (bytes) that hold equal amount of
   Each byte is made up of 8 binary digits (bits) that use
    0 and 1 to represents on and off “switches”
   Each byte is a assigned a unique number known as an
    address, which are ordered from lowest to highest

                    Introduction to Computers & Java      6
        Secondary Storage Devices
   Type of memory that hold data for long periods
    of time
   Measured in terms of their size in bytes (KB,
    MB, GB)
   Common types of secondary storage devices
       Hard disks
       Jump drives
       Zip disks
       Floppy disks

                       Introduction to Computers & Java   7
                Output Devices

   Formats and presents processed data
    (information) to the outside world
       Common devices include:
         Monitors
         Printers

                     Introduction to Computers & Java   8
   Programs that run on a computer
   Has two general categories:
       System software – enables application software to
        interact with the computer hardware
            E.g. operating systems, utilities, device drivers, and
             programming languages
       Application software – programs that solve specific
        problems or perform general operations useful to the
            E.g. word processors, spreadsheets, etc

                          Introduction to Computers & Java            9

   Rules or guidelines for people to follow
    when using software, hardware, and data
       Guidelines are documented in manuals

                   Introduction to Computers & Java   10

   Raw facts entered into the computer
    system for processing
   Processed to produce information

                Introduction to Computers & Java   11

   Making people more productive is what
    computers are all about
       Users include:
          Analysts
          Designers

          Developers

          End-users

                        Introduction to Computers & Java   12
                Computer Program
   Set of instructions that enables the computer to
    solve a problem or perform a task
   The instructions are called algorithms
       A computer’s CPU can only process algorithms written
        in machine language – consisting of binary
        numbers (0s and 1s)
            E.g. 1011010000000101
       Each different type of CPU has its own machine
       Algorithms written with programming languages
        are much easier to understand

                       Introduction to Computers & Java   13
          Computer Programming

   An art and a science of creating
    instructions to solve problems and perform
       An art because every aspect of the program
        should be carefully designed
       A science because of the need to indulge in
        the tasks of analyzing, experimenting,
        correcting, and redesigning

                    Introduction to Computers & Java   14
           Program Development
            (Programming) Cycle
   The process of writing instructions (programs)
    for a computer to solve a problem
   Programming steps include:
    1.   Creating program specifications
    2.   Designing the application
    3.   Writing source code
    4.   Compiling/Interpreting programs
    5.   Executing (running) program

                   Introduction to Computers & Java   15
       Program Development
       (Programming) Cycle…
   Creating program specifications –
    the requirements the application must

               Introduction to Computers & Java   16
             Program Development
             (Programming) Cycle…
   Designing the application – create file
    formats, screen layouts, and algorithms
       Algorithm – a sequence of procedures,
        programming code, or commands that are used as
        part of a program or result in a program
       Tools used in designing the sequential and logical
        structure of a program include:
            Flowchart – uses symbols for program design
            Pseudocode – uses natural English for program design

                         Introduction to Computers & Java           17
             Program Development
             (Programming) Cycle…
   Writing source code – the code must be
    written, tested and debugged
       Source code (file) – the file with the actual code
        which is written with a programming language of
        choice in a text editor
       Debugging – the process of going through program
        code to locate and fix errors such as:
            Syntax errors – grammatical mistakes in program language
            Logical errors – logical mistakes in a program

                         Introduction to Computers & Java          18
         Program Development
         (Programming) Cycle…
   Compiling/Interpreting programs – the
    source code is translated in its entirety at one
    time (compiled) or a single line at a time
    (interpreted) from high-level program
    instructions into machine language, and
    executed if no errors are found (run)

                   Introduction to Computers & Java    19
             Program Development
             (Programming) Cycle…
   Compiling/Interpreting programs
       Compiler – a system software program that translates an entire
        high-level program (source code) at one time into machine
        language (object code grouped together in files called library
        files) that the computer can interpret and execute
            It gives no feedback until the entire program has been compiled
       Interpreter – a system software program that translates a
        single line at a time in a program
            An immediate feedback is given if the code contains an error

                              Introduction to Computers & Java                 20
           Program Development
           (Programming) Cycle…
   Executing (running) program – the compiled
    or interpreted code is executed if no errors are
       Executable code – a linker or link editor resolves
        object code references to other programs by creating
        an executable code.

                      Introduction to Computers & Java     21
        Programming Languages
   Invented to ease the task of programming with the use
    of words instead of binary numbers
   Programming languages have evolved in generations
    and are improved over the years
   The generations of programming languages include:
      Low-level languages

      High-level languages

                    Introduction to Computers & Java        22
      Programming Languages…
   Low-level languages – include:
          Machine language (1st Generation) – instructions are
           coded as a series of 0s and 1s and are unique to a particular
          Assembler language (2nd Generation) – instructions are
           coded using some recognized symbols called mnemonics
           (memory aids) and are also unique to a particular computer
                Example: MUL is used to represent a multiply instruction. An
                 assembler translates the mnemonics into 0s and 1s

                           Introduction to Computers & Java                     23
      Programming Languages…
   High-level languages – programs instructions are
    often written in English-like expressions in languages
    such as:
           3rd Generation languages – instructions are coded at the
            programmer’s convenience but cannot be executed in their original
            form (source code)
                 A compiler or interpreter is needed to translate the language syntax into low-
                  level machine language to be executed.
                 Examples include: FORTRAN (FORmula TRANslator)-1955, Pascal-
                  1968, C-1972, C++-1980s, Java-1990
           4th Generation languages – Has a graphical user interface (GUI)
            that combines a code editor, compiler, debugger, linker, and
            executor into a single Inter-Development Environment (IDE).
                 Examples include: Visual Basic, Delphi, PowerBuilder, Visual.NET, etc

                               Introduction to Computers & Java                                24
    Programming Language Elements

   Every programming language uses the following
    general program elements:
       Syntax – rules of a programming language
       Comments – non executing programming language statements
       Constant data – raw data used in programming such as
        numbers, strings, etc
       Data output – displaying data on a screen or sending data to a
       Data input – receiving data from the keyboard or file
       Variables – named memory locations for data storage

                        Introduction to Computers & Java            25
Programming Language Elements…

   Other programming language elements include:
       Data types – specifies the types of data native to the
        programming language
       Keywords – words with a special meaning in the programming
       Operators – symbols or words that perform operations on
       Selections (Condition testing)
       Repetitions (Looping structures)
       Arrays
       Files/Databases

                       Introduction to Computers & Java          26
         Methods of Programming
   Two primary methods of programming are:
       Procedural – creates programs made up of variables
        and procedures
            Variable – named storage location in a computer’s memory
            Procedure – set of programming language statements that
             perform a specific task
       Object-oriented – creates programs made up of
        objects (instances of a class)
            Object – a software entity with attributes (fields) and
             procedures (methods)
            Class – specifies the attributes and methods of objects

                          Introduction to Computers & Java             27
        Principles of Object-Oriented
            Programming (OOP)
   Encapsulation – grouping data (fields, methods, etc)
    into a single object
   Information Hiding (Abstraction) – hiding an
    object’s data from other objects
       The object’s methods are used directly access its data
       Typically, the object’s data is hidden but allows its methods to
        be accessed
   Inheritance – deriving classes (subclasses) based on
    other existing classes (superclasses)
   Polymorphism - using the same procedure name or
    operator with different types of arguments
       There are 2 types of polymorphism: overloading and

                          Introduction to Computers & Java                 28
                    History of Java
   In 1991 the Green Team was formed at Sun
    Microsystems to develop a hand-held device (named
    *7) to control home entertainment devices
   James Gosling (the project leader) created the Oak
    language for the project
       The Oak language translated programs into byte code for
        different processors
       Oak (renamed Java) was later used to develop a Web browser
        named HotJava – which was able to download and run small
        Java programs known as applets
       HotJava was demonstrated in 1995 which made Java popular
       Netscape later incorporated Java into its Navigator browser

                        Introduction to Computers & Java              29
         Types of Java Programs

   Two types of Java programs are:
       Application – stand-alone programs that run
        on a computer
       Applets – programs that are transmitted over
        the Internet from a Web server and executed
        on a Web browser

                   Introduction to Computers & Java   30
               Properties of Java
   Object-Oriented – uses objects to perform specific tasks
   Portable – enables programs to behave identical on different
    platforms like: Mac, Windows, Solaris (UNIX)
   Compiles into byte code instead of machine language – the
    byte code is read by the Java Virtual Machine (JVM) – which
    interprets the code for different processors
   “Architecture-neutral” – the byte code that comes out of the
    compiler will run on any processor and operating system
   Can be embedded on Web pages – applets are downloaded and
    ran from Web pages
   Secured – Web browsers run applets in a secure environment
    within a computer’s memory

                      Introduction to Computers & Java         31
    The Java Compiler & Java Virtual
            Machine (JVM)
   Text editors are used to write Java programming
    statements (source code) and saved in a source file
    (.java extension) and translated (compiled) by a
   Compiler – program that translates source code into an
    executable form
       Java compilers translate source code into a file (.class
        extension) containing byte code
       The byte code instructions (not machine language) are executed
        by the Java Virtual Machine (JVM)
       The JVM simulates a computer whose machine language is the
        Java byte code

                        Introduction to Computers & Java            32
Java Program Development Process
  1.   The programmer uses a text edit to
       create a Java source code file (.java             Text
       extension)                                       Editor


  2.   The programmer runs the compiler to                Java
       translate the source code file into a byte       Compiler
       code file (.class extension)

                                                       Byte Code

  3.   The Java Virtual Machine (JVM) reads           Java Virtual
       and executes each byte code instruction          Machine

                            Introduction to Computers & Java         33
                    Java Editions
   The software used to create Java programs is
    known as the Java Development Kit (JDK) or
    the Software Development Kit (SDK)
   Some Java editions include:
       Java Standard Edition (Java SE) – used for
        writing Java applications and applets
       Java Enterprise Edition (Java EE) – used to
        create business client/server and Web server-based
       Java Micro Edition (Java ME) – runtime-
        environment for consumer products like cell phones,
        pagers, etc

                      Introduction to Computers & Java        34
        Java Integrated Development
             Environments (IDE)
   Consists of text editor, compiler, debugger, and
    other utilities integrated into a package
   Current popular Java IDEs include:
       Eclipse (
       NetBeans (
       IntelliJ IDEA (
       jGRASP (

                      Introduction to Computers & Java   35
          Compiling & Running Java
   javac is used to compile Java programs
       E.g. javac
   A .class file is created if no are found
   java is used to run Java programs
       E.g. java Hello
   Two types of errors (bugs) are:
       Syntax errors – mistakes that violate the rules of
        the programming language
       Logical errors – mistakes that cause programs to
        produce erroneous results

                      Introduction to Computers & Java       36

Shared By: