JAVA TUTORIAL

 
     

3.CHARACTERISTICS OF JAVA

 
 

I'm sure that you have eared a lot of things about Java™. Here you have a brief relaction of some of this things. Some of the characteristics that we describe here, were extracted from a White Paper where the Java™ developers explains their desing goals and accomplishments. In spite of that paper is organized along eleven buzzwords, we make reference here to only six of that buzzwords. Here you have the relaction of them :

Simple Portable
Object Oriented Interpreted
Distributed High Performance
Robust Multithreaded
Secure Dynamic
Architecture Neutral

Search the White Paper at http://java.sun.com/docs/white/index.html

 
       

3.1.DESCRIPTION OF FEATURES

     
   

Java™ is simple

We wanted to build a system that could be programmed easily without a lot of esoteric training and which leveraged today's standard practice.

Java™, which is one of the most modern programming languages, is a mixture of many other programming languages (C, C++, LISP, Objective-C, MESA, Modula3...). Specially, the syntax in Java™ is very similar to C and C++, but Java™ is too much simple than these languages (later we'll see the differences between Java™ and C++). This simplicity, with the fact that Java™ is an strongly tiped language, makes Java a powerful programming language.

Java™ is robust

Java is intended for writing programs that must be reliable in a variety of ways. Java puts a lot of emphasis on early checking for possible problems, later dynamic (run-time) checking, and eliminating situations that are error-prone.... The single biggest difference between Java and C/C++ is that Java has a pointer model that eliminates the possibility of overwriting memory and corrupting data.

Some of these differences, make Java™ a very robust programming language. For example, Java don't allows multiple inheritance, it haven't pointers which are a source of continuous mistakes and it's a strongly-tiped programming language. For these and too many others things programers from all around the world can say that Java™ is a very robust language.

Java™ is an Object-Oriented Programming Language

Simply stated, object-oriented design is a technique for programming that focuses on the data (=objects) and on the interfaces to that object. To make an analogy with carpentry, an "object-oriented" carpenter would be mostly concerned with the chair he was building, and secondarily with the tools used to make it; a "non-object-oriented" carpenter would think primarily of his tools. The object-oriented facilities of Java are essentially those of C++.

Maybe you don't know yet how is the Object-Oriented Programming and maybe you are worried for this. Don't worry. You probably know already the structured programming. If you think a bit about the model of structured programming, you'll see that it's not the same model that we use naturally to organize the information in our sense. The OOP (Object-Oriented Programming) tries to use in programming, the same model which our sense uses. So, you will learn rapidly how to use this way of programming.

The OOP has only one difficulty: you have to learn some new concept based in a special object-oriented terminology. So, you will ear words like object, class, instance... and you will ear that OOP has based on three major properties: encapsulation, polymorphism and inheritance. You will learn more about this along this tutorial.

Java™ is portable (because is both compiled and interpreted)

...Unlike C and C++, there are no "implementation-dependent" aspects of the specification. The sizes of the primitive data types are specified, as is the behavior of arithmetic on them...

... The Java interpreter can execute Java bytecodes directly on any machine to which the interpreter has been ported. Since linking is a more incremental and lightweight process, the development process can be much more rapid and exploratory...

While most programming languages you have only to compile or interpret a program to can run it on your computer, the Java™ way to do this is very different. Java™ is both compiled and interpreted and this is the difference that allows that portability.

You need two steps to execute a Java™ program:

  1. Using the compiler, you translate the source code of a program into an interpreted language called Java bytecodes.
  2. Using the interpreter of the Java platform, you can finally execute this program.

The difference between Java™ and other languages which allows Java™ to be portable is in that first step and in that bytecodes. The bytecodes can be interpreted on the Java platform of a any one computer. When you find, for example, a Java™ applet on a web page, you are downloading a bytecode file that the Java Virtual Machine (JVM), which is installed on your computer, is executing.

Java™ is secure

Java is intended to be used in networked/distributed enviroments. Toward that end, a lot of emphasis has been placed on security. Java enables the construction of virus-free, tamper-free systems.

Here you have some points which tries to guarantee the applets security in Java:

  • Language and compiler : All the references to memory are symbolic references (you can't know where in the memory will stay your program, it only depends of the JVM and of each machine).
  • Bytecodes checker : On the Java Virtual Machine the bytecodes code is checked to confirm that it was compiled on an standard compiler.
  • Classes loader : Each applet is loaded on its own memory space, to make impossible the information interchange between applets.
  • Security on applets : The programmer can configure his communications with a certain degree of security.

Java™ is multithreaded

... (the) benefits of multithreading are better interactive responsiveness and real-time behavior.

A good way to prevent your Java programs from locking up is to use multithreading, which simply means you write a program that enables multiple execution streams to occur simultaneously within the same program

Threads are rapidly becoming an important programming facility, particularly for Internet-related applications. They permit a form of parallelism within a single program that can greatly improve program performance. For instance, the Netscape 3.0 browser and its posterior versions permits the user to download a file while continuing to browse the WWW, an example of multiple threads within a program.

Using multiple threads in Java programs is far easier than in C or C++ because of the language-level support offered by the Java programming language.

 
       

3.2.DIFFERENCES BETWEEN JAVA AND JAVASCRIPT

 
   

Most people thinks that Java™ and JavaScript are the same thing, but they are wronged. See here what are the differences between these two languages:

JavaScript
Java
Object-based. Code uses built-in, extensible objects, but no classes or inheritance. Object-oriented. Applets consist of object classes with inheritance.
Interpreted (not compiled) by client. Compiled on server before execution on client.
Code integrated with, and embedded in, HTML. Applets distinct from HTML (accesed from HTML pages).
Variable data types not declared (loose typing). Variable data types must be declared (strong typing).
Dynamic binding. Object references checked at run-time. Static binding. Object references must exist at compile-time.
 
       

3.3.DIFFERENCES BETWEEN JAVA AND C++

 
   

...we found that C++ was unsuitable, we designed Java as closely to C++ as posible in order to make the system more comprehensible. Java omits many rarely used, poorly understood, confusing features of C++ that, in our experience, bring more grief than benefit...

...The object-oriented facilities of Java are essentially those of C++....

...The single biggest difference between Java and C/C++ is that Java has a pointer model that eliminates the possibility of overwriting memory and corrupting data...

...In a number of ways, Java is a more dynamic language than C or C++. It was designed to adapt to an envolving enviroment...

In a first contact, Java™ seems like C++, and it's logical because how we have said Java™ takes the C and C++ syntax. Java™ have nevertheless some important differences with C++. For instance, you can't use pointers in Java™, neither operators overload, neither multiple inheritance, neither predefined types. These features of C++ that Java doesn't has, make it a simplest and more robust language. Interpreted Java™ is furthermore slowly than C++ (even 20 to 50 times slower than C in the original Java interpreters).

Main differences between Java™, C and C++

    Memory administration:
    Java memory administration is automatic; memory is assigned automatically when you creat an object, and also a garbage collector frees the memory when that object is no used.
    Functions malloc() and free() don't exist in Java.

    Tipe of data:
    Primitive Java data (like char, int, long...) have sizes and behaviors which consist in some platforms and operative systems. In Java language, don't exist unsigned data.
    The boolean data has two values in Java : true and false. So it isn't an integer type, but you can force "0" and "1" (which are integers) to be booleans.

    Operators:
    The execution order of the operators is the same as in C. But, for example, the special word new (to create a new object) is linked in a more narrow form than point notation (.), which has another behavior in C++.

    Flux Control:
    The syntax of the following statements if, while, for and do is the same as in C and C++. But there is an important difference : the proof expression for each flux construction should return a boolean value (true or false). In C and C++, the expression can return an integer.

    Arguments:
    In Java all method definitions have to have an specific number of arguments.
    The arguments in the command line have a different behavior than in C and C++. So, in this languages argv[0] is the name of the program but in Java this is the first of additionals arguments.