




















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Instructions on creating and running a simple java program using notepad, wordpad, and various ides such as textpad, jbuilder, and netbeans. It covers creating and modifying source code, compiling it using javac, and running the bytecode using java. The document also explains the concept of trace a program execution and compiling and running java from the command window.
Typology: Slides
1 / 28
This page cannot be seen from the preview
Don't miss anything!





















Introduction to Java
//This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { System.out.println("Welcome to Java!"); } }
To use Word Pad , type w rite Welcom e.java from the DOS prom pt.
Creating, Compiling, and Running Programs
Source Code
Create/Modify Source Code
i.e., javac Welcome.java^ Compile Source Code
Bytecode
i.e., java Welcome^ Run Byteode
Result
If compilation errors
If runtime errors or incorrect result
public class Welcome { public static void main(String[] args) { }^ System.out.println("Welcome^ to Java!"); }
… Method Welcome() 0 aload_0 … Method void main(java.lang.String[]) 0 getstatic #2 … Java!^ 3 ldc #3 <String">^ "Welcome to 5 invokevirtual #4 … 8 return
Saved on the disk
stored on the disk
Source code (developed by the programmer)
Byte code (generated by the compiler for JVM to read and interpret, not for you to understand)
Trace a Program Execution
//This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { System.out.println("Welcome to Java!"); } }
Execute statement
animation
Trace a Program Execution
//This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { System.out.println("Welcome to Java!"); } }
animation
print a message to the console
Anatomy of a Java Program
Comments
In Java, comments are preceded by two slashes (//) in a line, or enclosed between /* and / in one or multiple lines. When the compiler sees //, it ignores all text after // in the same line. When it sees /, it scans for the next / and ignores any text between / and */.
Reserved Words
Reserved words or keywords are words that have a specific meaning to the compiler and cannot be used for other purposes in the program. For example, when the compiler sees the word class, it understands that the word after class is the name for the class. Other reserved words in Listing 1.1 are public, static, and void. Their use will be introduced later.
Modifiers
Java uses certain reserved words called modifiers that specify the properties of the data, methods, and classes and how they can be used. Examples of modifiers are public and static. Other modifiers are private, final, abstract, and protected. A public datum, method, or class can be accessed by other programs. A private dat or method cannot be accessed by other programs.
A pair of braces in a program forms a block that groups
components of a program.
public class Test { public static void main(String[] args) { System.out.println("Welcome to Java!"); } }
Class block Method block
Classes
The class is the essential Java construct. A class is a template or blueprint for objects. To program in Java, you must understand classes and be able to write and use them. For now, though, understand that a program is defined by using one or more classes.