Java Is a Strongly Typed Language
on May 30, 2018
Java Is a Strongly Typed Language
It is important to state at the outset that Java is a strongly typed language. Indeed, part
of Java’s safety and robustness comes from this fact. Let’s see what this means. First, every
variable has a type, every expression has a type, and every type is strictly defined. Second,
all assignments, whether explicit or via parameter passing in method calls, are checked
for type compatibility. There are no automatic coercions or conversions of conflicting
types as in some languages. The Java compiler checks all expressions and parameters
to ensure that the types are compatible. Any type mismatches are errors that must be
corrected before the compiler will finish compiling the class.
If you come from a C or C++ background, keep in mind that Java is more strictly typed
than either language. For example, in C/C++ you can assign a floating-point value to
an integer. In Java, you cannot. Also, in C there is not necessarily strong type-checking
between a parameter and an argument. In Java, there is. You might find Java’s strong
type-checking a bit tedious at first. But remember, in the long run it will help reduce the
possibility of errors in your code.
0 comments: