Programming language Java
Java as a programming language promising a lot of new facilities for junior and senior programmers. This tutorial will take you know more about this language through a discussion of the concept model of the design and use simple instructions.
Is Java?
Java is an object oriented programming language developed by Sun Microsystems in 1991. The language was developed with a model that is similar to language C ++ and Smalltalk, but is designed to be easier to use, and platform independent, which can run on different types of operating systems and computer architecture. The language is also designed for programming on the Internet that is designed to be secure and portable.
Platform independent means that programs written in Java can be easily transferred between different types of operating systems and various types of computer architectures. This aspect is very important in order to achieve the goal of Java as a programming language of the Internet where a program will be run by various types of computers with different types of operating systems. These properties apply to the level of source code and binary code from Java programs. Unlike the C and C ++ language, all data types in the Java language has a size that is consistent across all types of platforms. Source code Java program itself does not need to be changed at all if you want to recompile on other platforms. Results of compile Java source code is not machine code or processor instructions that are specific to a particular machine, but rather in the form of bytecode form .class file extension. You can direct bytecode execution on each platform using the Java Virtual Machine (JVM) as an interpreter for the bytecode.
In addition to the compiler and interpreter, the Java language itself has a fairly large library that can facilitate you in making an application quickly. This library already includes for graphics, user interface design, cryptography, network, sound, databases, and others.
Java is an object oriented programming language. Explicitly object-oriented programming is a technique for organizing the program and can be done with almost any programming language. But Java itself has implemented various facilities so that a programmer can optimize the object-oriented programming techniques.
Little additional comparison with C and C ++, Java inherits many object-oriented concepts of C ++, but by eliminating aspects of complexity in C ++ without reducing its strength. It is easier for beginners to learn Java programmers, but reduces the flexibility of programmers experienced in tinkering with a program. Behind the conveniences offered Java, the extent of its own Java library facilities to make a programmer needs a short time to be able to master the use of libraries.
To create Java programs, as has been mentioned before, you need JDK. JDK installation process is very easy and does not require any particular knowledge. However, to use it you need to make some adjustments to your operating system. Generally you need to do is enter the path to your JDK directory path to the settings in your operating system. Suppose your JDK directory is C: \ JDK1.4 then on Windows 98 you can simply add the command line SET PATH = C: \ JDK1.4 \ bin in your autoexec.bat file. For Windows NT / 2000 / XP you can simply add the directory C: \ JDK1.4 \ bin to the path variable in the System Environment. The trick: right-click the My Computer icon, select Properties. Then select the Advanced tab. Then click the Environment Variables button, find the path variable, and then add your JDK directory path into the variable. For Linux, add the command line SET CLASSPATH = (your JDK directory) file to your profile. To try JDK, type the command java and javac at the shell prompt (or DOS Command Prompt). If the command has been recognized, the program will display a java or javac syntax usage. For convenience and additional facilities you can use the Integrated Development Environment (IDE) for Java languages such as Visual Café from Symantec or JBuilder from Borland.
The sequence of steps you have to do to create a simple Java program are:
- Make the source code with any text editor program. Remember, the file must be with extension .java and case sensitive.
- Compile the source code with the command javac. For example: javac HelloWorld.java. If successful, the result is the ending .class bytecode files.
- Executes bytecode with the java command. The parameter of this command is the file name without the extension .class compilation. Example: java HelloWorld.
Here's the code for HelloWorld.java:
public class HelloWorld
{
public static void main (String [] args)
{
System.out.println ("What the World news?");
}
}
And this is another example, which is a simple applet to display text in the applet. Call this file is named HelloWorldApplet.java:
java.awt.Graphics import;
public class extends HelloWorldApplet java.applet.Applet
{
public void paint (Graphics g)
{
g.drawString ("Apa Kabar World?", 5, 25);
}
}
After both files saved with name HelloWorld.java and HelloWorldApplet.java, we will compile both programs with the command:
prompt> javac HelloWorld.java
prompt> javac HelloWorldApplet.jav
Have finished discussing the basic syntax of Java in both the listing, then we will try to execute the program. For the first program in the form of regular applications, we just type HelloWorld java command at the prompt and messages What World News? will appear on the screen (or possibly elsewhere, depending on your operating system). As for the applet we must create an HTML file as a wrapper-or callers. The following example is given to wrap applet HTML file that we created.
<HTML>
<HEAD>
<TITLE> Try Applet </ TITLE>
</ HEAD>
<BODY>
<APPLET CODE = "HelloWorldApplet.class" WIDTH = 150 HEIGHT = 25>
</ APPLET>
</ BODY>
</ HTML>