Chapter 2. Java Summary

Table of Contents

1. Compared to JavaScript, what is different in Java?
2. JavaBean Classes and Entity Classes

1. Compared to JavaScript, what is different in Java?

  1. No program without a class: Any Java program must include at least one class.

  2. No object without a class: For creating an object, a class has to be used (or defined) for

    • defining the properties of the object's property slots

    • defining the methods and functions that can be applied to the object (and all other objects instantiating the class)

  3. No global variables, no global methods: In Java, all variables and methods must be defined in the context of a class, which provides their name space.

  4. Classes, properties and methods are defined with a visibility level: public, protected or private.

  5. Java is strongly typed: Properties, parameters and variables must be declared to be of some type.

  6. Type parameters: Classes and complex data structures (such as lists) can be defined with the help of type parameters. See, for instance, this tutorial.

  7. Arrays are static: Arrays have a fixed size, which cannot be changed at run-time.

  8. Java programs must be compiled before they can be executed.

  9. Speed: Java is about twice as fast as optimized JavaScript.

In Java, visibility levels are used to define the possible levels of access:

Table 2.1. Java Visibility Level

Class Package Subclass World
public y y y y
protected y y y n
no modifier y y n n
private y n n n

Normally, properties are defined as private, with public getters and setters, so they are only directly accessible at the level of the class defining them.