You can see the class file generated in the folder. Once the compilation is done, we can execute the program by using the below command java MyFirstJavaJCGProgramįind the screenshot below and you will be able to see the output of the program. Bytecode is the intermediary code that java generates and get executed by the JVM. class file, MyFirstJavaJCGProgram.class in our case contains the bytecode. class file on a successful compilation of the program. Javac is a compiler that compiles the program(check for the syntax errors) and generates the. You can see the name of the file should always be same as the public class in a java file.Now to compile the java program enter the command as shown below javac MyFirstJavaJCGProgram.java Save the file in a folder and go to the folder from the terminal. Once created write the content as shown below to the java file public class MyFirstJavaJCGProgram Make sure the file have the extension as java( to make sure java recognises that), for example MyFirstJavaJCGProgram.java. Create a file with any name of your choice. In order to run your first java program open any text editor of your choice. Once verifying the installation, now we can run the programs.
Compiling and Executing your first Java program
In case if you already have a variable called PATH in the environment variables, you can just Go to Edit and add the value as shown below PATH=%PATH% C:\Program Files\Java\jdk1.8.0_131.jdk\bin 3. Now go to the My Compute–> Right Click and go to the properties–> Click on the Advanced System Settings –> Go to the environment variables –> Click New and add a variable as PATH and paste the path of the bin folder you copied previously. In order to set it into the environment variables we need to know where the java has been installed and just copy the path till the bin for example it could be like this C:\Program Files\Java\jdk1.8.0_131.jdk\bin Warning: The links /usr/lib/jvm/default and /usr/lib/jvm/default-runtime should always be edited with archlinux-java.Export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Homeįor Windows, we need to manually set up the java in the environment variables to be able to execute program from the command line.