Brief History of Java-Lecture

Embed Size (px)

Citation preview

  • 8/3/2019 Brief History of Java-Lecture

    1/10

    Brief History of Java

    Java, having been developed in 1991, is a relatively new programming language. At that time,James Gosling from Sun Microsystems and his teambegan designing the first version of Javaaimed at programming home appliances which are controlled by a wide variety of computer

    processors.

    Gosling's new language needed to be accessible by a variety of computer processors. In

    1994, he realized that such a language would be ideal for use with web browsers and Java'sconnection to the internet began. In 1995, Netscape Incorporated released its latest version of

    the Netscape browser which was capable of running Java programs.

    Why is it called Java? It is customary for the creator of a programming language to name the

    language anything he/she chooses. The original name of this language was Oak, until it wasdiscovered that a programming language already existed that was named Oak. As the story goes,after many hours of trying to come up with a new name, the development team went out for

    coffee and the name Java was born.

    While Java is viewed as a programming language to design applications for the Internet, it is

    in reality a general all purpose language which can be used independent of the Internet.

    Acronyms

    ALU - Arithmetic Logic Unit -the part of the processor which performs =, +, -, , ,>,etc. operations and comparisons.

    CRT - Cathode Ray Tube -an electrical device found in monitors for displaying images byexciting phosphor dots with a scanned electron beam. CRT is often used to mean monitor.

    CPU - Central Processing Unit -the heart (brains) of the computer system. It is comprisedof the control unit, the arithmetic logic unit, and temporary storage (RAM).

    DOS - Disk Operating System - was the first widely-installed operating system for personal computers developed for IBM by Microsoft. It is software used in most computer

    systems to manage storage devices as well as data of any kind, including files. It is referred to asa "disk" operating system because the storage devices are made of rotating platters.

  • 8/3/2019 Brief History of Java-Lecture

    2/10

    IDE - Integrated Development Environment - a system where you can control theediting and compiling from one program.

    LAN - Local Area Network - a set of computers connected in order to share programs andstorage space. "Local" implies that the network is contained within a relatively small space, such

    as a classroom, an office, one section of the building, or one building.

    OOP - Object Oriented Programming - the use of small, reusable components toconstruct large software systems.

    OS - Operating System - the program that manages all the other programs in a computer.Some popular operating systems include MS-DOS, Windows 98/2000/NT/XP, MacOS, Unix,and Linux.

    RAM - Random Access Memory - temporary memory lost when the computer is turnedoff.

    ROM - Read Only Memory -hardwired memory which cannot be changed. Contains thesystem directions.

    Vocabulary

    Hardware - the "machinery" - computer equipment - the CPU, the monitor, the keyboard, themouse, the external speakers, the scanner, the printer, etc. The physical, touchable parts of a

    computer system.

    Software - the program instructions that make the computer do something, such as wordprocessing, database management, games, etc. Your Java programs will be your software.

    Program - a listing of instructions (code) for the computer to follow written in some programming language. For this course, these instructions will be written in the language ofJava.

    Hard Copy - a paper printout of the program code or data displayed on the screen.

    Soft Copy - copy of a program stored on a hard drive, diskette, or CD.

    Network - a hardware and software data communication system. Usually a group ofcomputers that are linked to share memory and programs.

    Control Unit - the unit inside of the CPU which "directs the traffic" - makes decisions. Itperforms the functions of fetch, decode, execute, and store.

  • 8/3/2019 Brief History of Java-Lecture

    3/10

    Machine Language - the lowest level of computer languages where instructions are given bynumeric code.

    High Level Language - a computer language which is easily read by humans - the codeconsists of English-like words where each statement corresponds to several machine language

    instructions.

    Object Code - the machine code version of the source program (a program written by aprogrammer).

    Compiler - converts the source code of a program to machine language placing the result in anobject code file.

    Interpreter - converts a program one line at a time into machine language.

    Bit - the representation of a 1 or 0 designating power ON or power OFF. A binary digit.

    Byte - 8 bits.

    Kilobyte - approximately 1000 bytes (1024 bytes).

    Megabyte - approximately 1,000,000 bytes (1,048,576 bytes).

    Gigabyte - approximately a billion bytes (1,073,741,824 bytes).

    Why are the actual

    number of bytes

    "more" than what

    we expect them to

    be?We are thinking"kilo" in base 10

    while the computer

    is thinking "kilo" in

    base 2.

    Format/Initialize - to prepare a storage device (diskette or hard disk) for receivinginformation for a system. The storage device is said to be formatted (into areas called sectors

    and tracks) when its space has been divided and organized into areas that can be quicklycontrolled by the system for storage and access.

  • 8/3/2019 Brief History of Java-Lecture

    4/10

    The MechanicsofCreating

    a Java Program

    Java Program: a set of instructions for the computer to follow. The source code.

    Data: data for the Java program

    Java Compiler: translates the program from Java to a language that the computer can

    understand. Compilers differ by make of machine and operating systems.

    Byte Code Program: the compiler translates Java into a language called byte-code. Byte codeis the machine language for a hypothetical computer called the Java Virtual Machine.

    Byte Code Interpreter: the interpreter translates each instruction of byte code into instructionsthat the computer in use can execute.

    Machine Language: is the language the computer in use understands.

  • 8/3/2019 Brief History of Java-Lecture

    5/10

    Parts of a Java Program

    /**************************************Project: LabOneA

    *Programmer: John Smith*Date: September 23*Program Name: Hello.java

    **************************************/import java.io.*;public class Hello{

    public static void main (String[ ] args){

    System.out.println("This is a literal print.");System.out.print("Yea!");

    System.out.println("Go Java!");}}

    The CODE: Information about the code:

    /**************************************Project: LabOneA*Programmer: John Smith*Date: September 23

    *Program Name: Hello.java**************************************/

    All programs should begin with a comment

    identifying the purpose of the program and theprogrammer.

    /**documentation */ - documentation

    commenting./* text*/ - is the format for block commenting.// text - is the format for single line commenting.Comment statements are ignored by the

    compiler. It is a message to the reader of thecode.

    import java.io.*;

    The import command tells the computer to findpackages that will be needed in the execution of

    the program. The java.lang package is the onlypackage imported automatically without an

    explicit command; all other packages need animport command. This package is used for input

    and output. (Packages are collections of classes(libraries) which contain portable Java bytecode

    files.)

  • 8/3/2019 Brief History of Java-Lecture

    6/10

    public class Hello

    Every Java program is a class. The program

    starts with the name of the class. This namemust be the same name as the . java file in

    your folder. In this case the file is saved asHello.java.

    Class names must begin with a letter, an

    underscore or a dollar sign.Class names may contain only letters, digits,

    underscores and/or dollar signs.Class names may not use reserved words.

    {A set of French curly braces { } is needed for

    every class.

    public static void main (String[ ] args)

    A main method is needed for execution to havea place to start. This main method gets executed

    first. The idea of static will be discussed later.

    The array of strings parameter is a necessity.

    {A set of French curly braces { } is needed formain.

    System.out.println("This is a literalprint.");System.out.print("Yea!");System.out.println("Go Java!");

    Output statements: the basic output statement

    in Java is the System.out.println( ) statement.The System.out.println( ) line will print what is

    between the double quotes" " (called a literalprint) and move the printing cursor to the next

    line.The System.out.print( ) line will print what is

    between the double quotes and leave the printingcursor on the same line.

    }}

    Braces are closed to end the program.

  • 8/3/2019 Brief History of Java-Lecture

    7/10

    Style Issues

    Program Format:

    import java.io.*;//printing a message onthe screen//notice the format ofthe codepublic class HelloClass{

    public static void main (String[ ] args){

    System.out.println ("Hello, Java world!");System.out.println ("I plan to be a Java expert!");

    }}

    Notice the format style thatwe will be using. The

    indentations keep the codeclearly visible and easy to

    read.

    It is possible, in Java, towrite all of your code on one

    line -- this is called freeform style. Free form style

    is extremely difficult todebug at a later date and is

    nearly impossible for a

    programming team todecipher. We will NOT beusing free form style.

    Case sensitivity:

    if (netpay > grosspay)

    If (NetPay > GrossPay)

    IF (NETPAY > GROSSPAY)

    Java is very picky about

    your caps lock key. Thethree lines of code at the

    left, at first glance, mayappear to all say the same

    thing. The Java compiler,

    however, will only executethe first line of code. MostJava code is written in

    smaller case and ALLreserved words (such as

    "if") MUST be written insmaller case.

    Comments:

    import java.io.*;

    //printing anothermessage onthe screen//notice the commented linespublic class HelloAgainClass{

    public static void main (String[ ] args){

    System.out.println ("Hello!"); //firstprintSystem.out.println ("I just love this Java!");

    In Java, comments may beexpressed in different forms.

    The comments beginningwith // are single line

    comments. They canappear on a line by

    themselves, or they mayfollow other lines of code.

    The comments enclosed

  • 8/3/2019 Brief History of Java-Lecture

    8/10

    }}/*sometimes comments are longerstatements thatwrap around to the next line onthe screen*/

    within /* and */ are used forlonger comments that wraparound a line.

    Blank Space:

    import java.io.*;//notice the spacinginthis codepublic class HelloStillClass{

    public static void main (String[ ] args){

    System.out.println ("Java rocks!");

    System.out.println ("A real space cadet!");}

    }

    The compiler ignores extra

    blanks between words andsymbols.

    Blank lines between lines ofcode are also ignored.

    Notice the blank linebetween the two print

    statements.

    You cannot, however,embed blanks in identifiers.

    The use of blanks improves

    readability.

    Examples of comments

    There are 3 styles of comments:

    /**documentation */ - documentation commenting./* text*/ - is the format for block commenting.

    // text - is the format for single line commenting.

    Comment statements are ignored by the compiler.

    Comments are simply messages to the reader of the code.

    /************************************ *Project: Demo forComments*Programmer: Mr. Data*Date: June, 2003*Program Name: Comments.java*************************************/

    import java.io.*;public class Comments

  • 8/3/2019 Brief History of Java-Lecture

    9/10

    {public static void main (String[ ] args){

    System.out.println("Hi"); //message to userSystem.out.println("LabOneA"); //assignment

    }}/*if you wantto write a detailed comment, and itwraps around the screen, use this block style ofcommenting.*/

    The CODE:Information about the

    code:

    /************************************ *Project: Demo forComments*Programmer: Mr. Data*Date: June, 2003*Program Name: Comments.java*************************************/

    All programs should begin witha comment identifying thepurpose of the program and the

    programmer. For our courseplease use the style shown at the

    left.

    import java.io.*;public class Comments{

    public static void main (String[ ] args){

    System.out.println("Hi"); //message to userSystem.out.println("LabOneA"); //assignment

    }}

    Comments can also be placed

    within the body of a program toact as documentation. These

    comments should be brief and tothe point.

    This body prints Hi! on thescreen and LabOneA on thescreen.

    /*if you wantto write a detailed comment, andit wraps around the screen, use this block styleof commenting.*/

    The block form of commentingis used to display lengthy

    comments that wrap around thescreen.

  • 8/3/2019 Brief History of Java-Lecture

    10/10

    Escape Sequences

    The following is a table ofescape sequences to be used when printing in Java.These statements are embedded within a literal print remark (they go between the quotes):

    Sequence Name Meaning

    \n New line Moves to beginning of next line

    \b Backspace Backs up one character

    \t Horizontal tabMoves to next tab positionTab spacing is every 8 columns starting with 1.(Columns 9, 17, 25, 33, 41, 49, 57, 65, 73 ...)

    \\ Backslash Displays an actual backslash

    \' Single quote Displays an actual single quote

    \" Double quote Displays an actual double quote

    System.out.println("\tGeorge\t\tPaul");

    will tab, print George, tab twice more, and print Paul.