-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.html
146 lines (125 loc) · 12.1 KB
/
types.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>methods and types</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="navig.css">
<link rel="stylesheet" type="text/css" href="main.css">
<script type="application/javascript">
function resizeIFrameToFitContent( iFrame ) {
iFrame.width = iFrame.contentWindow.document.body.scrollWidth;
iFrame.height = iFrame.contentWindow.document.body.scrollHeight;
}
window.addEventListener('DOMContentLoaded', function(e) {
var iFrame = document.getElementById( 'iFrame1' );
resizeIFrameToFitContent( iFrame );
// or, to resize all iframes:
var iframes = document.querySelectorAll("iframe");
for( var i = 0; i < iframes.length; i++) {
resizeIFrameToFitContent( iframes[i] );
}
} );
</script>
</head>
<body>
<body>
<div class="container">
<div class="row">
<div class="col-md-3 left-menu">
<div class="logo"><i class="fa fa-coffee "></i>
<div>VIZ JAVA</div>
</div>
<div class="accordion">
<div class="section">
<input type="radio" name="accordion-1" id="section-1" value="toggle"/>
<label for="section-1"><span>Intro</span></label>
<div class="content">
<ul>
<li><i class="fa fa-start"></i><span><a href="howtouse.html">How to use</a></span></li>
</ul>
</div>
</div>
<div class="section">
<input type="radio" name="accordion-1" id="section-2" value="toggle"/>
<label for="section-2"> <span>Primitive and reference types</span></label>
<div class="content">
<ul>
<li><i class="fa fa-start"></i><span><a href="types.html">types</a></span></li>
</ul>
</div>
</div>
<div class="section">
<input type="radio" name="accordion-1" id="section-3" checked="toggle"/>
<label for="section-3"> <span>Array</span></label>
<div class="content">
<ul>
<li><i class="fa fa-start"></i><span><a href="arrays_1.html">Arrays_1</a></span></li>
<li><i class="fa fa-start"></i><span><a href="arrays_2.html">Arrays_2</a></span></li>
<li><i class="fa fa-start"></i><span><a href="arrays_3.html">Arrays_3</a></span></li>
<li><i class="fa fa-start"></i><span><a href="arrays.html">Advacned</a></span></li>
</ul>
</div>
</div>
<div class="section">
<input type="radio" name="accordion-1" id="section-4" value="toggle"/>
<label for="section-4"> <span>Recursion</span></label>
<div class="content">
<ul>
<li><i class="fa fa-start"></i><span><a href="recur.html">Start</a></span></li>
</ul>
</div>
</div>
<div class="section">
<input type="radio" name="accordion-1" id="section-5" value="toggle"/>
<label for="section-5"> <span>forloop</span></label>
<div class="content">
<ul>
<li><i class="fa fa-start"></i><span><a href="forloop.html">Basic</a></span></li>
<li><i class="fa fa-start"></i><span><a href="forloop_1.html">Medium</a></span></li>
<li><i class="fa fa-start"></i><span><a href="forloop_2.html">Advanced</a></span></li>
</ul>
</div>
</div>
<div class="section">
<input type="radio" name="accordion-1" id="section-6" value="toggle"/>
<label for="section-6"> <span>While Loops </span></label>
<div class="content">
<ul>
<li><i class="fa fa-start"></i><span><a href="Whileloop_1.html">Basic</a></span></li>
<li><i class="fa fa-start"></i><span><a href="Whileloop_2.html">Medium</a></span></li>
<li><i class="fa fa-start"></i><span><a href="Whileloop_3.html">Advanced</a></span></li>
</ul>
</div>
</div>
<div class="section">
<input type="radio" name="accordion-1" id="section-7" value="toggle"/>
<label for="section-7"> <span>Lab Reviews </span></label>
<div class="content">
<ul>
<li><i class="fa fa-start"></i><span><a href="lab1.html">Lab 1</a></span></li>
<li><i class="fa fa-start"></i><span><a href="lab2.html">Lab 2</a></span></li>
<li><i class="fa fa-start"></i><span><a href="lab3.html">Lab 3</a></span></li>
<li><i class="fa fa-start"></i><span><a href="lab4.html">Lab 4</a></span></li>
</ul>
</div>
</div>
</div>
</div>
<div class="col-md-9 right-content">
<p>For this tutorial, we are going to take a close look on the differences between <strong>primitive</strong> and <strong>reference</strong> types in Java.</p>
<p>Look at the code below. Before running this, what are the expected output in the console?</p>
<p>Now, let's see what is the actual output in the console. (Use the 'Forward' button or taggle the bard)</p>
<iframe src="http://pythontutor.com/iframe-embed.html#code=public%20class%20SwapCircle%20%7B%0A%0A%20%20%20private%20static%20int%20circleCount%20%3D%200%3B%0A%20%20%20%0A%20%20%20private%20double%20radius%3B%0A%20%20%20%0A%20%20%20public%20SwapCircle%28double%20radius%29%20%7B%0A%20%20%20%20%20%20circleCount%2B%2B%3B%0A%20%20%20%20%20%20if%20%28radius%20%3E%200%29%20%7B%0A%20%20%20%20%20%20%20%20%20this.radius%20%3D%20radius%3B%0A%20%20%20%20%20%20%7D%20else%20%7B%0A%20%20%20%20%20%20%20%20%20this.radius%20%3D%201%3B%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%20%20%20%0A%20%20%20public%20static%20int%20getCircleCount%28%29%20%7B%0A%20%20%20%20%20%20return%20circleCount%3B%0A%20%20%20%7D%0A%20%20%20%0A%20%20%20public%20double%20getRadius%28%29%20%7B%0A%20%20%20%20%20%20return%20this.radius%3B%0A%20%20%20%7D%0A%20%20%20%0A%20%20%20public%20static%20void%20swapInts%28int%20x,%20int%20y%29%20%7B%0A%20%20%20%20%20%20%20System.out.println%28%22%5CtInside%20swapInts%22%29%3B%0A%20%20%20%20%20%20%20System.out.println%28%22%5Ctswapping%20integers%20%22%20%2B%20x%20%2B%20%22%20and%20%22%20%2B%20y%29%3B%0A%20%20%20%20%20%20%20int%20temp%20%3D%20x%3B%0A%20%20%20%20%20%20%20x%20%3D%20y%3B%0A%20%20%20%20%20%20%20y%20%3D%20temp%3B%0A%20%20%20%20%20%20%20System.out.println%28%22%5Ctfinished%20swapping%20%22%20%2B%20x%20%2B%20%22%20and%20%22%20%2B%20y%29%3B%0A%20%20%20%20%7D%0A%20%20%20%0A%20%20%20public%20static%20void%20swapCircles%28SwapCircle%20c1,%20SwapCircle%20c2%29%20%7B%0A%20%20%20%20%20%20%20System.out.println%28%22%5CtInside%20swapCircles%22%29%3B%0A%20%20%20%20%20%20%20System.out.println%28%22%5Ctswapping%20circles%20%22%20%2B%20c1%20%2B%20%22%20and%20%22%20%2B%20c2%29%3B%0A%20%20%20%20%20%20%20double%20r%20%3D%20c1.radius%3B%0A%20%20%20%20%20%20%20c1.radius%20%3D%20c2.radius%3B%0A%20%20%20%20%20%20%20c2.radius%20%3D%20r%3B%0A%20%20%20%20%20%20%20System.out.println%28%22%5Ctfinished%20swapping%20%22%20%2B%20c1%20%2B%20%22%20and%20%22%20%2B%20c2%29%3B%0A%20%20%20%7D%0A%20%20%20%0A%20%20%20public%20String%20toString%28%29%20%7B%0A%20%20%20%20return%20String.format%28%22Circle%28%25.0f%29%22,%20this.radius%29%3B%0A%20%20%20%20%7D%0A%20%20%20%20%0A%0A%20%20%20public%20static%20void%20main%28String%5B%5D%20args%29%20%7B%0A%20%20%20%0A%20%20%20%20//%20first%20try%20swapping%20integers%0A%20%20%20int%20a%20%3D%207,%20b%20%3D%204%3B%0A%20%20%20System.out.println%28%22BEFORE%20swap%3A%22%29%3B%0A%20%20%20System.out.println%28%22a%20%3D%20%22%20%2B%20a%29%3B%0A%20%20%20System.out.println%28%22b%20%3D%20%22%20%2B%20b%29%3B%0A%20%20%20SwapCircle.swapInts%28a,%20b%29%3B%0A%20%20%20System.out.println%28%22AFTER%20swap%3A%22%29%3B%0A%20%20%20System.out.println%28%22a%20%3D%20%22%20%2B%20a%29%3B%0A%20%20%20System.out.println%28%22b%20%3D%20%22%20%2B%20b%29%3B%0A%20%20%20System.out.println%28%29%3B%0A%20%20%20%0A%20%20%20%7D%0A%20%20%20%20%0A%7D%0A&codeDivHeight=400&codeDivWidth=350&cumulative=false&curInstr=0&heapPrimitives=false&origin=opt-frontend.js&py=java&rawInputLstJSON=%5B%5D&textReferences=false" onload='javascript:(function(o){o.style.height=o.contentWindow.document.body.scrollHeight+"px";}(this));' style="height:600px;width:800px;border:none;overflow:hidden;"></iframe>
<p/>
<p>Look at the code below. Before running this, what are the expected printouts in the console?<p/>
<p>Now, let's see what is the actual output in the consol. (Use the 'Forward' button or taggle the bard)<p/>
<iframe width="1200" height="800" frameborder="0" src="http://pythontutor.com/iframe-embed.html#code=public%20class%20SwapCircle%20%7B%0A%0A%20%20%20private%20static%20int%20circleCount%20%3D%200%3B%0A%20%20%20%0A%20%20%20private%20double%20radius%3B%0A%20%20%20%0A%20%20%20public%20SwapCircle%28double%20radius%29%20%7B%0A%20%20%20%20%20%20circleCount%2B%2B%3B%0A%20%20%20%20%20%20if%20%28radius%20%3E%200%29%20%7B%0A%20%20%20%20%20%20%20%20%20this.radius%20%3D%20radius%3B%0A%20%20%20%20%20%20%7D%20else%20%7B%0A%20%20%20%20%20%20%20%20%20this.radius%20%3D%201%3B%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%20%20%20%0A%20%20%20public%20static%20int%20getCircleCount%28%29%20%7B%0A%20%20%20%20%20%20return%20circleCount%3B%0A%20%20%20%7D%0A%20%20%20%0A%20%20%20public%20double%20getRadius%28%29%20%7B%0A%20%20%20%20%20%20return%20this.radius%3B%0A%20%20%20%7D%0A%20%20%20%0A%20%20%20public%20static%20void%20swapInts%28int%20x,%20int%20y%29%20%7B%0A%20%20%20%20%20%20%20System.out.println%28%22%5CtInside%20swapInts%22%29%3B%0A%20%20%20%20%20%20%20System.out.println%28%22%5Ctswapping%20integers%20%22%20%2B%20x%20%2B%20%22%20and%20%22%20%2B%20y%29%3B%0A%20%20%20%20%20%20%20int%20temp%20%3D%20x%3B%0A%20%20%20%20%20%20%20x%20%3D%20y%3B%0A%20%20%20%20%20%20%20y%20%3D%20temp%3B%0A%20%20%20%20%20%20%20System.out.println%28%22%5Ctfinished%20swapping%20%22%20%2B%20x%20%2B%20%22%20and%20%22%20%2B%20y%29%3B%0A%20%20%20%20%7D%0A%20%20%20%0A%20%20%20public%20static%20void%20swapCircles%28SwapCircle%20c1,%20SwapCircle%20c2%29%20%7B%0A%20%20%20%20%20%20%20System.out.println%28%22%5CtInside%20swapCircles%22%29%3B%0A%20%20%20%20%20%20%20System.out.println%28%22%5Ctswapping%20circles%20%22%20%2B%20c1%20%2B%20%22%20and%20%22%20%2B%20c2%29%3B%0A%20%20%20%20%20%20%20double%20r%20%3D%20c1.radius%3B%0A%20%20%20%20%20%20%20c1.radius%20%3D%20c2.radius%3B%0A%20%20%20%20%20%20%20c2.radius%20%3D%20r%3B%0A%20%20%20%20%20%20%20System.out.println%28%22%5Ctfinished%20swapping%20%22%20%2B%20c1%20%2B%20%22%20and%20%22%20%2B%20c2%29%3B%0A%20%20%20%7D%0A%20%20%20%0A%20%20%20public%20String%20toString%28%29%20%7B%0A%20%20%20%20return%20String.format%28%22Circle%28%25.0f%29%22,%20this.radius%29%3B%0A%20%20%20%20%7D%0A%20%20%20%20%0A%0A%20%20%20public%20static%20void%20main%28String%5B%5D%20args%29%20%7B%0A%20%20%20%20%20//%20next%20try%20swapping%20SwapCircle%20radii%0A%20%20%20%20%20SwapCircle%20first,%20second%3B%0A%20%20%20%20%20first%20%3D%20new%20SwapCircle%287%29%3B%0A%20%20%20%20%20second%20%3D%20new%20SwapCircle%284%29%3B%0A%20%20%20%20%20System.out.println%28%22BEFORE%20swap%3A%22%29%3B%0A%20%20%20%20%20System.out.println%28%22first%20%3D%20%22%20%2B%20first%29%3B%0A%20%20%20%20%20System.out.println%28%22second%20%3D%20%22%20%2B%20second%29%3B%0A%20%20%20%20%20SwapCircle.swapCircles%28first,%20second%29%3B%0A%20%20%20%20%20System.out.println%28%22AFTER%20swap%3A%22%29%3B%0A%20%20%20%20%20System.out.println%28%22first%20%3D%20%22%20%2B%20first%29%3B%0A%20%20%20%20%20System.out.println%28%22second%20%3D%20%22%20%2B%20second%29%3B%0A%20%20%20%20%20System.out.println%28%29%3B%0A%20%20%20%7D%0A%20%20%20%20%0A%7D%0A&codeDivHeight=400&codeDivWidth=350&cumulative=false&curInstr=0&heapPrimitives=false&origin=opt-frontend.js&py=java&rawInputLstJSON=%5B%5D&textReferences=false"> </iframe>
<p/>
<p>Why do you think, they performnce differently?<p/>
<p>What can you conclude with the aspect of primitive and reference type?<p/>
</div>
</div>
</div>
</body>
</body>
</html>