|
|
|
|
|||
|
The SCJP Handbook |
In the last chapter, we learned how Java operators are used to manipulate variables (for ex. increment them, shift their bits, compare them with one another etc). Often when you manipulate a variable, you are not only changing its value, but also changing its type. Sometimes these type changes are done implicitly by Java and hence you may not even realize it. However sometimes you may be explicitly doing it with the cast operator. It is important to note that “Java is a strongly typed language”. It gives a lot of importance to type and so should you. Java imposes numerous compile-time and runtime checks to ensure that type changes are appropriate. You need to be aware of how these types change, which changes are allowed and what are the implications (of type change). If you are not, it is very likely that your code will fail to compile and even if it compiles, it is likely to fail at run time.
The exam expects you to know about the implicit type changes. It also expects you to know where you need to do an explicit type change. This chapter discusses how the type changes during the conversion, casting and promotion of types. You will learn when a type change is automatic and where you need to do it explicitly. By the end of the chapter, you should be able to look at the code and tell whether it compiles as it is, needs a type change or whether it would compile but fail at runtime. The exam expects that level of dexterity from you when it comes to the type and type changes. Specifically this chapter covers 5.1 (partially) and 5.4 and 1.4 sections of SCJP objectives.