generated from nighthawkcoders/student
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9040bed
commit afee5fb
Showing
2 changed files
with
51 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.nighthawk.hacks; | ||
|
||
public class StackHeapTest { | ||
public int n = 5; // Primitive data type | ||
public Integer n1 = 5; | ||
public String n2 = "before"; | ||
|
||
public static void changeInt(int nValue, int nRefn, StackHeapTest nRef, Integer nInt, String nString) { | ||
System.out.println("\nBefore (Stack):\n"); | ||
System.out.println(nValue + " or " + System.identityHashCode(nValue)); | ||
System.out.println(nRefn + " or " + System.identityHashCode(nRefn)); | ||
System.out.println(nRef + " or " + System.identityHashCode(nRef)); | ||
|
||
nValue += 10; | ||
nRefn += 10; | ||
nRef.n += 10; | ||
|
||
System.out.println("\nAfter (Stack):\n"); | ||
System.out.println(nValue + " or " + System.identityHashCode(nValue)); | ||
System.out.println(nRefn + " or " + System.identityHashCode(nRefn)); | ||
System.out.println(nRef.n + " or " + System.identityHashCode(nRef.n)); | ||
} | ||
|
||
public static void main(String[] args) { | ||
int nValue = 5; | ||
// int nRef = 5; | ||
StackHeapTest nRef = new StackHeapTest(); | ||
|
||
System.out.println("\nBefore (Heap):\n"); | ||
System.out.println(nValue + " or " + System.identityHashCode(nValue)); | ||
System.out.println(nRef + " or " + System.identityHashCode(nRef)); | ||
System.out.println(nRef.n + " or " + System.identityHashCode(nRef.n)); | ||
|
||
changeInt(nValue, nRef.n, nRef); | ||
|
||
System.out.println("\nAfter (Heap)\n"); | ||
System.out.println(nValue + " or " + System.identityHashCode(nValue)); | ||
System.out.println(nRef + " or " + System.identityHashCode(nRef)); | ||
System.out.println(nRef.n + " or " + System.identityHashCode(nRef.n)); | ||
} | ||
} |