Scope, Pass by Value, Static (Discussion 2) (Phạm vi, truyền tham trị và từ khóa static trong Java) - Christine Zhou
Tài liệu thảo luận về phạm vi, truyền tham trị và từ khóa static trong Java, kèm ôn tập danh sách liên kết và sơ đồ box-and-pointer.
Génération de l'aperçu...
Discussion 2: Scope, Pass-byValue, Static Christine Zhou Agenda Announcements Worksheet #1 Worksheet #2 Worksheet #3 (if we can!) Administrivia Lab 1 and Lab 2 due this Friday 2/1 at midnight. ○ Note, all labs are due Friday at midnight the week they are assigned. Proj0 NBody also due Friday at midnight. ○ If you haven’t started please start ASAP! Office hours and exam prep/LOST sections start this week! See calendars on the course website. Pre-semester Advising: @414 or email me! Discussion survey: http://tinyurl.com/cz-disc2-sp19 ○ Good for me to collect your emails (in case I have announcements or mess up during discussion 😅) Review: Defining classes // class definition public class IntList { // instance variables int head; IntList tail; // constructors, which will create IntList objects public IntList() {...} public IntList(int value, IntList tail) {...} // you can create methods that use the instance variables! public void insert(int val) {...} public void removeLast() {...} } Review: Java’s Types Primitives: References: byte, short, long, int, double, float, char, boolean Everything else! Objects, arrays, Strings, etc. Review: Box and Pointer Diagrams Box and Pointers are the 61B equivalent of 61A’s environment diagram They are crucial to helping us keep track of what goes on in a program: use them! int x = 29; int x 29 Primitives go in the box int[] arr = new int[3]; We didn’t specify what integers are going in the array, so Java initializes it with the default value 0 int[ ] arr 0 0 0 Reference types are referenced via pointers Java is pass by value Golden Rule of Equals AKA pass-by-value When you do “a = b”, you always copy the bits (whatever is inside the box) of b into a. For primitives: Directly copy the value inside b to a. For Reference types: Copy the memory address of b into a. ○ Also can say “copies the pointer in b to a” int[ ] arr1 int x = 29; int y = x; int x int y 29 29 int[] arr1 = new int
… Téléchargez le fichier original pour lire le document complet.
- Nom du document
- Scope, Pass by Value, Static (Discussion 2) (Phạm vi, truyền tham trị và từ khóa static trong Java) - Christine Zhou
- École / Cours
- University of California, Berkeley · Lập trình Java
- Contenu
- Tài liệu thảo luận về phạm vi, truyền tham trị và các thành phần tĩnh trong Java, kèm theo các ví dụ và bài tập thực hành về định nghĩa lớp, kiểu dữ liệu và cấu trúc dữ liệu IntList.
- Table des matières
- Agenda
- Announcements
- Administrivia
- Review: Defining classes
- Review: Java’s Types
- Review: Box and Pointer Diagrams
- Java is pass by value
- 1) Pass by What?
- Review: Static Variables/Methods
- 2) Static Methods and Variables
- Review: IntLists
- 3) Practice with Linked Lists
- 4) Extra: Squaring a List
- Pages
- 15 pages
- Téléversé par
- Giang Le
Foire aux questions
Ce document est-il gratuit ?
Oui. « Scope, Pass by Value, Static (Discussion 2) (Phạm vi, truyền tham trị và từ khóa static trong Java) - Christine Zhou » est gratuit — il suffit de vous connecter et de cliquer sur Télécharger pour obtenir le fichier original.
Combien de pages compte ce document ?
Le document contient 15 pages, pour le cours Lập trình Java. Vous pouvez le prévisualiser en ligne avant de le télécharger.
Puis-je prévisualiser avant de télécharger ?
Oui. Vous pouvez prévisualiser ce document directement sur cette page avec le lecteur en ligne, puis décider de le télécharger ou non.

Commentaires (0)
Aucun commentaire pour le moment. Soyez le premier !