Engineering Full Stack Apps with Java and JavaScript
JDK stands for Java Development Kit, which contains the compiler executable javac.exe. The java.exe executable compiles the source code (.java files) into an intermediate form called as byte code ( .class files). If a source file has more than one class, each class is compiled into a separate .class file.
JRE stands for Java Runtime Environment and contains the JVM (the interpreter java.exe executable). The java.exe executable reads the byte code (.class file), translates it into the native language of the host machine and execute it.
A java program is written in a .java file, which is called as source code file.
javac.exe (part of JDK) which compiles the source code source files (.java files) into a .class file.
JVM java.exe (part of JDK and JRE) reads the byte code and translates it into the native language of the host machine on the fly, and execute.
A class can have variables (properties) and methods (functions).
Let us write a simple class called Hello with a single method called main, in a file Hello.java:
public class Hello {
public static void main(String[] args)
{
System.out.println("Hello");
}
}
Save the file Hello.java.
Note: Classes and methods are explained in other tutorials. The scope of this tutorial is only to execute and see the output to verify environment.
Compiling the program
To compile source code file (Hello.java) from command line, go to command prompt and go to the folder where your .java file is present (e.g. using 'CD path' where path is the path to your folder.)
javac Hello.java
A file called Hello.class will be created.
Executing the program
You can execute the class file (Hello.class) from command line as:
java Hello
Don't mention .class.
Rather than writing the code in command line, you can use an IDE like Eclipse for easy writing and execution. But during the initial learning days, I would suggest you use command line for a better understanding of the basics.
Main Method in Java
Main method is a static method whose name is already known to Java. You executed the class without specifying any method name, but only the class name. Java will look for a method with name as main and above syntax (from example). The main method is the entry point to a desktop based core Java application.
You can read more @ http://javajee.com/main-method-in-java.
Some useful DOS commands for Windows OS
To go to a path (e.g. C:\javaprograms)
CD C:\javaprograms
To see files in a folder
DIR
Rename a file (e.g. from asdfg.txt to qwert.txt)
rename asdfg.txt qwert.txt
Comments
nicely explained
nicely explained
problem with command promt
facing some problem while i am trying to compile my program.whenever i write " javac " a messege appears informing javac is not recognised.
what to do ???
Re: problem with command promt
This is because javac is not in your PATH. The PATH environment variable is something that the operating system uses to find executable files like javac. The PATH variable contains directories of executables seperated by semi colon (windows) or colon(linux). If you type "javac" in command prompt, you should have the "bin" directory of your jdk into the PATH.
Regarding Java Programming
As I am Very New to Programming so I am Confused when coming to this programming point especially on 7th step, could you pls explain.. Thank you