Sunday, December 10, 2017

Java Basic 001

A Simple Java Program


Let us being with java program that displayed the message “welcome to java….!!” on the console.



Every Java programmer must have at least one class. A class is a construct that defines data and methods. Each class has a name. By convention, class names start with an upper case latter. In this example, the class name is Welcome.
In order to run a class, the class must contain a method named main. The JVM executes the program by invoking the main method. A method is construct that contains statements. The main method in this program contains the System.out.pritln statement. This statement prints a message “Welcome to Java…!!”  to the console.

Creating, Compiling, and Executing the Java Program 


You have create your program and compile it before it can be executed. This process is repetitive, as shown in above Figure. if your program has compilation errors, you have to fix them by modifying the program, and then recompile it. If your program has runtime errors or does not produced the correct result, you have to  modifying the program, recompile it, and execute it again.

You can use any text editor to create and edit a java source code file, or you can use an IDE like JCreator , Eclipse , JBuilder or NetBeans.



This file must end with the extension .java and must have the exact same name as the public class name. For example, the file for the source code in above image should be named Welcome.java , since the public class name is Welcome.

A Java compiler translates a Java source file into a Java bytecode file. The following command compiles Welcome.java:

Javac Welcome.java 


If there are no syntax errors, the compiler generates a bytecode file with a .class. the bytecode is similar to machine instructions but is architecture-neutral and can run on any platform that has a JVM. This is one of Java's primary advantages: Java bytecode can run on a variety of hardware platform and operating systems.

To execute a java program is to run the program's bytecode. You can execute the bytecode on any platform with a JVM. The following command runs the bytecode

java Welcome 






No comments:

Post a Comment

How many application installed on Linux

Identify all Linux codes that accessible from terminal https://www.youtube.com/watch?v=p6VGmXlTEYs