















































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!
















































Mitsu Ogihara
Department of Computer Science University of Miami
(^1) The Programming language Java
(^2) Our First Program
(^3) Errors
(^4) Special Characters and Commenting
In programming environments, the numbers are often represented using either the binary encoding or the hexadecimal encoding Binary Encoding : the denominations are powers of 2 and at each position the number is either 0 or 1 Hexidecimal Encoding : the denominations are powers of 16 and at each position the number is one of 0 .. 9 and A .. F, where A - F correspond to 10 - 15
Decimal Binary Hexadecimal 0 0 0 10 1010 A 11 1011 B 12 1100 C 13 1101 D 14 1100 E 15 1111 F 99 1100011 63 100 1100100 64 127 1111111 7F 128 10000000 80
Java Virtual Machine (JVM) is a program that provides a machine-like environment in which to run Java bytecodes , the kind of program exclusively designed for Java To run Java bytecodes you need Java runtime , a program that runs on JVM
Hardware (e.g., Macbook Pro)
Operating System (e.g., El Capitan)
Java Virtual Machine
Java Runtime
Compilation & Execution Tools (e.g., shell programs, integrated development environments)
(^1) Use a text editor to write the source code (with the file extension of “.java”) (^2) Generate the Java bytecode (with the file extension of “.class”) from the source code (^3) Execute the bytecode
(^1) Use a text editor to write the source code (with the file extension of “.java”) (^2) Generate the Java bytecode (with the file extension of “.class”) from the source code (^3) Execute the bytecode
IDEs combine the first two steps into one In a shell environment, the second step is accomplished by executing a line command javac
The source code of HelloWorld
1 public class HelloWorld { 2 public static void main( String[] args ) { 3 System.out.println( "Hello, World!" ); 4 } 5 }
The source code of HelloWorld
1 public class HelloWorld { 2 public static void main( String[] args ) { 3 System.out.println( "Hello, World!" ); 4 } 5 }
A class is a building block of Java programs This code specifies that “HelloWorld” is a class
In a shell environment you type a command to execute
By the command javac
By the command java
% javac HelloWorld.java % java HelloWorld Hello, World! % Here % is the shell’s output to indicate the start of a new command, called prompt
public class
A method is a named block of code The main in the example is a method has attributes public, static, and void and has a parameter String[] args to run with The class name should be followed by a pair of curly brackets in which the contents appear Each method name followed by a pair of curly brackets in which the contents appear
public static void main( String[] args ) {
A statement is an executable unit
1 public class HelloWorld2 { 2 public static void main( String[] args ) { 3 System.out.println( "Hello, World!" ); 4 System.out.println( "Hello, Class!" ); 5 System.out.println(); 6 System.out.println( "This is the fourth line of output." ); 7 } 8 }