Getting Started with Java

Add to Favourites
Post to:

Getting Started with JavaGetting Java Basics quickly has become easy with http://javapruthwirajk.blogspot.com/. This site is for the java programmers who want to use the Java programming language to create applications using the Java basics. This site is for absolute beginners to advanced java programmers who do not require any prerequisite Java knowledge. For getting started with Java you’ll have to have some basic understanding of the concepts of programming.After going through all the tutorials in this site, you would have learnt the essential concepts and features of the Java Programming Language which include exceptions, Swing GUI programming, Collections framework etc. A lot of code examples are used throughout tutorial to make you understand the language better.All the listings and programs in the website are compiled and run using the JDK 1.5.Download: JDK and JRE 1.5Java ArchitectureThe Java environment is composed of a number of system components. You use these components at compile time to create the Java program and at run time to execute the program. Java achieves its independence by creating programs designed to run on the Java Virtual Machine rather than any specific computer system.After you write a Java program, you use a compiler that reads the statements in the program and translates them into a machine independent format called bytecode.
Bytecode files, which are very compact, are easily transported through a distributed system like the Internet.The compiled Java code (resulting byte code) will be executed at run time.Java programs can be written and executed in two ways:Stand-alone application (A Java Swing Application)Applet which runs on a web browser (Example: Internet Explorer)Java source codeA Java program is a collection of one or more java classes. A Java source file can contain more than one class definition and has a .java extension. Each class definition in a source file is compiled into a separate class file. The name of this compiled file is comprised of the name of the class with .class as an extension. Before we proceed further in this section, I would recommend you to go through the ‘Basic Language Elements’.Below is a java sample code for the traditional Hello World program. Basically, the idea behind this Hello World program is to learn how to create a program, compile and run it. To create your java source code you can use any editor( Text pad/Edit plus are my favorites) or you can use an IDE like Eclipse.public class HelloWorld {public static void main(String[] args) {System.out.println("Hello World");}//End of main}//End of HelloWorld ClassOutputHello WorldABOUT THE PROGRAMI created a class named “HelloWorld” containing a simple main function within it. The keyword class specifies that we are defining a class. The name of a public class is spelled exactly as the name of the file (Case Sensitive). All java programs begin execution with the method named main(). main method that gets executed has the following signature : public static void main(String args[]).Declaring this method as public means that it is accessible from outside the class so that the JVM can find it when it looks for the program to start it. It is necessary that the method is declared with return type void (i.e. no arguments are returned from the method). The main method contains a String argument array that can contain the command line arguments. The brackets { and } mark the beginning and ending of the class. The program contains a line ‘System.out.println(”Hello World”);’ that tells the computer to print out on one line of text namely ‘Hello World’. The semi-colon ‘;’ ends the line of code. The double slashes ‘//’ are used for comments that can be used to describe what a source code is doing. Everything to the right of the slashes on the same line does not get compiled, as they are simply the comments in a program.Java Main method Declarationsclass MainExample1 {public static void main(String[] args) {}}class MainExample2 {public static void main(String []args) {}}class MainExample3 {public static void main(String args[]) {}}All the 3 valid main methods shown above accepts a single String array argument. Compiling and Running an ApplicationTo compile and run the program you need the JDK distributed by Sun Microsystems. The JDK contains documentation, examples, installation instructions, class libraries and packages, and tools. Download an editor like Textpad/EditPlus to type your code. You must save your source code with a .java extension. The name of the file must be the name of the public class contained in the file.Steps for saving, compiling and Running a JavaStep 1: Save the program With .java Extension.Step 2: Compile the file from DOS prompt by typing javac .Step 3: Successful Compilation, results in creation of .class containing byte codeStep 4: Execute the file by typing java Java Development KitThe Java Developer’s Kit is distributed by Sun Microsystems. The JDK contains documentation, examples, installation instructions, class libraries and packages, and toolsjavadocThe javadoc tool provided by Sun is used to produce documentation for an application or program,Jar FilesA jar file is used to group together related class files into a single file for more compact storage, distribution, and transmission.PATH and CLASSPATHThe following are the general programming errors, which I think every beginning java programmer would come across. Here is a solution on how to solve the problems when running on a Microsoft Windows Machine.1. ‘javac’ is not recognized as an internal or external command, operable program or batch fileWhen you get this error, you should conclude that your operating system cannot find the compiler (javac). To solve this error you need to set the PATH variable.How to set the PATH Variable?Firstly the PATH variable is set so that we can compile and execute programs from any directory without having to type the full path of the command. To set the PATH of jdk on your system (Windows XP), add the full path of the jdk\bin directory to the PATH variable. Set the PATH as follows on a Windows machine:a. Click Start > Right Click “My Computer” and click on “Properties”b. Click Advanced > Environment Variables.c. Add the location of bin folder of JDK installation for PATH in User Variables and System Variables. A typical value for PATH is:C:\jdk\bin (jdk Right Click “My Computer” and click on “Properties”b. Click Advanced > Environment Variables.Add the location of classes’ folder containing all your java classes in User Variables.If there are already some entries in the CLASSPATH variable then you must add a semicolon and then add the new value. The new class path takes effect in each new command prompt window you open after setting the CLASSPATH variable.Java 1.5The Java 1.5 released in September 2004.GoalsLess code complexityBetter readabilityMore compile-time type safetySome new functionality (generics, scanner)New FeaturesEnhanced for loopEnumerated typesAutoboxing & unboxingGeneric typesScannerVariable number of arguments (varargs)Static importsAnnotations

Description
This document will help you learn the basics of Java. It covers the Java Architecture and JDK.

This document also tells you the Compilation and Execution Process of Java Program.

I hope you will like this document and it will help you.

Any corrections and suggestions are always welcome.

Comments

Want to learn?

Sign up and browse through relevant courses.

Name:
Your Email:
Password:
Country:
Contact no:


Area code Number
Subjects you are interested in:
Word verification: (Enter the text as in image)


Sign Up Already a member? Sign In
I agree to WizIQ's User Agreement & Privacy Policy
Pruthwiraj Ghadge
Logic building is the Key to Programmming
User
42 Followers

Your Facebook Friends on WizIQ

Give live classes, create & sell online courses

Try it free Plans & Pricing

Connect