180 likes | 303 Views
Advanced Programming in Java. Sadegh Aliakbary Sharif University of Technology Fall 2010. Agenda. Type Checking Type Casting Type Conversion toString () method equals() method . Type Safety. The Java language is designed to enforce type safety
E N D
Advanced Programming in Java SadeghAliakbary Sharif University of Technology Fall 2010
Agenda • Type Checking • Type Casting • Type Conversion • toString() method • equals() method Sharif University of Technology
Type Safety • The Java language is designed to enforce type safety • Accessing memory in inappropriate ways is banned • Every piece of memory is part of some Java object • Each object has some class • Because of • No Pointer • Strong Type Checking Sharif University of Technology
Java Type Checking • Java has a strong type checking mechanism Sharif University of Technology
Primitive Types Sharif University of Technology
Type Checking Special Cases • Reference-type to primitive type and vise versa Sharif University of Technology
Type Checking in Method Calls Sharif University of Technology
Type Casting • You can change the type by type casting • Casting in reference types and other objects is not so simple • See it later Sharif University of Technology
Type Conversion • Sometimes we want to convert an object to another type • Type casting is not the solution here • We should write some methods to convert the types Sharif University of Technology
Type Conversion (2) Sharif University of Technology
toString • toString() is a special method • You can write it for every class Sharif University of Technology
Checking equality in java Sharif University of Technology
equals method Sharif University of Technology
Parameter Passing • Call by value • Call by reference • Java style : Call by passing value of references! • Let’s see! Sharif University of Technology
Quiz! • Write a java class for representing … Sharif University of Technology