A Java program just does not run like any other program written in any other language. There is no direct windows .exe file which can be generated (as of now in my lessons). Now back to the question -how do we run a Java program?
Java, is a platform independent language. But any Java program we write has to be run in an environment, be it any platform, and the concept of a platform independence means that if i write a program in my laptop(windows), it should work fine in my brother’s mac, or for that sake in my friend’s laptop (Linux) as well.
This is achieved not by any platform independence funda, but by a virtual machine which allows the program to be a “write once run anywhere code”-as Java lovers call it. So, it is but evident that every OS, has it’s own JVM-the Java Virtual Machine. It behaves like an emulator, thereby making the program believe that it is running in a Java environment.
For more info on JVM, see here.
So, if you have J2SDK installed(suggested use is the latest version 1.6) and a JVM installed, try the following:
javac "filename.java"
This will compile your program and generate the necessary bytecodes which is converted to executable code by the JVM, with the help of a JIT(Just in time) compiler- a component of the JVM.
If there are any errors, you will see it, correct them, and if not move to:
java "filename"
This should do. Try to keep you program in the bin folder of the java installation, or else use:
javac -c "path to the program class file" "filename.java"
Once you know it is done like this, use an stop using the boring command line and move to an IDE with auto complete-as i suggested here.
Using an IDE is an opposed idea, but you get to know about a lot of functions, which books do not teach. So, use an IDE for faster development and better knowledge and proficiency with any language. Now that the program runs, go grab a cup of coffee.
Chinmoy Kanjilal is the geek behind Techarraz. This is where he rants about his adventures with technology. Get to know him better, and connect with him on social networks.
n wht about linux??