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

Slides:



Advertisements
Similar presentations
STRING AN EXAMPLE OF REFERENCE DATA TYPE. 2 Primitive Data Types  The eight Java primitive data types are:  byte  short  int  long  float  double.
Advertisements

Fields, Constructors, Methods
Basic Classes Subclasses and Inheritance By Greg Butler.
Java™ How to Program, 9/e © Copyright by Pearson Education, Inc. All Rights Reserved.
Written by: Dr. JJ Shepherd
CSCI 1100/1202 April 3, Testing A program should be executed multiple times with various input in an attempt to find errors Debugging is the process.
George Blank University Lecturer. CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 4.
© Copyright 2012 by Pearson Education, Inc. All Rights Reserved. 1 Chapter 7 Object-Oriented Programming.
Applying OO Concepts Using Java. In this class, we will cover: Overriding a method Overloading a method Constructors Mutator and accessor methods The.
CPS 108 : Spring From C++ to Java l Java history: Oak, toaster-ovens, internet language, panacea  Not really a standard language like C++  Arguably.
3.1 Documentation & Java Language Elements Purpose of documentation Assist the programmer with developing the program Assist other programers who.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
Java Programming, Second Edition Chapter Four Advanced Object Concepts.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
CIS Computer Programming Logic
Created by, Author Name, School Name—State FLUENCY WITH INFORMATION TECNOLOGY Skills, Concepts, and Capabilities.
CSC 212 Object-Oriented Programming and Java Part 1.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
Java 2 More Java Then Starbucks ;-). Important Terms Primitive Data – Basic, built-in values (characters & numbers) Data Type – Used to talk about values.
Outline Character Strings Variables and Assignment Primitive Data Types Expressions Data Conversion Interactive Programs Graphics Applets Drawing Shapes.
Java Software Solutions Lewis and Loftus Chapter 4 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Objects and Classes -- Introduction.
Objects, Classes and Syntax Dr. Andrew Wallace PhD BEng(hons) EurIng
Generic Programming  Object Type  Autoboxing  Bag of Objects  JCL Collections  Nodes of Objects  Iterators.
Java Basics.  To checkout, use: svn co scb07f12/UTORid  Before starting coding always use: svn update.
SE-1010 Dr. Mark L. Hornick 1 Variables & Datatypes.
Copyright Curt Hill Variables What are they? Why do we need them?
CSCI 1100/1202 April 1-3, Program Development The creation of software involves four basic activities: –establishing the requirements –creating.
Java Basics Opening Discussion zWhat did we talk about last class? zWhat are the basic constructs in the programming languages you are familiar.
Introduction to Java Chapter 7 - Classes & Object-oriented Programming1 Chapter 7 Classes and Object-Oriented Programming.
Lecture 04 – Models of memory Mutable and immutable data.
Cs2220: Engineering Software Class 3: Java Semantics Fall 2010 University of Virginia David Evans.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 9 Java Fundamentals Objects/ClassesMethods Mon.
ISBN Object-Oriented Programming Chapter Chapter
Memory Management in Java Computer Science 3 Gerb Objective: Understand references to composite types in Java.
Copyright © 2012 Accenture All Rights Reserved.Copyright © 2012 Accenture All Rights Reserved. Accenture, its logo, and High Performance Delivered are.
Duke CPS From C++ to Java l Java history: Oak, toaster-ovens, internet language, panacea l What it is ä O-O language, not a hybrid (cf. C++)
Copyright © 2012 Accenture All Rights Reserved.Copyright © 2012 Accenture All Rights Reserved. Accenture, its logo, and High Performance Delivered are.
CSC 205 Java Programming II Introduction. Topics Syllabus Course goals and approach Review I Java language fundamentals.
In this class, we will cover: Overriding a method Overloading a method Constructors Mutator and accessor methods The import statement and using prewritten.
© 2006 Pearson Addison-Wesley. All rights reserved 1-1 Chapter 1 Review of Java Fundamentals.
5.1 Basics of defining and using classes A review of class and object definitions A class is a template or blueprint for an object A class defines.
Data Types References:  Data Type:  In computer science and computer programming, a data type or simply type is a.
Copyright © 2012 Accenture All Rights Reserved.Copyright © 2012 Accenture All Rights Reserved. Accenture, its logo, and High Performance Delivered are.
Today Review passing by reference and pointers. null pointers. What is an Object? Winter 2016CMPE212 - Prof. McLeod1.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 10 Java Fundamentals Objects/ClassesMethods.
Objects and Memory Mehdi Einali Advanced Programming in Java 1.
Lecture 3: Introduction to Object and Classes Michael Hsu CSULA.
Objects and Classes. F OO Programming Concepts F Creating Objects and Object Reference Variables –Differences between primitive data type and object type.
Programming in Java: lecture 7
Creating and Using Objects, Exceptions, Strings
JAVA MULTIPLE CHOICE QUESTION.
objects CIS 421 Kutztown University
Chapter 4: Writing Classes
CMSC 202 Static Methods.
MSIS 655 Advanced Business Applications Programming
Unit-2 Objects and Classes
Chapter 10 Thinking in Objects
C Programming APP3o.
Object-Oriented Programming
Applying OO Concepts Using Java
Fall 2018 CISC124 2/22/2019 CISC124 Quiz 1 This Week. Topics and format of quiz in last Tuesday’s notes. The prof. (me!) will start grading the quiz.
Java Programming Review 1
Tutorial 10: Programming with javascript
Copyright © 2013 Elsevier Inc. All rights reserved.
Java Basics Data Types in Java.
Outline Creating Objects The String Class The Random and Math Classes
Chap 2. Identifiers, Keywords, and Types
Chapter 3 Introduction to Classes, Objects Methods and Strings
String Class.
Classes and Objects Object Creation
Presentation transcript:

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

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

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

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

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

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

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

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

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

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

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