Java Programming Language | Part 2

Java Programming Language | Part 2

Java Programming Language — Platform Independence

The platform independence means that the execution of programs written in Java must have a similar behavior on different hardware. In principle, you should be able to write the program once and run it anywhere (hence the famous slogan of Sun’s “write once, run everywhere”). This is possible with the compilation of Java code into an intermediate language called bytecode, which is based on simplified instructions that follow the machine language. The bytecode is then executed by a virtual machine. In addition, standardized libraries are provided to allow access to the machine characteristics (such as graphics and networking) in a unified way. The Java language includes support for multithreaded programs, necessary for many applications that use the network.

Portability is a technically difficult goal to achieve, and the success of Java in this area is a matter of some controversy. Although it is indeed possible to write Java programs that behave consistently across many different hardware platforms, then we must remember that these are dependent on virtual machines that are, in turn, the programs themselves and that they inevitably have their bugs, other each other: this is a parody of the slogan created by Sun “Write once, run anywhere” (“write once, run everywhere”), which became “Write once, debug everywhere you” (” write once, debug anywhere “).

Just-In-Time compilation

The first implementations of the language used a Java virtual machine (known as JVM or Java Virtual Machine) that interpreted bytecode for maximum portability, defined Neutral Architecture. This solution has proved inefficient, however, interpreted as the programs were very slow. For this reason, all recent implementations of Java virtual machines have a built-just-in-time compiler (JIT compiler), that is an internal compiler, which translates to at launch flight program in a normal Java bytecode into machine language program the host computer. Moreover, this recompilation is dynamic, ie constantly analyzes the virtual machine execution model code (profiling), and further optimize the parts most frequently performed while the program is running.

These devices, at the cost of a small waiting in the launch phase of the program, allow for Java applications much faster and lighter. However, even so, Java is a language less efficient languages properly compiled as C + +, reflecting the fact that they have layers of abstraction, and implement a series of automated, as the garbage collector, that while they save time and errors in development programs, other consume memory and CPU time to run the finished program.

Secure remote code execution

The Java platform was one of the first systems to provide broad support for running code from remote sources. A Java applet is a special type of application that can be launched within the user’s browser, executing code downloaded from a remote Web server. This code runs in area (sandbox) highly restricted, which protects the user from the possibility that the code is malicious or has an undesired behavior, who publishes the code can be applied using a certificate to digitally sign applets declaring ” safe “, giving them permission to exit the restricted access to the file system and the network, presumably with the approval and under user control. In reality, applets have not had much luck. Presupposes that the client where they are performed has the JRE installed (must run the applet code). Have had no luck applications involving the so-called thin-client, that client ‘light’ that does not need special tools to perform remote code (sometimes you only need the browser).

Other aspects of interest

Compared to traditional object-oriented languages from which (particularly compared to its direct ancestor, the C + +), Java has introduced a series of significant change with respect to the extension of its semantics. Among the most significant is likely to include the ability to build GUI (graphic user interfaces) with standard tools and not using proprietary packages java.awt and javax.swing (for C + + and other languages typically similar GUIs are not part of language, but they are delegated to external libraries), the ability to create multi-threaded applications, or performing multiple activities concurrently, and support for reflection, the ability of a program to act on its structure and use of dynamically loaded classes outside.

Among the subjects who appear often in favor of Java in the choice of implementation language of a modern software project, also, it must certainly count the vast library for which language has, and in particular contribute to make highly integrated with other technologies. Some examples of library facilities of Java are:

  • Access to databases via JDBC and ODBC drivers with the DBMS through the JDBC-ODBC bridge
  • Handling XML documents
  • Dialogue with CORBA platforms
  • Powerful tools for server side programming in the context of Web
  • Native support for most IP family of protocols, see for example the Java Socket
  • Support for multimedia applications, streaming audio and video.

Java Language

Hello, world!

The following example prints the text “Hello world”:

public class HelloWorld
(
public static void main (String [] args)
(
System.out.println (“Hello World”);
)
)

Follows line by line analysis of the code snippet:

* Public class HelloWorld

The class named HelloWorld, and it is declared “public” means that the file name will be written in which the program should call Helloworld.java. So the name of file.java and the class name “public” must match.

* Public static void main (String [] args)

The HelloWorld class contains one method, called “main”. It is a special name. Indeed, loading the class, the Java interpreter will try the method that will bear this name or is the ‘entry point of the program.

* “Public” because the method has to be accessible from any class, in particular, by the same interpreter.
* “Static” because it should not be relied on a particular object (called “invocation”).
* “Void” because it does not return any value.

Study: From Wikipedia, the free encyclopedia. The text is available under the Creative Commons.
To be continued.

Sharing