انت هنا الان : شبكة جامعة بابل > موقع الكلية > نظام التعليم الالكتروني > مشاهدة المحاضرة

Type Checking in Java

Share |
الكلية كلية تكنولوجيا المعلومات     القسم قسم شبكات المعلومات     المرحلة 3
أستاذ المادة مهدي عبادي مانع الموسوي       13/11/2018 12:07:16
Type Checking
Java is a strongly types language, which means that the Java compiler checks the code to ensure that every assignment and every call is type correct. If a type error is discovered, compilation fails with an error message.
Type checking depends on the fact that every variable declaration gives the type checking of the variable, and the header of every method and constructor defines its signature: the types of its arguments and results (and also the types of any exceptions it throws).
This information allows the compiler to deduce an apparent type for any expression and this deduction then allows it to determine the legality of an assignment
For example consider
int y= 7;
int z= 3;
int x= num.gcd (z,y); // discuss that

When the compiler processes the call to Num.gcd, it knows that the Num.gcd requires two integer arguments and it also knows that expressions z and y are both of type int. therefore; it knows the call of gcd is legal. Furthermore it knows that gcd returns an int and therefore it knows that the assignment to x is legal.
Note Java has an important property: legal Java programs (that is, those accepted by the compiler) are guaranteed to be type safe. This mean that there cannot by any type errors when the program runs.
Java types are organized into a hierarchy in which a type can have a number of supertypes , we say the type is a subtype of each its supertype (other texts may use the term superclass and subclass)


المادة المعروضة اعلاه هي مدخل الى المحاضرة المرفوعة بواسطة استاذ(ة) المادة . وقد تبدو لك غير متكاملة . حيث يضع استاذ المادة في بعض الاحيان فقط الجزء الاول من المحاضرة من اجل الاطلاع على ما ستقوم بتحميله لاحقا . في نظام التعليم الالكتروني نوفر هذه الخدمة لكي نبقيك على اطلاع حول محتوى الملف الذي ستقوم بتحميله .
الرجوع الى لوحة التحكم