Presentation is loading. Please wait.

Presentation is loading. Please wait.

Copyright © 2012 Accenture All Rights Reserved.Copyright © 2012 Accenture All Rights Reserved. Accenture, its logo, and High Performance Delivered are.

Similar presentations


Presentation on theme: "Copyright © 2012 Accenture All Rights Reserved.Copyright © 2012 Accenture All Rights Reserved. Accenture, its logo, and High Performance Delivered are."— Presentation transcript:

1 Copyright © 2012 Accenture All Rights Reserved.Copyright © 2012 Accenture All Rights Reserved. Accenture, its logo, and High Performance Delivered are trademarks of Accenture. Application Delivery Fundamentals 2.0: Java Module 9: Object-Oriented Programming Classes and Objects Appendix

2 Copyright © 2012 Accenture All Rights Reserved. Mutable and Immutable Data Types: Objects All of the java.lang package wrapper classes are immutable: Boolean, Byte, Character, Double, Float, Integer, Long, Short, String. Mutable Objects Immutable Objects Contents of the instance can be altered Contents of the instance cannot be altered 2

3 Copyright © 2012 Accenture All Rights Reserved. Mutable and Immutable Data Types: Example Consider the code snippet below: Since String is immutable, it is represented in memory in the following manner: String str1 = “hello”; str1 = “HelloWorld” Heap Stack hello str1 100 HelloWorld 200 3

4 Copyright © 2012 Accenture All Rights Reserved. Mutable and Immutable Data Types: String Pool Consider the code snippet below: Since the content of both Strings is the same, it will be represented in memory in the following manner: String str1 = “hello”; String str2 = “hello”; str1 str2 hello 100 Heap Stack 4

5 Copyright © 2012 Accenture All Rights Reserved. Memory Management: Garbage Collection Special Case In special cases, despite Garbage Collection, memory leaks may still happen in Java. Programmers need to be aware of such cases and should use tools to detect and prevent the same. 5

6 Copyright © 2012 Accenture All Rights Reserved. OO Concepts: Creating a Package Sample Refer to the sample code: com.accenture.adf.newcodington.module10.sample. Codington.java i 6

7 Copyright © 2012 Accenture All Rights Reserved. OO Concepts: Methods Overview Methods define the operations that the instances of a class can perform. These operations form the behavior of objects of the class. Role of Methods The method code is loaded in the heap and the callstack is on stack. Method Loading 7

8 Copyright © 2012 Accenture All Rights Reserved. OO Concepts: Methods – Calling Method of Another Class Sample Refer to the sample code: com.accenture.adf.newcodington.module10.sample. Codington.java i 8

9 Copyright © 2012 Accenture All Rights Reserved. OO Concepts: Access Control Overview Public methods must ensure that modifications made to an object’s state adhere to the intended design of that object’s class. Adherence to design A class should not expose details of its implementation to other objects Hidden details A class should provide some public methods which can be used to call object’s implementation. Use of public methods 9

10 Copyright © 2012 Accenture All Rights Reserved. OO Concepts: Access Control – Access Modifiers Class Access modifiers define how a class can be accessed. Member Access modifiers define how a member (variable or method) can be accessed. ModifierDescription (no modifier)Class can only be accessed from same package. publicClass can be accessed from anywhere. ModifierDescription (no modifier)Member can be accessed within its package only. public Member can be accessed from any class of any package. protected Member is accessible in its class package and by its subclasses. privateMember is accessible only from its class. 10

11 Copyright © 2012 Accenture All Rights Reserved. OO Concepts: Member Variables – Example Class Event { String eventId; //This variable stores a unique id assigned to each event. } 11


Download ppt "Copyright © 2012 Accenture All Rights Reserved.Copyright © 2012 Accenture All Rights Reserved. Accenture, its logo, and High Performance Delivered are."

Similar presentations


Ads by Google