Memory Management in Java Mr. Gerb Computer Science 4.

Slides:



Advertisements
Similar presentations
Chapter 5: The Singleton Pattern
Advertisements

Chapter 16 Java Virtual Machine. To compile a java program in Simple.java, enter javac Simple.java javac outputs Simple.class, a file that contains bytecode.
Dynamic Memory Allocation in C.  What is Memory What is Memory  Memory Allocation in C Memory Allocation in C  Difference b\w static memory allocation.
Constructor. 2 constructor The main use of constructors is to initialize objects. A constructor is a special member function, whose name is same as class.
Introduction to Memory Management. 2 General Structure of Run-Time Memory.
Chapter 6 Data Types
Portability and Safety Mahdi Milani Fard Dec, 2006 Java.
Various languages….  Could affect performance  Could affect reliability  Could affect language choice.
Memory allocation CSE 2451 Matt Boggus. sizeof The sizeof unary operator will return the number of bytes reserved for a variable or data type. Determine:
CIS 101: Computer Programming and Problem Solving Lecture 8 Usman Roshan Department of Computer Science NJIT.
Evan Korth New York University Computer Science I Classes and Objects Professor: Evan Korth New York University.
1 Programming Languages b Each type of CPU has its own specific machine language b But, writing programs in machine languages is cumbersome (too detailed)
Run-Time Storage Organization
Pointers and Dynamic Variables. Objectives on completion of this topic, students should be able to: Correctly allocate data dynamically * Use the new.
What is a class? a class definition is a blueprint to build objects its like you use the blueprint for a house to build many houses in the same way you.
Terms and Rules Professor Evan Korth New York University (All rights reserved)
Memory and C++ Pointers.  C++ objects and memory  C++ primitive types and memory  Note: “primitive types” = int, long, float, double, char, … January.
U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles C/C++ Emery Berger and Mark Corner University of Massachusetts.
CS 225 Lab #2 - Pointers, Copy Constructors, Destructors, and DDD.
Memory organization and usage A computer’s memory is, at its lowest level, composed of binary digits (bits). The memory is organized into bytes, which.
Shallow Versus Deep Copy and Pointers Shallow copy: when two or more pointers of the same types point to the same memory – They point to the same data.
Review of C++ Programming Part II Sheng-Fang Huang.
OOP Languages: Java vs C++
Programming Languages and Paradigms Object-Oriented Programming.
Learners Support Publications Pointers, Virtual Functions and Polymorphism.
BPJ444: Business Programming Using Java Classes and Objects Tim McKenna
Advanced Programming Collage of Information Technology University of Palestine, Gaza Prepared by: Mahmoud Rafeek Alfarra Lecture 2: Major Concepts of Programming.
1 Comp 104: Operating Systems Concepts Java Development and Run-Time Store Organisation.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Dynamic Memory Allocation 9.8.
Comp 245 Data Structures Linked Lists. An Array Based List Usually is statically allocated; may not use memory efficiently Direct access to data; faster.
Introduction and Features of Java. What is java? Developed by Sun Microsystems (James Gosling) A general-purpose object-oriented language Based on C/C++
Lecture :2 1.  DEFENTION : Java is a programming language expressly designed for use in the distributed environment of the Internet. It was designed.
Netprog: Java Intro1 Crash Course in Java. Netprog: Java Intro2 Why Java? Network Programming in Java is very different than in C/C++ –much more language.
Computer Science and Software Engineering University of Wisconsin - Platteville 2. Pointer Yan Shi CS/SE2630 Lecture Notes.
CS212: Object Oriented Analysis and Design Lecture 7: Arrays, Pointers and Dynamic Memory Allocation.
C++ Memory Overview 4 major memory segments Key differences from Java
Concordia TAV 2002 Comp5421_421 Comp5421 Object Oriented Programming Using C++ Efficiently Lecture 4 (2) Tianxiang Shen Summer 2002 Department of Computer.
More C++ Features True object initialisation
Run-Time Storage Organization Compiler Design Lecture (03/23/98) Computer Science Rensselaer Polytechnic.
C# Classes and Inheritance CNS 3260 C#.NET Software Development.
1 Linked Structures, LinkedSet References as Links Linear Linked Lists and Non-linear Structures Managing Linked Lists Data Encapsulation Separate from.
Java Basics Opening Discussion zWhat did we talk about last class? zWhat are the basic constructs in the programming languages you are familiar.
COP 2800 Lake Sumter State College Mark Wilson, Instructor.
CS415 C++ Programming Takamitsu Kawai x4212 G11 CERC building WV Virtual Environments Lab West Virginia University.
CS-1030 Dr. Mark L. Hornick 1 Basic C++ State the difference between a function/class declaration and a function/class definition. Explain the purpose.
Objects and Variables Local variables – Confined to single context: allocated on stack – Primitive types such as int or object references – Must be initialized.
Memory Management in Java Computer Science 3 Gerb Objective: Understand references to composite types in Java.
CSI 3125, Preliminaries, page 1 Class. CSI 3125, Preliminaries, page 2 Class The most important thing to understand about a class is that it defines a.
Programming Languages and Paradigms Activation Records in Java.
1 Lecture07: Memory Model 5/2/2012 Slides modified from Yin Lou, Cornell CS2022: Introduction to C.
CS 152: Programming Language Paradigms March 19 Class Meeting Department of Computer Science San Jose State University Spring 2014 Instructor: Ron Mak.
CMSC 202 Advanced Section Classes and Objects: Object Creation and Constructors.
More about Java Classes Writing your own Java Classes More about constructors and creating objects.
Java & C++ Comparisons How important are classes and objects?? What mechanisms exist for input and output?? Are references and pointers the same thing??
AP Java Ch. 4 Review Question 1  Java methods can return only primitive types (int, double, boolean, etc).
Design issues for Object-Oriented Languages
Object Lifetime and Pointers
Dynamic Storage Allocation
CS 153: Concepts of Compiler Design November 28 Class Meeting
Pointers Revisited What is variable address, name, value?
Dynamically Allocated Memory
Dynamic Memory Allocation
Binding Times Binding is an association between two things Examples:
Core Concepts.
Dynamic Memory.
Java Programming Language
Dynamic Memory CSCE 121.
Classes and Objects Object Creation
Run-time environments
CMPE 152: Compiler Design May 2 Class Meeting
Presentation transcript:

Memory Management in Java Mr. Gerb Computer Science 4

Overview What’s special about Java? Memory management in Java

The Java Compiler Earlier Languages (Fortran, C,C++,Pascal) – Source code compiled into object code – Object code linked into executable code – Computer runs executable code Java – Source code compiled into bytecode – Bytecode run by Java Virtual Machine

Why Bytecode is Better Bytecode created on one computer will run on any Java virtual machine – Not true of C/C++ object code More secure – Executable code can do anything in a computer – Java virtual machine keeps bytecode from doing anything malicious … But nothing is faster than executable code

Memory Management In Java, 3 types of memory: TypeComes fromHow? StaticFixed place in memory Declare as static AutomaticStackLocal variables DynamicHeapAllocated via new

Examples Static static int foo; Automatic int bar; Dynamic baz=new myClass(arg)

Composite Types More than one data item – Classes – Arrays In Java, all extended types are dynamic – But references to them can be static, dynamic or automatic Primitive types can be static (declared static), automatic (as local variables) or dynamic (part of a composite type)

Declaring Extended Type in Java myClass foo; – No memory has been allocated – foo is a special pointer called null – It is an error to reference a data member or method of foo foo = new myClass(); – An instance of myClass is now allocated from the heap. Foo points to it. – Can pass arguments to the constructor.

Deallocating Memory in Java No need to delete Java automatically returns all allocated memory to the heap when your program is done with it. Called garbage collection Greatest invention since the egg slicer