DOC PREVIEW
USF CS 112 - Java Programs

This preview shows page 1 out of 2 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 2 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 2 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CS112-2012S-02 Creating Classes 102-0: Java Programs• Java programs are a collection of classes• Each class is a Template, not an Object• Can’t use a class until we create an instance (call “new”)• One exception: Static Methods• In this course, we will only use one static method: main method02-1: Java Programs• Simpliest Java Program:• Hello World 3 ways02-2: Classes• Classes contain data and methods (like functions in python)• Methods can access data members (called instance variables) of a class• Special method, called “Constructor”, which is called when an object of the class is created using new.02-3: Classes• Second Example: Employee02-4: Implementation I: Locals• Variables declared inside functions are called local variables• Stored on the Call Stack• Created when function is called• Dissappear when function ends02-5: Implementation I: locals• When a method is called:• Allocate space on the call stack to store method parameters & variables local to the method• Activation record for the method• Copy values into the space allocated for the parameters• Execute the body of the method• Pop activation record off the stack02-6: Implementation I: locals• Example: MethodTest• Code• Memory contents (on whiteboard)CS112-2012S-02 Creating Classes 202-7: Pass-By-Value• Methods in Java are “Pass-By-Value”• Value is copied into the parameter• Changes to the parameter don’t change the value passed int• Example: MethodTest202-8: Objects• Stack is not the only place where data is stored• Objects (specifically, instance variables) are stored on the Heap• Different section of memory than the stack• Memory is allocated (or set aside) on the heap through a call to new02-9: Objects• HeapData, HeapDriver102-10: Objects• Every object in your program is a pointer to memory on the heap• When we pass an object as a parameter, copy the pointer• Changes to the pointer itsef are not reflected back to the calling method• Changes made to what the pointer points to are reflected back to the calling method02-11: Objects• HeapData, HeapDriver2,


View Full Document

USF CS 112 - Java Programs

Documents in this Course
Structs

Structs

4 pages

Trees

Trees

25 pages

Strings

Strings

27 pages

Queues

Queues

3 pages

Trees

Trees

24 pages

Arrays

Arrays

5 pages

ArrayList

ArrayList

24 pages

Stacks

Stacks

2 pages

Stacks

Stacks

8 pages

Trees

Trees

24 pages

Stacks

Stacks

8 pages

Queues

Queues

16 pages

Queues

Queues

17 pages

Queues

Queues

17 pages

Load more
Download Java Programs
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Java Programs and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Java Programs 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?