Repository navigation
Expand file tree
/
Copy pathch1_overview.ptx
More file actions
494 lines (444 loc) · 22.7 KB
/
Copy pathch1_overview.ptx
File metadata and controls
494 lines (444 loc) · 22.7 KB
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
<?xml version="1.0"?>
<!-- Generated by Docutils 0.19 -->
<chapter xml:id="overview">
<title>Overview</title>
<section xml:id="sec-prerequisites">
<title>Prerequisites</title>
<p>
This book assumes that you are already familiar with the <url href="http://www.python.org" visual="http://www.python.org">Python</url> programming language.
We will use Python as a starting point for our journey into <url href="http://java.sun.com" visual="http://java.sun.com">Java</url>.
We will begin by looking at a very simple Java program, just to see what the language looks like and how we get a program to run.
Next, we will look at the main constructs that are common to most programming languages:
</p>
<blockquote>
<p>
<ul>
<li>
<p>
Data Types
</p>
</li>
<li>
<p>
Loops
</p>
</li>
<li>
<p>
Reading user input
</p>
</li>
<li>
<p>
Conditionals
</p>
</li>
</ul>
</p>
</blockquote>
<p>
Once we have the basics of Java behind us we will move on to look at the features of Java that are both unique and powerful.
</p>
<blockquote>
<p>
<ul>
<li>
<p>
Classes
</p>
</li>
<li>
<p>
Interfaces
</p>
</li>
<li>
<p>
Collections
</p>
</li>
<li>
<p>
Graphical User Interface Programming
</p>
</li>
<li>
<p>
Generic Programming
</p>
</li>
</ul>
</p>
</blockquote>
</section>
<section xml:id="sec-java-development-environment">
<title>Java Development Environment</title>
<introduction>
<note>
<p>
Thank you to Beryl Hoffman for contributing to this section from her CSAwesome: AP Java Programming book.
</p>
</note>
<p>
The tool that we use to compile a Java source file into a Java class file
is called a <term>compiler</term>. Most programmers use an
<term>Integrated Development Environment</term> (IDE) that has the
compiler built in and helps you write, compile, run, and debug programs.
</p>
<p>
You can learn Java by just using the interactive coding panels called
<term>Active Code</term> in this e-book. If you are logged in, the Active
Code will remember your changes and even show you a history of your
changes to the code if you click on Load History.
</p>
<p>
However, it’s a good idea to also try a Java IDE to build code outside of
this e-book, especially to try coding with user input which Active Code
cannot do. There are many Java IDEs available.
</p>
</introduction>
<subsection xml:id="subsec-java-ide-options">
<title>Java IDE Options</title>
<p>
There are a lot of online cloud IDEs where you can code online in many
programming languages. Most are free to start, but offer different
features for a price. These are great options if you are using a
Chromebook or you cannot install software on your computer or you want an
easy no-installation option. Some of the Active Code samples in this
e-book also include a link to online IDEs. These projects can be copied to
make your own copy.
</p>
<p>Here are some popular online IDEs:</p>
<p>
<ul>
<li>
<p>
CodeHS (<url href="https://codehs.com/"
>https://codehs.com/</url>) has a free Sandbox online IDE
(<url href="https://codehs.com/app/sandbox">https://codehs.com/app/sandbox</url>)
where you can run Java and Java Swing programs. Students can share the links
to their code and the history of their code is saved. CodeHS has free and paid features.
Grading features are in the paid version.
</p>
</li>
<li>
<p>
PickCode (<url href="https://pickcode.io/"
visual="https://pickcode.io/">https://pickcode.io/</url>) is another
online IDE that offers many free and paid features for setting up
classrooms. In the free version, tudents can share links to their code and
the history of their code is saved. Classroom features are in the paid version.
</p>
</li>
<li>
<p>
Replit (<url href="https://replit.com/"
visual="https://replit.com/">https://replit.com/</url>) an online
IDE which recently switched to only allowing 3 projects at a time
for free. Be aware that Replit has turned on its AI feature for code
completion for all accounts (<url href="https://replit.com/ai"
visual="https://replit.com/ai">https://replit.com/ai</url>). Each
user can turn the AI on and off at the bottom of the code window,
and use an AI chat window to ask questions of the AI.
</p>
</li>
<li>
<p>
JuiceMind (<url href="https://juicemind.com/"
visual="https://juicemind.com/">https://juicemind.com/</url>) is an
online IDE that offers many free and paid features for teachers to
set up classrooms like Coding Rooms. It has a built-in version of
CSAwesome.
</p>
</li>
</ul>
</p>
</subsection>
<subsection>
<title>Github Classroom and Codespaces</title>
<p>
Github provides many free opportunities for students and teachers (<url
href="https://docs.github.com/en/education/quickstart"
visual="https://docs.github.com/en/education/quickstart">https://docs.github.com/en/education/quickstart</url>).
Github Classroom (<url href="https://classroom.github.com/"
visual="https://classroom.github.com/">https://classroom.github.com/</url>)
allows teachers to set up a classroom based on github repositories. Github
and git are both widely used in the computer industry, so learning to use
them is great experience for students. Github now has a cloud IDE called
Codespaces (<url href="https://github.com/features/codespaces"
visual="https://github.com/features/codespaces">https://github.com/features/codespaces</url>)
which you can use for 60 hours a month for free or completely free if you
join as a school or get approved as a teacher or student. In Codespaces,
you can start from a blank template or a repo, open a .java file in the
VSCode editor, follow prompts to install the Extension Pack for Java,
click on the Run and Debug (play button), follow the prompts to install
the Java debugger, and see the output of your code in the terminal. You
can also use Copilot (<url href="https://github.com/features/copilot"
visual="https://github.com/features/copilot">https://github.com/features/copilot</url>),
which is a coding AI based on GPT, for free if you are approved for
educational use.
</p>
<p>
Students will need to sign up for a free Github account (<url
href="https://github.com/signup"
visual="https://github.com/signup">https://github.com/signup</url>) if
they don’t already have one in order to use Codespaces.
</p>
</subsection>
<subsection>
<title>VSCode</title>
<p>
VSCode (<url href="https://code.visualstudio.com"
visual="https://code.visualstudio.com">https://code.visualstudio.com</url>)
is a widely used coding editor which you can download on your local
computers. It has many useful extensions. The code can be run in a
terminal window in the editor. See <url
href="https://code.visualstudio.com/docs/languages/java"
visual="https://code.visualstudio.com/docs/languages/java">https://code.visualstudio.com/docs/languages/java</url>
for Java support. This editor is different than Microsoft Visual Studio
which is a very large IDE.
</p>
</subsection>
<subsection>
<title>Dr. Java</title>
<p>
DrJava (from <url href="http://DrJava.org"
visual="http://DrJava.org">http://DrJava.org</url>) is a free, simple,
easy to install and use development environment. One nice feature is the
interactions pane at the bottom which lets you try out Java code without
having to create a class first.
</p>
</subsection>
<subsection>
<title>BlueJ</title>
<p>
BlueJ (<url href="https://www.bluej.org/"
visual="https://www.bluej.org/">https://www.bluej.org/</url>) is a free
Java IDE designed for beginners. It is built to explore objects and
object-oriented programming and has a teachers’ community as well as a
playlist of videos online <url
href="https://www.youtube.com/playlist?list=PLYPWr4ErjcnzWB95MVvlKArO6PIfv1fHd"
visual="https://www.youtube.com/playlist?list=PLYPWr4ErjcnzWB95MVvlKArO6PIfv1fHd">https://www.youtube.com/playlist?list=PLYPWr4ErjcnzWB95MVvlKArO6PIfv1fHd</url>
to go with the BlueJ Object-First Java book.
</p>
</subsection>
<subsection>
<title>jGRASP</title>
<p>
jGRASP (<url href="https://www.jgrasp.org/"
visual="https://www.jgrasp.org/">https://www.jgrasp.org/</url>) is a free
lightweight development environment, created specifically to provide
automatic generation of software visualizations. jGRASP is implemented in
Java, and runs on all platforms with a Java Virtual Machine (Java version
1.5 or higher). jGRASP produces Control Structure Diagrams (CSDs) for
Java, C, C++, Objective-C, Python, Ada, and VHDL; Complexity Profile
Graphs (CPGs) for Java and Ada; UML class diagrams for Java; and has
dynamic object viewers and a viewer canvas that work in conjunction with
an integrated debugger and workbench for Java. The site includes both
intro video and PDF tutorials.
</p>
</subsection>
<subsection>
<title>IntelliJ</title>
<p>
IntelliJ (<url href="https://www.jetbrains.com/idea/"
visual="https://www.jetbrains.com/idea/">https://www.jetbrains.com/idea/</url>)
is a free Java IDE from JetBrains which many professionals use. It is a
little easier to configure than Eclipse below. Here is a guide on how to
set up IntelliJ: <url
href="https://www.jetbrains.com/help/idea/install-and-set-up-product.html"
visual="https://www.jetbrains.com/help/idea/install-and-set-up-product.html">https://www.jetbrains.com/help/idea/install-and-set-up-product.html</url>.
</p>
</subsection>
<subsection>
<title>Netbeans</title>
<p>
Netbeans (<url href="https://netbeans.org/"
visual="https://netbeans.org/">https://netbeans.org/</url>) is one of the
original Java IDEs. Here is a tutorial on how to set it up: <url
href="https://netbeans.org/kb/docs/java/quickstart"
visual="https://netbeans.org/kb/docs/java/quickstart">https://netbeans.org/kb/docs/java/quickstart</url>.
</p>
</subsection>
<subsection>
<title>Eclipse</title>
<p>
Eclipse (<url href="https://www.eclipse.org/downloads/packages/installer"
visual="https://www.eclipse.org/downloads/packages/installer">https://www.eclipse.org/downloads/packages/installer</url>)
is what many professional Java programmers use. It may be a little complex
for beginners. Here are some installation and configuration instructions
for Eclipse for Java beginners: <url
href="http://skylit.com/javamethods/faqs/Eclipse.pdf"
visual="http://skylit.com/javamethods/faqs/Eclipse.pdf">http://skylit.com/javamethods/faqs/Eclipse.pdf</url>.
</p>
</subsection>
</section>
<section xml:id="why-another-programming-language">
<title>Why Another Programming Language?</title>
<p>
Python is a nice language for beginning programming for several reasons.
First the syntax is sparse, and clear.
Second, the underlying model of how objects and variables work is very consistent.
Third, you can write powerful and interesting programs without a lot of work.
However, Python is representative of one kind of language, called a dynamic language.
You might think of Python as being fairly informal.
There are other languages, like Java and C++ that are more formal.
</p>
<p>
These languages have some advantages of their own.
First, is speed: Java and C++ code will generally give better performance than Python code. (See <xref ref="note-python-performance"/>.)
Second is their maintainability.
A lot of what makes Python easy to use is that you must remember certain things.
For example if you set variable <c>x</c> to reference a turtle, and forget later that <c>x</c> is a turtle but try to invoke a string method on it, you will get an error.
Java and C++ protect you by forcing you to be upfront and formal about the kind of object each variable is going to refer to.
</p>
<p>
In one sense Python is representative of a whole class of languages, sometimes referred to as “scripting languages.” Other languages in the same category as Python are Ruby and Perl.
Java is representative of what I will call industrial strength languages.
Industrial strength languages are good for projects with several people working on the project where being formal and careful about what you do may impact lots of other people.
Languages in this category include Rust, C++, C#, and Ada.
</p>
<p>
Programming languages will always change.
As the field of computer science advances there will be new programming languages and you will need to learn them.
It is important to learn several programming languages so that you know what to expect.
There are certain features that most programming languages have in common; variables, loops, conditionals, functions.
And there are some features that are unique.
If you know what is common in languages that is a good place to start.
</p>
<note xml:id="note-python-performance">
<title>A Note about Python Performance</title>
<p>
Although Python code is generally slower than Java and C++ code, in practice Python programs can achieve equivalent performance.
This can be done by compiling Python code to C code (see: <url href="https://cython.org" visual="https://cython.org">Cython</url>) or by calling high-performance libraries from Python (e.g., <url href="https://numpy.org" visual="https://numpy.org">NumPy</url>, <url href="https://scikit-learn.org/stable/" visual="https://scikit-learn.org/stable/">scikit-learn</url>, etc.).
So native language performance is just one criteria to consider when deciding which language to use for a program.
</p>
</note>
</section>
<section xml:id="sec-why-java-why-not-c-or-c">
<title>Why Learn Java? Why not C or C++?</title>
<p>
It is easier to learn to create interesting programs in Java than in C or C++, for several reasons:
</p>
<p>
<ul>
<li>
<p>
Java includes a larger standard library than C or C++, which means that sophisticated programs can be created in Java without including external dependencies.
The Java Standard Edition contains thousands of built-in classes that support tasks like file input/output, networking, data structures, and graphical interfaces.
We could not begin to scratch the surface of these classes even if we devoted all of class time! However, we will cover many useful and powerful features of the Java standard library this semester.
</p>
</li>
<li>
<p>
Java incorporates automatic garbage collection of memory, whereas C and C++ programs typically include some degree of manual memory management.
This makes programming in those languages more challenging.
</p>
</li>
<li>
<p>
C++’s syntax is more complicated than Java’s, making it more difficult to learn.
For example, C++ supports a feature called operator overloading, which makes it possible to change the behavior of operators like <c>+</c>.
This can make it more difficult to understand what a C++ program is doing.
</p>
</li>
</ul>
</p>
<p>
Certainly, C and C++ are important languages, and are worth learning.
But for these and other reasons, we’ve decided to use Java for this course.
Learning Java will be a good preparation for learning these and other languages!
</p>
</section>
<section xml:id="overview_summary">
<title>Summary & Reading Questions</title>
<p><ol>
<li>
<p>Learning multiple programming languages helps programmers adapt to different styles and environments.</p>
</li>
<li>
<p>Python is a dynamic scripting language that is beginner-friendly, but it is less strict with types and generally slower than compiled languages.</p>
</li>
<li>
<p>Languages like Java and C++ are statically typed and offer better performance and maintainability for large-scale projects.</p>
</li>
<li>
<p>Java has a simpler syntax than C++ and includes automatic garbage collection, which reduces the complexity of memory management.</p>
</li>
<li>
<p>Java’s extensive standard library enables the development of sophisticated programs without relying on external dependencies.</p>
</li>
</ol></p>
<reading-questions xml:id="rqs-learnlang2">
<exercise label="summary-lang-1">
<statement>
<p>Which of the following best describes Python as a programming language?</p>
</statement>
<choices>
<choice>
<statement><p>Statically typed and high-performance</p></statement>
<feedback><p>No. This better describes languages like Java or C++.</p></feedback>
</choice>
<choice correct="yes">
<statement><p>Dynamically typed and beginner-friendly</p></statement>
<feedback><p>That’s right! Python is dynamically typed and easy for beginners.</p></feedback>
</choice>
<choice>
<statement><p>Industrial strength and verbose</p></statement>
<feedback><p>No. Python is more informal and concise.</p></feedback>
</choice>
<choice>
<statement><p>Memory-managed and pointer-based</p></statement>
<feedback><p>No. That describes lower-level languages like C or C++.</p></feedback>
</choice>
</choices>
</exercise>
<exercise label="summary-lang-2">
<statement>
<p>Why is Java a better language for beginners compared to C++?</p>
</statement>
<choices>
<choice>
<statement><p>It requires more manual memory management</p></statement>
<feedback><p>No. Java manages memory automatically.</p></feedback>
</choice>
<choice>
<statement><p>It has a smaller standard library</p></statement>
<feedback><p>No. Java has a very large standard library.</p></feedback>
</choice>
<choice correct="yes">
<statement><p>It avoids complex syntax and has automatic garbage collection</p></statement>
<feedback><p>Correct! These features make Java easier for beginners.</p></feedback>
</choice>
<choice>
<statement><p>It supports operator overloading</p></statement>
<feedback><p>No. That's a C++ feature and it adds complexity.</p></feedback>
</choice>
</choices>
</exercise>
<exercise label="summary-lang-3">
<statement>
<p>What is a major benefit of learning multiple programming languages?</p>
</statement>
<choices>
<choice>
<statement><p>You can standardize all projects using one universal syntax</p></statement>
<feedback><p>No. Each language has its own syntax and is suited for different tasks.</p></feedback>
</choice>
<choice>
<statement><p>You will minimize runtime errors across all platforms</p></statement>
<feedback><p>No. Runtime errors depend more on logic and environment than the number of languages you know.</p></feedback>
</choice>
<choice correct="yes">
<statement><p>You gain exposure to different language features and paradigms</p></statement>
<feedback><p>Great choice! This helps you become a more adaptable and well-rounded programmer.</p></feedback>
</choice>
<choice>
<statement><p>You can bypass the need for understanding compilation and interpretation</p></statement>
<feedback><p>No. Understanding how code is executed remains essential regardless of how many languages you know.</p></feedback>
</choice>
</choices>
</exercise>
</reading-questions>
</section>
</chapter>