Why JAVA??
JAVA as you all know is famous for its Portability that is as per the famous quote
"Write Once Run Anywhere". So once you finish writing a java program,you can compile it using your java compiler so that it is turned to bytecode. The Bytecode is a platform-independent code which can be used to run the written java program on any machine which has a JVM-java virtual machine installed in the system. The JVM interpretes the bytecode to run your java program.
The next question that arises is how to compile and run a java program?A software called JDK that was developed by Sun Microsystems makes our job simpler.A compiler called 'javac' that comes with JDK helps to compile the java program. Follow the below steps to successfully create your first java program.
Step1:
Create a java program HelloWorld.java
package firstPackage;
public class FirstProgram {
public static void main(String args[]){
System.out.println("My first java program");
}
}
}
Step:2Compile the java program
now open the command prompt and go to the place where you had created your java program and type the below command
G:\workspace\firstjava\src\firstPackage>javac -d c:\users\me FirstProgram.java
-This will create FirstProgram.class inside a folder named 'firstPackage' which is the package name which you had given in the java program.
you can find this here.....C:\users\me\firstPackage
Step:3Now type the following in the command prompt after traversing to the required path
C:\Users\Me>java firstPackage/FirstProgram
My first java program
That's it! Your first java program is created.
No comments:
Post a Comment