The Java Programming Language Invented 1995 by James

The Java Programming Language • Invented 1995 by James Gosling at Sun Microsystems. • Based on previous languages: C, C++, Objective-C, … • Intended to be a safe programming language for the Internet • Common choice for first programming language § § § Object oriented Encourages good programming habits Very popular commercially Simpler and more elegant than C++, but similar to it Cool Lecture A Slide 1 of 40.

Hello World Program // My First Program!! public class Hello. World { public static void main(String[] args){ System. out. println(“Hello World!”); } } Lecture A Slide 2 of 40.

Java Program Elements • Words § § Keywords Identifiers • Constants Numbers § Strings § • Symbols § ()[]{}, . ; +-*/ • Comments Lecture A Slide 3 of 40.

Java Elements Comment Identifier Symbols // My First Program!! public class Hello. World { public static void main(String[] args){ System. out. println(“Hello World!”); } } Keywords String Constant Lecture A Slide 4 of 40.

Java Program Structure • A program is composed of a collection of classes • Each class contains a collection of methods • Each method is composed of a sequence of instructions (commands, statements) Lecture A Slide 5 of 40.

Java Program Structure Class Method // My First Program!! public class Hello. World { public static void main(String[] args){ System. out. println(“Hello World!”); } } Instruction Lecture A Slide 6 of 40.

Running a Java Program • Use an editor to enter (type) the program § Save to a file named Hello. World. java • Use the compiler to translate the program into bytecode javac Hello. World. java § This produces a file named Hello. World. class § • Run the program using the Interpreter § java Hello. World Lecture A Slide 7 of 40.

Java Compilation Xxx. java Compiler Xxx. class Interpreter Output Lecture A Slide 8 of 40.

Entering a Java Program into an Editor Lecture A Slide 9 of 40.

Running a Java Program Lecture A Slide 10 of 40.
- Slides: 10