Sadegh Aliakbary Sharif University of Technology Fall 2010
Agenda Method Call Call by value & reference Variable argument lists For each Packages Fall 2010Sharif University of Technology2
Parameter Passing Call by value Call by reference Java style : Call by passing value of references! Let’s see! Fall 2010Sharif University of Technology3
What happens in a method call Fall 2010Sharif University of Technology4
Swap Fall 2010Sharif University of Technology5
Swap (2) Fall 2010Sharif University of Technology6
Call by reference in C++ Fall 2010Sharif University of Technology7
Call by reference in C# Fall 2010Sharif University of Technology8
In java Everything is passed by value Primitive-types are passed by value References are passed by value If you want to pass something by reference… Wrap it in an object Fall 2010Sharif University of Technology9
Fall 2010Sharif University of Technology10
For Each Fall 2010Sharif University of Technology11
For Each (2) In for each expression, each element is assigned to another variable If X is a primitive type, element values are copied into item variable Fall 2010Sharif University of Technology12
Quiz! Fall 2010Sharif University of Technology13
Fall 2010Sharif University of Technology14
Variable argument lists Fall 2010Sharif University of Technology15
Variable argument lists Called as vararg in C++ Varargs are actually arrays Fall 2010Sharif University of Technology16
Package A package contains a group of classes Organized together under a single namespace Packages organize classes belonging to the same category or providing similar functionality A package provides a unique namespace for the types it contains Classes in one package has the same folder Packages may contain other packages Hierarchy of packages Fall 2010Sharif University of Technology17
Some famous java packages java.util java.lang java.io Fall 2010Sharif University of Technology18
Java Packages import keyword Class Qualified Name = package-name + class-name For example java.lang.String java.lang.Math double sqrt = Math.sqrt(123); java.util.Scanner java.awt.Event org.w3c.dom.events.Event Fall 2010Sharif University of Technology19
Write a packaged java project Lets write … Fall 2010Sharif University of Technology20
Package Access Remember public and private access specifiers The default access has no keyword It is commonly referred to as package access and sometimes friendly Other classes in the current package have access to that member To classes outside of this package, the member appears to be private. Fall 2010Sharif University of Technology21
Exceptions Fall 2010Sharif University of Technology22
Fall 2010Sharif University of Technology23