Thursday, August 8, 2013

Getting Started with Java JDK (Java Development Kit)

Part 2  Start with part 1 is very understand

Introduction Fundamentals of Java quickly became easier with Intecs. This site is for Java programmers who want to use the Java programming language to create applications using the basics of Java. This site is for beginners and for advanced Java programmers that do not require prerequisite knowledge of Java. To start using Java you must have a basic understanding of programming concepts.



After going through all the tutorials on this site, you should learn the basic concepts and features of the Java programming language, including exceptions, swing GUI programming, under Collections etc. A lot of code examples used throughout exercise to better understand the language.
All advertisements and programs on this site are compiled and run with JDK .

Download : JDK and JRE 

Java Architecture

The Java environment consists of a number of system components. You can use these components at compile time to create the Java program at runtime to execute the program. Java achieves its independence with the creation of programs designed to run on the Java virtual machine, rather than any specific computer system.

  • After writing a Java program, you are using a compiler that reads the instructions in the program and translated into a machine-independent format called bytecode.
  • Bytecode files, which are very compact, easily transported through a distributed system such as the Internet.
  • The compiled Java code (code resulting byte) will be executed at run time.

Java programs can be written and executed in two ways:

  • Stand-alone application (a Java Swing)
  • Applet that runs in a web browser (eg Internet Explorer)



Java source code

A Java program is a set of one or more Java classes. A Java source file can contain more than one class definition and has an extension of Java .. Each class definition in the source file is compiled into a separate class file. The name of the compiled file consists of the name of the class. Class as an extension. Before proceeding further in this section, I suggest you go through the "basic elements of the following languages.

Below is an example of Java code for the traditional Hello World program. In essence, the idea behind this Hello World program is to learn how to create a program, compile and run. To create the Java source code you can use any editor (pad / Edit Plus text are my favorite), 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 Class

Output
Hello World

Program information

I have created a class called "HelloWorld," which contains a simple main function within it. The class keyword specifies that we are defining a class. The name of a public class is written exactly the file name (case sensitive). All java programs begin execution with a method called main (). main execution method has the following signature: void main (String args []) public static declare this method as public transport which is accessible from outside the class to the JVM when trying to find the program to start. her. And 'necessary that the method is declared with a void return type (ie, no arguments are returned by the method). The main method contains an array of string arguments that can contain the command line arguments. The braces {and} mark the beginning and the end of the class. The program contains "System.out.println (" Hello "); 'a line that tells the computer to print a line of text to say,' Hello World 'The semicolon.'; 'End the line of code.' s double slashes '/ comments /' are used which can be used to describe what he is doing a source code. All right of the bars in the same line is not filled in, as they are only comments in a program.

Java Main method statements

class MainExample1 {public static void main(String[] args) {}}
class MainExample2 {public static void main(String []args) {}}
class MainExample3 {public static void main(String args[]) {}}

They are all 3 main valid method shown above takes a single argument array of strings.

Compile and run an application

To 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 instruments. Download editor like Textpad / EditPlus to write the code. You need to keep the source code, with an extension of Java .. The file name must be the name of the public class in the file.

Steps to follow to save, compile and run a Java application

Step 1:Save the program With .java Extension.
Step 2:Compile the file from DOS prompt by typing javac <filename>.
Step 3:Successful Compilation, results in creation of .class containing byte code
Step 4:Execute the file by typing java <filename without extension>


Java Development Kit

Java Developer Kit is distributed by Sun Microsystems. The JDK contains documentation, examples, installation instructions, class libraries and packages and tools

javadoc

The javadoc tool provided by Sun is used to produce the documentation of an application or a program,


Jar files

A JAR file is used to group related class files into a single file for more compact storage, distribution and transmission.


PATH and CLASSPATH

The following are general programming errors, which I think every beginning java programmer find. Here's a solution on how to solve problems when running on a Windows machine.

1. "Javac 'is not recognized as an internal or external command, program or batch file

When you get this error, you must conclude that the operating system can not find the compiler (javac). To resolve this error, you must set the PATH variable.

How to set the PATH variable?

First, the PATH variable is set so that you can compile and run programs from any directory without having to type the full path of the command. To set the path to the JDK on your system (Windows XP), add the full path to the JDK <version> \ bin to the PATH variable. Set the path follows on a Windows computer:

un. Click Start> Click on "My Computer" and click "Properties"
b. Variables Click Advanced> Environment.
c. Add the location of bin folder of JDK installation for PATH in User Variables and System Variables. A typical value for the path is:

C:\jdk<version>\bin (JDK <version is just the name of the directory where you installed the JDK)

If there is already some elements of the PATH variable should add a semicolon and then add the previous value (version is replaced with the version of the JDK). The new path takes effect in each new Command Prompt window you open after setting the PATH variable.


2. Exception in thread “main” java.lang.NoClassDefFoundError: HelloWorld

If you receive this error, Java can not find the file compiled bytecode, HelloWorld.class.If both class files and source code are in the same working directory, and if you try to run the program from the current working directory that the program should run smoothly as, try to find the Java class file. represents the current directory. If the class files are present in another directory than the java file we need to set the CLASSPATH pointing to the directory containing the compiled class files.CLASSPATH can be adjusted as follows on a Windows computer:

a. Click Start > Right Click “My Computer” and click on “Properties”
b. Click Advanced > Environment Variables.

Add the location of the folder class' that contains all Java classes in the user variables.

If there are already some items in your CLASSPATH must add a semicolon and then add the new value. The new classpath takes effect in each new Command Prompt window you open after setting the classpath.



SHARE THIS

Author:

Facebook Comment

0 comments: