Introduction::
Java is a programming language that was developed by the sun microsystems in 1991.Its original name was Oak and later on was renamed to JAVA. It is the programming language having much of the syntax same as c and c++. Now before starting with the tutorial you must have java virtual machine which compiles source code into byte code.As byte code is platform independent this code can be run on various platforms i.e code compiled on windows can be run on linux platform.This makes Java highly portable language Now to install jvm(java virtual machine)you have to install jdk on your O.S.You can download this at www.java.sun.com/downloads.
Another important thing that is needed is an editor in which you write a code.Nowadays different editors and IDE's are available.Some of them are editplus,Jcreator,netbeans,eclipse etc.But you can also write code in notepad and save the file with ".java" extension.
Considering you know some amount of coding let start with our first example.
public class mainclass
{
public static void main(String args[])
{
System.out.println("HELLO Reader!!");
}
}
now following are the steps to compile if your path is set in command prompt then javac mainclass.java
--the above code wont show any errors java mainclass
Output of above program would be HELLO Reader!!
Now the file name should be the same as class name.
Following are some of the utilities of jdk as well as their description(short)
Tool                                                                                         Function
javac                                                                       The Java compiler. Converts Java source code into bytecodes.
java                                                                   The Java interpreter. Executes Java application bytecodes directly from class files. appletviewer                                                        A Java interpreter that executes Java applet classes hosted by HTML files.
javadoc                                                            Creates HTML documentation based on Java source code and the comments it contains. rmic                                                                   Creates class files that support Remote Method Invocation (RMI).
rmiregistry                                                            Registry used to gain access to RMI objects on a specific machine.
rmid                                                                 Activation system daemon for RMI object registration and activation.
native2ascii                                                    Special program used to convert between standard Latin-1 Unicode characters and                                                                                   other international encoding schemes.
jar                                                                       Java Archive (JAR) file generator. JAR files allow multiple Java classes and resources                                                                              to be distributed in one compressed file.
keytool                                                                    Used for security key generation and management. jarsigner Implements digital                                                                                      signing of JAR and class files. Allows applets to be certified by trusted authorities.
policytool                                                          Allows user-installation-level security policy configuration.
Done with this then data types that are used in c and c++ all are present in java except that of pointers and structures Here boolean datatype is also there string is an inbuilt data type.some other additions are date and calendar.
Again operators which we use in c and c++ are same here.
Control statement and looping statement are same as that of c and c++ with an addition of foreach loop foreach loop
(general form)code is as below
for(type itr-var : iterableObj) statement-block
public class MainClass
{
public static void main(String args[])
{
int nums[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
for(int x : nums)
{
System.out.print(x + " "); x = x * 10;
}
System.out.println();
for(int x : nums)
System.out.print(x + " ");
System.out.println();
}
}
here its an read only loop....which will print 1-10 2 times here is another example
import java.util.ArrayList;
public class MainClass
{
public static void main(String args[])
{ ArrayList list = new ArrayList();
list.add(10.14); list.add(20.22);
list.add(30.78); list.add(40.46);
double sum = 0.0;
for(double itr : list)
sum = sum + itr;
System.out.println(sum);
}
}
output of above code will be 101.6
let us end 1st part of tutorial.
I will be back with more examples and concept in next

Like it on Facebook, Tweet it or share this article on other bookmarking websites.

No comments