Presentation is loading. Please wait.

Presentation is loading. Please wait.

Sadegh Aliakbary Sharif University of Technology Fall 2010.

Similar presentations


Presentation on theme: "Sadegh Aliakbary Sharif University of Technology Fall 2010."— Presentation transcript:

1 Sadegh Aliakbary Sharif University of Technology Fall 2010

2 Agenda Method Call Call by value & reference Variable argument lists For each Packages Fall 2010Sharif University of Technology2

3 Parameter Passing Call by value Call by reference Java style : Call by passing value of references! Let’s see! Fall 2010Sharif University of Technology3

4 What happens in a method call Fall 2010Sharif University of Technology4

5 Swap Fall 2010Sharif University of Technology5

6 Swap (2) Fall 2010Sharif University of Technology6

7 Call by reference in C++ Fall 2010Sharif University of Technology7

8 Call by reference in C# Fall 2010Sharif University of Technology8

9 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

10 Fall 2010Sharif University of Technology10

11 For Each Fall 2010Sharif University of Technology11

12 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

13 Quiz! Fall 2010Sharif University of Technology13

14 Fall 2010Sharif University of Technology14

15 Variable argument lists Fall 2010Sharif University of Technology15

16 Variable argument lists Called as vararg in C++ Varargs are actually arrays Fall 2010Sharif University of Technology16

17 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

18 Some famous java packages java.util java.lang java.io Fall 2010Sharif University of Technology18

19 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

20 Write a packaged java project Lets write … Fall 2010Sharif University of Technology20

21 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

22 Exceptions Fall 2010Sharif University of Technology22

23 Fall 2010Sharif University of Technology23


Download ppt "Sadegh Aliakbary Sharif University of Technology Fall 2010."

Similar presentations


Ads by Google