Sie sind auf Seite 1von 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 team began designing the first version of Java aimed 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's connection 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 was discovered 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 by
exciting 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 comprised
of 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 as a "disk" operating system because the storage devices are made of rotating platters.

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

LAN - Local Area Network - a set of computers connected in order to share programs and
storage 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 to


construct 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 turned
off.

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

Vocabulary
Hardware - the "machinery" - computer equipment - the CPU, the monitor, the keyboard, the
mouse, 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 word
processing, 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 of Java.

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 of computers that are linked to share memory and programs. Control Unit - the unit inside of the CPU which "directs the traffic" - makes decisions. It
performs the functions of fetch, decode, execute, and store.

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

High Level Language - a computer language which is easily read by humans - the code
consists 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 a
programmer).

Compiler - converts the source code of a program to machine language placing the result in an
object 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 receiving information 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 quickly controlled by the system for storage and access.

The Mechanics of Creating 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 code is the machine language for a hypothetical computer called the Java Virtual Machine. Byte Code Interpreter: the interpreter translates each instruction of byte code into instructions that the computer in use can execute. Machine Language: is the language the computer in use understands.

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:
/************************************* *Project: LabOneA *Programmer: John Smith *Date: September 23 *Program Name: Hello.java **************************************/

Information about the code:


All programs should begin with a comment identifying the purpose of the program and the programmer. /**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 the code. The import command tells the computer to find packages that will be needed in the execution of the program. The java.lang package is the only package imported automatically without an explicit command; all other packages need an import command. This package is used for input and output. (Packages are collections of classes (libraries) which contain portable Java bytecode files.)

import java.io.*;

public class Hello

Every Java program is a class. The program starts with the name of the class. This name must be the same name as the . java file in your folder. In this case the file is saved as Hello.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. A main method is needed for execution to have a place to start. This main method gets executed public static void main (String[ ] args) 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 for { main. Output statements: the basic output statement in Java is the System.out.println( ) statement. The System.out.println( ) line will print what is System.out.println("This is a literal between the double quotes" " (called a literal print."); print) and move the printing cursor to the next System.out.print("Yea!"); line. System.out.println("Go Java!"); The System.out.print( ) line will print what is between the double quotes and leave the printing cursor on the same line. } Braces are closed to end the program. }

Style Issues
Program Format:
import java.io.*; //printing a message on the screen //notice the format of the code public 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 that we will be using. The indentations keep the code clearly visible and easy to read. It is possible, in Java, to write all of your code on one line -- this is called free form style. Free form style is extremely difficult to debug at a later date and is nearly impossible for a programming team to decipher. We will NOT be using free form style.

Case sensitivity:
if (netpay > grosspay) If (NetPay > GrossPay) IF (NETPAY > GROSSPAY)

Java is very picky about your caps lock key. The three lines of code at the left, at first glance, may appear to all say the same thing. The Java compiler, however, will only execute the first line of code. Most Java code is written in smaller case and ALL reserved words (such as "if") MUST be written in smaller case. In Java, comments may be expressed in different forms. The comments beginning with // are single line comments. They can appear on a line by themselves, or they may follow other lines of code. The comments enclosed

Comments:
import java.io.*; //printing another message on the screen //notice the commented lines public class HelloAgainClass { public static void main (String[ ] args) { System.out.println ("Hello!"); //first print System.out.println ("I just love this Java!");

} } /*sometimes comments are longer statements that wrap around to the next line on the screen*/

within /* and */ are used for longer comments that wrap around a line.

Blank Space:
import java.io.*; //notice the spacing in this code public 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 and symbols. Blank lines between lines of code are also ignored. Notice the blank line between 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 for Comments *Programmer: Mr. Data *Date: June, 2003 *Program Name: Comments.java *************************************/ import java.io.*; public class Comments

{ public static void main (String[ ] args) { System.out.println("Hi"); //message to user System.out.println("LabOneA"); //assignment } } /* if you want to write a detailed comment, and it wraps around the screen, use this block style of commenting. */

The CODE:
/************************************ *Project: Demo for Comments *Programmer: Mr. Data *Date: June, 2003 *Program Name: Comments.java *************************************/ import java.io.*; public class Comments { public static void main (String[ ] args) { System.out.println("Hi"); //message to user System.out.println("LabOneA"); //assignment } }

Information about the code:


All programs should begin with a comment identifying the purpose of the program and the programmer. For our course please use the style shown at the left. Comments can also be placed within the body of a program to act as documentation. These comments should be brief and to the point. This body prints Hi! on the screen and LabOneA on the screen.

The block form of commenting /* if you want to write a detailed comment, and is used to display lengthy it wraps around the screen, use this block style comments that wrap around the of commenting. */ screen.

Escape Sequences
The following is a table of escape sequences to be used when printing in Java. These statements are embedded within a literal print remark (they go between the quotes): Sequence \n \b \t \\ \' \" Name New line Backspace Horizontal tab Backslash Single quote Double quote Meaning Moves to beginning of next line Backs up one character Moves to next tab position
Tab spacing is every 8 columns starting with 1. (Columns 9, 17, 25, 33, 41, 49, 57, 65, 73 ...)

Displays an actual backslash Displays an actual single quote Displays an actual double quote

System.out.println("\tGeorge\t\tPaul"); will tab, print George, tab twice more, and print Paul.

Das könnte Ihnen auch gefallen