Friday, 6 January 2017

How Install Java and create Java environment.

  •           Open google chrome and type "download JDK latest version"

  • Click on the 5 link "Download Java Development Kit(JDK) - FileHippo.com" .
  • You can view a page like this. Then click on the green button "Download 64 bit(195.13MB)".
  • It will take about 15 to 20 minutes to get download.                                 

  • Open the file named "jdk-8u112-windows-x64" from downloads. A pop up will appear then click "Ok". After that your installation will start.
  • Then just click "Next" and it will give you a screen like this.



  • Wait just for few seconds till your installation completes.
  • After this installation a pop up will appear, then click on "Next". Then a window will appear as shown below.
.
  • After your installation is complete, you can see 2 files in your " c: drive", as  shown below in the highlighted.
  • Next right click on "This PC" or "my computer" and click "properties".




  • Click on "Advanced system settings".
  • Click on "Environment Variables", then click on "Edit".

  • This window will appear. Type "Variable name" as "Path" and copy the "directory" as followed in picture 2 into "Variable value".

picture 1

Picture 2


  • Then click "Ok". And our Java environment is successfully created 😉.





Wednesday, 4 January 2017

Explanation of Java with a simple program.


  •       This example is just displaying a string named "Hello World".



example:-

import java.lang.*; // Java defaultly import this package.

class hello //class name should be same as the file name you saved{
public static void main(String args[]){
System.out.println("Hello World");
}
}

Output:-











  • Let us elaborate this example, have a look at the very first line of program "import java.lang.*;". Java automatically import this package when ever you type your program. This package provides classes that are fundamental to the design of Java programming language, in this package the most important classes are object, which is the root of class hierarchy and class, instances of which represent classes at run time.
  • The second line of our program "class hello" which should be similar to the program file you created, because the JVM(Java Virtual Machine) compile your program based on the name of your class so it can give a similar byte code file".class". 
for example:-

  Output:-
In this example the compiler will generate the byte code but it won't be able to executed it and will give an error saying "Could find or load main class 'file name' " because the name of the file and class names are different.


  •  The third and the most important line to understand is "public static void main(String args[])".

Purpose of writing public to main()

          The main() is invoked  by JVM that stays outside the package of the class to which main() belongs. If main() is not declared as public then it won't be accessible outside the package and JVM cannot invoke it. Hence we wan't main() to be accessible outside package so it is declared as public

Purpose of writing static to main()

           If main() is not declared as static, then JVM will need to create  object main(). But since, main() is all entry point of Java program no objects are allowed to be created before main() is invoked. So we don not wan't main() to be invoked using object, hence it is declared as static. As to call static function object is not created.

Purpose of writing String args[]

           The "args[]" is an array whose type data type is String, in this array we can store various string arguments by invoking them at the command line for example:- myProgram Shaan Royal, then Shaan and Royal will be stored in the array as args[0] = "Shaan" and args[1] = "Royal". You can do this manually also inside the program, when don't call them at command line.


  •   The last line "System.out.println();" is an output statement, in which System is a class in the java.lang package. ".out" is a static member of System class, and is an instance of java.io.PrintStream, "println" is a method of java.io.PrintStream. This method is overloaded tom print message to output destination, which is typically a console or file.

Tuesday, 3 January 2017

Features of Java

  • Java has syntax similar to that of c,c++ making it easier of c, c++ programmers to learn
  • Java is platform independent i.e java programs compiled on one machine can be executed on any other machine having java environment.
  • Memory in java is automatically garbage collected by calling "System.gc()" function.
  • Java is fully object oriented programming language.
  • One of the most important feature of java is multi-threading, i.e each thread is a unit of execution and java can have multiple-thread which can be executed simultaneously("a thread is executed by CPU simultaneously and not by JVM").
  • Java is architecture-neutral, means if a java program is transferred  from one machine to another than change in OS,processor etc. won't force any change in java program.

Importance of learning Java programming language


  • Java is easy to learn for beginners.
  • Easier to maintain.
  • Java is object oriented programming language.
  • Java is platform independent.
  • Java is free.
  • Java has rich API.
  • Powerful development tools eg:- Eclipse, Netbeans, AndroidStudio.
  • Great collection of open source libraries.
  • Java is everywhere.
  • Excellent documentation support.         
  • 2nd most tagged language on GitHub.               

Monday, 2 January 2017

Introduction to Java



  • What is java?...  

                   Java is a programming language that evolved from a language named Oak. Oak was developed by Sun Microsystems in nineties as a platform independent  language aimed at allowing entertainment appliances such as video console and VCR's to communicate. It was originally
developed by "James Gosling" at Sun Microsystems and released in 1995 as a core component of Sun Microsystems Java platform.
James Gosling


                    The very first and most popular reason for learning java is that, it is platform independent. Now how Java is platform independent?. Since on every machine where java is installed creates an environment of it's own i.e creates a virtual machine on top of the underlying operating system. This virtual machine is called as JVM(Java Virtual Machine
                    
                    In java there is a JIT(Just In Time) compiler converts byte code to native machine code.
Hence a java program compiled on one machine can be executed on any another machine having java environment. So java is platform independent.

  • What is Byte Code in Java?
                   Byte code is the compiled form of java programs. Once java program is converted into byte code it can transferred over the network and can be executed on any another by Java Virtual Machine. Byte code files normally have a .class extension.

Java Working Diagram.
          
                      In this diagram it is clearly shown about the working of java. First a user understandable code is converted into byte code and then machine understandable code and finally it gets executed. Java can also be called as run time programming language.