Thursday, December 26, 2013

Java Compiler, interpreter and configuring.

Hi Guys in this post we learn, what is java compiler, interpreter and how to configure java.

All the programming languages require compiler and a interpreter so that the instructions written the high level language can be easily understood by the system. Same is the case with the JAVA only difference between JAVA and other languages is java compiler will not convert the code into executable code rather it converts it in to byte code. The advantage of this byte code is, it can be executed on any platform if one has java interpreter of JVM[Java Virtual Machine] as explained in the below image.
Source: Head.First.Java.2nd.Edition

How To configure:

Before configuring let me explain the difference JDK and JRE. 

JDK: Java Development Kit which consists of both compiler(javac) and JVM(java). javac is a command to compile the java program and java is a command to interpret the byte code. We will learn how to use these commands shortly. Downloading and installing the JDK will enable your system to perform both compiling and interpreting the java code using javac and java commands from command line respectively.

In case you are only interpreting but not compiling any java code then you can just install JRE.

JRE: Java Run time Environment consists of only JVM(java) which enables one's system to run the java byte code irrespective platform where the byte code has been compiled. As said above we need java command to run the byte code. To run this command compiler is not mandatory.

One can download the JDK and JRE from:
http://www.oracle.com/technetwork/java/javase/downloads/index.html

Windows Configuring:

After downloading JDK or JRE as per requirement[either 32 or 64 bit based on system] you can install the executable by double clicking on it and follow the steps.
Once it is done you need to include javac and jre in your path variables, to do it please follow the steps below.

Windows 7-configuration:

1: Click on Windows button.
2. Right click on  computer and click on properties.
3. Click on Advanced system settings.
4. Click on Environment variables button and select a 'path' variable from 'system variables section as shown in the below image and click on edit button.
5. In the window pop up add the path “C:\Program Files (x86)\Java\jdk\bin” if you have downloaded JDK or “C:\Program Files (x86)\Java\jre\bin” if you have downloaded only JRE. 
The folder structure may differ based on the system type you have chosen 32 or 64. If you have chosen 32 bit then the folder structure will be as mentioned otherwise it will something like "C:\Program Files\Java\jdk\bin".
Note: Be careful while editing the path variables. All the values in the path variable are separated by colon(;) so, add the above path with out editing any values to the end of it separated by colon(;).


Once you are done with the above steps open command window and type javac -version and java -version
This commands should give you the version info of the java you installed in your machine as shown in the below image.
Note:Close all the open command windows before running the above commands

This ensures that we have successfully installed the java in our machine.
If one has installed JDK both the commands will give version info, in case of JRE only java -version will give info as compiler is not available.

Windows-8 Configuration:

To configure java in windows-8 please follow the below stpes.

1. Run Control Panel in Windows 8's Metro UI.
2. Click More Settings in Control Panel  on the left.
3. Search "Environment Variables" in Control Panel, and click "Edit the system environment variables".
4. Click on "Environment Variables"
5. Repeat steps 4 and 5 from the windows-7 configurations.
6. Once it is done you can verify the java installation by running the javac and java commands as told in  windows-7 configurations.

Hope this helps everyone..



Saturday, December 14, 2013

What makes JAVA special

I guess every person who wants to learn a programming language starts with a Hello World program. I am no different in that. I toot started with the same thing. After I started liking this language I felt like knowing what makes this language different from others. Though I have studied computer subjects like 'Computer Architecture', Computer Networks', 'Database', 'Compilers' etc  as my electives, I have not taken them seriously because mathematics dominated then. When Started digging things about 'what makes JAVA different from others', all those concepts which I have studied for examination purpose flashed in front of my eyes. Out of those concepts compilers and interpreters are the ones which refreshed my memory.

Coming back to JAVA, First major difference that I found between Java and other languages is "It is Platform Independent--Compile once and use it on any platform you want using java interpreter". One more important aspect of Java is it solves both security and portability problem by compiling the source code into a byte-code instead of executable code. This aspect of Java differentiates it with other languages.

Here in this post I want to post what are the advantages and disadvantages that Java has instead of 'Hello- Word' program.


Advantages of JAVA:


JAVA offers a number of advantages to developers.

Java is simple: Java was designed to be easy to use and is therefore easy to write, compile, debug, and learn than other programming languages. The reason that why Java is much simpler than C++ is because Java uses automatic memory allocation and garbage collection where else C++ requires the programmer to allocate memory and to collect garbage.

Java is object-oriented: Java is object-oriented because programming in Java is centered on creating objects, manipulating objects, and making objects work together. This allows you to create modular programs and reusable code.

Java is platform-independent: One of the most significant advantages of Java is its ability to move easily from one computer system to another.
The ability to run the same program on many different systems is crucial to World Wide Web software, and Java succeeds at this by being platform-independent at both the source and binary levels.

Java is distributed: Distributed computing involves several computers on a network working together. Java is designed to make distributed computing easy with the networking capability that is inherently integrated into it.
Writing network programs in Java is like sending and receiving data to and from a file.

Java is interpreted: An interpreter is needed in order to run Java programs. The programs are compiled into Java Virtual Machine code called bytecode.
The bytecode is machine independent and is able to run on any machine that has a Java interpreter. With Java, the program need only be compiled once, and the bytecode generated by the Java compiler can run on any platform.

Java is secure: Java is one of the first programming languages to consider security as part of its design. The Java language, compiler, interpreter, and runtime environment were each developed with security in mind.

Java is robust: Robust means reliable and no programming language can really assure reliability. Java puts a lot of emphasis on early checking for possible errors, as Java compilers are able to detect many problems that would first show up during execution time in other languages.

Java is multithreaded: Multithreaded is the capability for a program to perform several tasks simultaneously within a program. In Java, multithreaded programming has been smoothly integrated into it, while in other languages, operating system-specific procedures have to be called in order to enable multithreading. Multithreading is a necessity in visual and network programming.

Disadvantages of JAVA:

Performance: Java can be perceived as significantly slower and more memory-consuming than natively compiled languages such as C or C++.

Look and feel: The default look and feel of GUI applications written in Java using the Swing toolkit is very different from native applications. It is possible to specify a different look and feel through the pluggable look and feel system of Swing.

Single-paradigm language: Java is predominantly a single-paradigm language. However, with the addition of static imports in Java 5.0 the procedural paradigm is better accommodated than in earlier versions of Java. With Java 6.0 and 7.0 one can overcome this.

Hope this helps all those who reads it. Lets meets in my next post which talks about what is java compiler, interpreter, what makes it portable and how to configure Java in various operating systems.