itec133_lec1

Upload: paul-benedict

Post on 23-Feb-2018

220 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/24/2019 ITEC133_Lec1

    1/12

    COLLEGE OF SCIENCE, TECHNOLOGY AND

    APPLIED

    A R T S

    O F T R I N I D A D & T O B A G O

    BUSINESS & INFORMATION TECHNOLOGY DIVISION

    ITEC133

    Programming 1

    Introduction to Programming and Course

    &

    Introduction to Object Oriented Concepts

    Lecture Note 1

    Kadeem Best

  • 7/24/2019 ITEC133_Lec1

    2/12

    2

    Table of Contents

    An Overview of a Computer ...................................................................................................... 1

    What is a computer?............................................................................................................... 1

    Hardware ................................................................................................................................ 1

    Computer Organization ...................................................................................................... 1

    Software ................................................................................................................................. 2

    Operating Systems(O.S) .............................................................................................. 2

    Application Programs .................................................................................................. 3

    Programming Fundamentals ...................................................................................................... 3

    What is programming? ........................................................................................................... 3

    Programming Languages ....................................................................................................... 3

    What is a programming Language? ................................................................................... 3

    Generations of Programming Languages........................................................................... 3

    Types of Programming Languages .................................................................................... 4

    Steps in Developing Programs ............................................................................................... 4

    1.

    Define the problem .................................................................................................. 4

    2. Analyze the problem ................................................................................................ 4

    3.

    Develop the solution (Develop an Algorithm) ........................................................ 5

    4.

    Code the solution(Algorithm) into a Programming Language ................................ 5

    5. Compile and Run the Program ................................................................................ 5

    Algorithm ............................................................................................................................... 5

    Pseudocode ............................................................................................................................ 5

    Trace Tables ........................................................................................................................... 5

    Overview of Java ....................................................................................................................... 6

    What is Java ........................................................................................................................... 6

    History of Java ....................................................................................................................... 6

    Typical Java Development Environment ............................................................................... 6

    An overview of the software development process. .......................................................... 7

    The Java Platform .................................................................................................................. 7

    Java Editions .......................................................................................................................... 8

    The Java Runtime .................................................................................................................. 8

    The Java Development Kit..................................................................................................... 9

    Introduction to Object Oriented Concepts ................................................................................. 9

    Objects ................................................................................................................................... 9

    What Is an Object? ............................................................................................................. 9

    Classes.............................................................................................................................. 10

  • 7/24/2019 ITEC133_Lec1

    3/12

    1

    An Overview of a Computer

    What is a computer?

    A computer is an electronic device capable of performing computations and makinglogical decisions at speeds millions (even billions) of times faster than human beingscan. It has the ability to store, retrieve, and process data. You can use a computer totype documents, send email, and browse the internet. You can also use it to handlespreadsheets, accounting, database management, presentations, games, and more.A computer can be divided into two main parts: hardware and software.

    Hardware

    Hardware is any part of your computer that has a physical structure, such as thecomputer monitor or keyboard.

    Computer Organization

    Regardless of differences in physical appearance, virtually every computer may be

    envisioned as divided into six logical units or sections:

    Input Unit

    This is the receiving section of the computer. It obtains information (data andcomputer programs) from input devices (Input devices accept data in a formthat the computer can utilize) and places this information at the disposal ofother units so that it can be processed. Most information is entered intocomputer through keyboards and mouse devices. However, Information canalso be entered in many ways, including by speaking to your computer, by

    scanning images etc.

    Output Unit

    This is the shipping section of the computer. It takes information that thecomputer has processed and places it on various output devices to make theinformation available for use outside the computer. Most information outputfrom computers today is displayed on screens, printed on paper etc.

    Memory Unit

    This is the rapid-access, relatively low-capacity warehouse section ofcomputer. It retains information that has been entered through the input unit,

  • 7/24/2019 ITEC133_Lec1

    4/12

    2

    so that it will be immediately available for processing when needed. Thememory unit also retains processed information until it can be placed onoutput devices by the output unit. Information in the memory unit is oftencalled either memory or primary memory

    The Arithmetic logic Unit (ALU)

    This is the manufacturing section of the computer. It is responsible forperforming calculations, such as addition, subtraction, multiplication anddivision. It contains the decisions mechanism that allows the computer, forexample, to computer two items from the memory unit to determine whetherthey are equal.

    Central Processing unit (CPU)

    This is the administrative section of the computer. It coordinates andsupervises the operation of the other sections. The CPU tells the input unitwhen information should be read into the memory unit, tells the ALU wheninformation from the memory unit should be used in calculations and tells theoutput unit when to send information from the memory unit to certain outputdevices.

    Secondary Storage Unit

    This is the long-term, high-capacity warehousing section of the computer.Programs or data not actively being used by the other units normally areplaced on secondary storage devices (eg. Your hard drive) until they areagain needed, possibly hours, days, months or even years later. Informationin secondary storage takes much longer to access thanS information inprimary memory. Examples of secondary storage devices include CDs andDVDs, which can hold up to hundreds of millions of characters and billions ofcharacters, respectively

    Software

    Software is any set of instructions that tells the hardware what to do. It is whatguides the hardware and tells it how to accomplish each task. Some examples ofsoftware are web browsers, games, and word processors such as Microsoft Word.Software can be broken down into : Operating Systems, Application Programs.

    Operating Systems(O.S)

    An operating system is the most important software that runs on a computer.It manages the computers memory, processes, and all of its software andhardware. Examples of Operating Systems include: - Windows Vista,Windows XP , Windows 7 and Mac OS.

  • 7/24/2019 ITEC133_Lec1

    5/12

    3

    Application Programs

    Application Programs are designed to perform a specific function directly forthe user or, in some cases, for another application program. Examples of

    application programs include word processors; database programs; Webbrowsers; development tools; drawing, paint, and image editing programs;and communication programs

    Programming Fundamentals

    What is programming?

    Programming is instructing a computer to do something for you with the help of aprogramming language

    Programming Languages

    What is a programming Language?

    An artificial language used to write instructions that can be translated into machinelanguage and then executed by a computer.

    Some programming languages include :- formula translation (FORTRAN), C, C++,PASCAL, BASIC, Java

    Generations of Programming Languages

    First generation languages (abbreviated as 1GL)Represent the very early, primitive computer languages that consisted entirely of 1'sand 0's - the actual language that the computer understands (machine language).

    Second generation languages (2GL)Represent a step up from the first generation languages. Allow for the use ofsymbolic names instead of just numbers. Second generation languages are knownas assembly languages. Code written in an assembly language is converted intomachine language (1GL).

    Third generation languages (3GL)

    With the languages introduced by the third generation of computer programming,words and commands (instead of just symbols and numbers) were being used.

  • 7/24/2019 ITEC133_Lec1

    6/12

    4

    These languages therefore, had syntax that was much easier to understand. Thirdgeneration languages are known as "high level languages" and include C, C++,Java, and Javascript, among others.

    Types of Programming Languages

    Programing Languages can be mainly divided into the follow categories :

    Procedural

    Procedural languages execute a sequence of statements that lead to a result.In essence, a procedural language expresses the procedure to be followed to

    solve a problem. Procedural languages typically use many variables and haveheavy use of loops and other elements of "state", which distinguishes themfrom functional programming languages. Functions in procedural languagesmay modify variables or have other side effects (e.g., printing out information)other than the value that the function returns.

    Object-oriented

    Object-oriented programming views the world as a collection of objects thathave internal data and external means of accessing parts of that data. The

    goal of object-oriented programming is to think about the problem by dividingit into a collection of objects that provide services that can be used to solve aparticular problem.

    Steps in Developing Programs

    1.

    Define the problem

    At this step you are required to examine the problem until you understand itthoroughly.

    2.Analyze the problem

    Involves defining the data we need to provide to the program (input) andinformation we want the program to produce (the output).

  • 7/24/2019 ITEC133_Lec1

    7/12

    5

    3. Develop the solution (Develop an Algorithm)

    Once we have defined and analyzed the problem that is, decided on theoutput and the input then we can go on to develop the solution.

    The most important aspect of developing the solution is developing the logicto solve the problem. This requires creating a set of step-by-step instructionsand/or rules called an algorithm. Each step performs a particular task. We canwrite these steps in plain English.

    4. Code the solution(Algorithm) into a Programming Language

    Once we develop the algorithm, we need to convert it into a computerprogram using a programming language (a language used to developcomputer programs). A programming language is entirely different from the

    language we speak or write. However, it also has a fixed set of words andrules (syntax or grammar) that are used to write instructions for a computer tofollow.

    5. Compile and Run the Program

    6. Document and maintain the program

    Algorithm

    An Algorithm is a set of step by step instructions if followed faithfully should give asolution to a problem.

    Pseudocode

    Pseudocode is a structured way of expressing an algorithm. It uses the structuralconventions of aprogramming language,but is intended for human reading ratherthan machine reading

    Trace Tables

    A trace table is a technique used to test algorithms, in order to make sure that nological errors occur whilst thealgorithm is being processed. The table usually takesthe form of a multi-column, multi-row table; With each column showing a variable,and each row showing each number input into the algorithm and the subsequentvalues of the variables.

    http://en.wikipedia.org/wiki/Programming_languagehttp://en.wikipedia.org/wiki/Algorithmhttp://en.wikipedia.org/wiki/Variable_(programming)http://en.wikipedia.org/wiki/Variable_(programming)http://en.wikipedia.org/wiki/Algorithmhttp://en.wikipedia.org/wiki/Programming_language
  • 7/24/2019 ITEC133_Lec1

    8/12

    6

    Overview of Java

    What is Java

    Java technology is both a programming language and a platform.

    The Java programming language is a high-level language that can be characterizedby all of the following buzzwords:

    Simple Object oriented Distributed Multithreaded Dynamic

    Architecture neutral Portable High performance Robust Secure

    History of Java

    The Java programming language is designed to meet the challenges of applicationdevelopment in the context of heterogeneous, network-wide distributedenvironments. Paramount among these challenges is secure delivery of applicationsthat consume the minimum of system resources, can run on any hardware and

    software platform, and can be extended dynamically.

    The Java programming language originated as part of a research project to developadvanced software for a wide variety of network devices and embedded systems.The goal was to develop a small, reliable, portable, distributed, real-time operatingplatform. When the project started, C++ was the language of choice. But over timethe difficulties encountered with C++ grew to the point where the problems couldbest be addressed by creating an entirely new language platform. Design andarchitecture decisions drew from a variety of languages such as Eiffel, SmallTalk,Objective C, and Cedar/Mesa. The result is a language platform that has provenideal for developing secure, distributed, network-based end-user applications in

    environments ranging from network-embedded devices to the World-Wide Web andthe desktop.

    Typical Java Development Environment

    In the Java programming language, all source code is first written in plain text filesending with the .java extension. Those source files are then compiled into .class filesby the javac compiler. A .class file does not contain code that is native to yourprocessor; it instead contains bytecodesthe machine language of the Java VirtualMachine (Java VM). The java launcher tool then runs your application with aninstance of the Java Virtual Machine.

  • 7/24/2019 ITEC133_Lec1

    9/12

    7

    An overview of the software development process.

    Because the Java VM is available on many different operating systems, thesame .class files are capable of running on Microsoft Windows, the Solaris OperatingSystem (Solaris OS), Linux, or Mac OS. Some virtual machines, such as theJavaHotSpot virtual machine,perform additional steps at runtime to give your applicationa performance boost. This include various tasks such as finding performance

    bottlenecks and recompiling (to native code) frequently used sections of code.

    Through the Java VM, the same application is capable of

    running on multiple platforms.

    The Java Platform

    Aplatformis the hardware or software environment in which a program runs. Somepopular platforms include Microsoft Windows, Linux, Solaris OS, and Mac OS. Mostplatforms can be described as a combination of the operating system and underlyinghardware. The Java platform differs from most other platforms in that it's a software-only platform that runs on top of other hardware-based platforms.

    The Java platform has two components:

    http://java.sun.com/products/hotspot/http://java.sun.com/products/hotspot/http://java.sun.com/products/hotspot/http://java.sun.com/products/hotspot/
  • 7/24/2019 ITEC133_Lec1

    10/12

    8

    The Java Virtual Machine The Java Application Programming Interface(API)

    The API is a large collection of ready-made software components that provide manyuseful capabilities. It is grouped into libraries of related classes and interfaces; these

    libraries are known aspackages.

    The API and Java Virtual Machine insulate the programfrom the underlying hardware.

    As a platform-independent environment, the Java platform can be a bit slower thannative code. However, advances in compiler and virtual machine technologies arebringing performance close to that of native code without threatening portability.

    The terms"Java Virtual Machine" and "JVM" mean a Virtual Machine for the Javaplatform.

    Java Editions

    The Java platform editions contain additional JavaAPIs for creating different types ofapplications: Java comes in 3 main editions:

    Java 2 Standard Edition (J2SE) - Designed to run on desktop andworkstations computers.

    Java 2 Enterprise Edition (J2EE)=- With built-in support for Servlets, JSP, andXML, this edition is aimed at server-based applications.

    Java 2 Micro Edition (J2EE)- Designed for devices with limited memory,

    (mainly phones) display and processing power.

    The Java Runtime

    In order to run Java applications, a computer has to have the J2SE RuntimeEnvironment (JRE) installed. The JRE includes the Java Virtual Machine (JVM). Asmentioned previously the JVM is the software that translates Java into yourmachine's native language. So, someone running Windows on an Intel x86 machine,would install the Windows version of the JRE.

    http://java.about.com/od/a/g/api.htmhttp://java.about.com/od/a/g/api.htm
  • 7/24/2019 ITEC133_Lec1

    11/12

    9

    The Java Development Kit

    As a programmer, you'll also need the J2SE Development Kit (JDK). The JDKincludes everything you need to compile, debug, and run your Java applications. TheJDK includes the Java Runtime Environment so you shouldn't need to download the

    JRE.

    Introduction to Object Oriented Concepts

    Objects

    What Is an Object?

    Objects are key to understanding object-orientedtechnology. Look around right nowand you'll find many examples of real-world objects: your dog, your desk, yourtelevision set, your bicycle.

    Real-world objects share two characteristics: They all have stateand behavior. Dogshave state (name, color, breed, hungry) and behavior (barking, fetching, waggingtail). Bicycles also have state (current gear, current pedal cadence, current speed)and behavior (changing gear, changing pedal cadence, applying brakes). Identifyingthe state and behavior for real-world objects is a great way to begin thinking in termsof object-oriented programming.

    Take a minute right now to observe the real-world objects that are in your immediatearea. For each object that you see, ask yourself two questions: "What possible statescan this object be in?" and "What possible behavior can this object perform?". Makesure to write down your observations. As you do, you'll notice that real-world objects

    vary in complexity; your desktop lamp may have only two possible states (on and off)and two possible behaviors (turn on, turn off), but your desktop radio might haveadditional states (on, off, current volume, current station) and behavior (turn on, turnoff, increase volume, decrease volume, seek, scan, and tune). You may also noticethat some objects, in turn, will also contain other objects. These real-worldobservations all translate into the world of object-oriented programming.

  • 7/24/2019 ITEC133_Lec1

    12/12

    10

    A software object.

    Software objects are conceptually similar to real-world objects: they too consist ofstate and related behavior. An object stores its state in fields (variables in someprogramming languages) and exposes its behavior through methods (functions insome programming languages).

    Classes

    In the real world, you'll often find many individual objects all of the same kind. Theremay be thousands of other bicycles in existence, all of the same make and model.Each bicycle was built from the same set of blueprints and therefore contains thesame components. In object-oriented terms, we say that your bicycle isan instance of the class of objects known as bicycles. A class is the blueprint fromwhich individual objects are created.