1. Using the Command-Line Tools to compile and launch a Java program from the command line.
/** * @purpose: This program will print the Welcome message * @author: hoiquanphanmem * @date: 11/18/2014 */ public class Welcome { public static void main(String[] args) { String[] greeting = new String[3]; greeting[0] = "Welcome to Core Java"; greeting[1] = "by hoi quan ngoai ngu giao tiep"; greeting[2] = "va cong nghe phan mem"; for (String g : greeting) System.out.println(g); } }
2. Using IDE Eclipse IDE Eclipse for Java developer is an integrated development environment that is freely available from http://eclipse.org. a. This is how to install IDE Eclipse for Java Developer Step 1: Download the eclipse Step 2: Extract the zip file Step 3: Extract the zip file to C:\ b.This is how to compile and run a program with IDE Eclipse Step 1: Start IDE Eclipse Step 2: Select a workspace Step 3: Close the welcome window Step 4: Select File -> New -> Java Project from the menu Step 5: Supply the project name “Welcome” and click the “Next” button Step 6: Click the “Finish” button. The Project is now created Step 7: right click on “source”, Select New -> File Step 8: Supply the file name “Welcome” and click the Finish button. The source file is now created Step 9: Edit the source code, type the Welcome.Java program in the editor Step 10: Click on the project name (Welcome) in the leftmost pane. Select Run -> Run As -> Java Application 3. The Welcome Java Program Let’s look more closely at about the Welcome Java program. Java Keywords
- public Makes a class, method, or variable accessible from any other class.
- class Keyword used to specify a class
- new Used to instantiate an object by invoking the constructor.
- static Makes a method or a variable belong to a class as opposed to an instance
- for Used to perform a conditional loop for a block of code
- void Indicates no return type for a method
- main method
When you use java ClassName to run a compiled program, the Java virtual machine always starts execution with the code in the main method in the class you indicate. Thus, you must have a main method in the source file for your class for your code to execute. You can, of course, add your own methods to a class and call them from the main method. Notice the braces { }in the source code. In Java, as in C/C++, braces delineate the parts (usually called blocks) in your program. In Java, the code for any method must be started by an opening brace {and ended by a closing brace }