Syntax
The syntax of Java is largely derived from C++. Unlike C++, which combines the syntax for structured, generic, and object-oriented programming, Java was built almost exclusively as an object-oriented language. All code is written inside a class, and everything is an object, with the exception of the primitive data types (e.g. integers, floating-point numbers, boolean values, and characters), which are not classes for performance reasons.
Unlike C++, Java does not support operator overloading or multiple inheritance for classes. This simplifies the language and aids in preventing potential errors and anti-pattern design.
Java uses similar commenting methods to C++. There are three different styles of comments: a single line style marked with two slashes (//
), a multiple line style opened with /*
and closed with */
, and the Javadoc commenting style opened with /**
and closed with */
. The Javadoc style of commenting allows the user to run the Javadoc executable to compile documentation for the program.
Example:
// This is an example of a single line comment using two slashes /* This is an example of a multiple line comment using the slash and asterisk. This type of comment can be used to hold a lot of information or deactivate code, but it is very important to remember to close the comment. */ /** * This is an example of a Javadoc comment; Javadoc can compile documentation * from this text. */Read more about this topic: Java (programming Language)