This course is designed for the students who want to learn Java but have any programming experiences before. We will start with the very beginning of program design and fundamental concepts about programs and machines. You are expected to be capable to implement your idea in Java independently after 30 hours of lectures. Furthermore, I wish you could learn other programming languages without suffering from starting over.
The topics delivered in the following weeks are as follows:
Date | Summary |
---|---|
2019.1.5 | programs, computational solutions, computer systems (CPUs, memory, memory hierarchy), programming languages (high-level, assembly, machine code), algorithms, JDK + Eclipse, first Java program; |
2019.1.6 | variables, data types (int, double, char, boolean) (see IEEE754 standard; also see some disasters attributable to numerical analysis), assignment operator (=), arithmetic operators (+, -, *, /, %), type conversion, casting, rational operators (>, <, ==), logical operators (!, &&, ||, ^); |
2019.1.12 | compound operators (+=, ++), reference types, Scanner object, selections (if-else if-else, switch-case-default, ?: operator), loops (while, do-while; also see pp. 8-10 of the slides 20180824.pdf for programming games); |
2019.1.13 | for loops, jump statements, nested loops; HW1: Lab 2 due 2019.1.20; |
2019.1.19 | (no class) |
2019.1.20 | analysis of algorithms (you may refer to the slides of analysis of algorithms for further details); HW2: case (C) and (D) in p. 152 of the slides due 2019.1.26; |
2019.1.26 | arrays, for-each loops, briefing data structures, sorting algorithms, searching algorithms, higher-dimensional arrays, methods; |
2019.1.27 | call stack, scope of variable, method overloading, recursion, classe & object (also see what makes OOP ``good''?), fields and methods, encapsulation; HW3: Lab 3 and 4 due 2019.2.16 (FYR: DeepMind AI「AlphaStar」對戰《星海爭霸 II》職業高手,取得十勝一敗成績 by Engadget); |
2019.2.16 | constructor, this operator, static members, garbage collection, HAS-A relationship (aggregation) (you should know memory and objects); |
2019.2.17 | IS-A relationships, inheritance, super operator, method overriding (worth to study relationBetweenClasses_slides.pdf), subtype polymorphism, up/down casting, instanceof operator; HW4: Lab 6 due 2019.2.24; |
2019.2.24 | final variable/method/class, abstract class/method, interface, wrapper classes, immutable objects, enum types, namespace, nested classes, anonymous classes, iterators, packages, class path, jar, assertion and exception handling, strings, regular expressions (see regex by Oracle, or regexone, regex crossword), file NIO (Chapter 10: File System), events, listeners, callbacks, Java graphics and GUIs, Java event handling, Java 2D games tutorial (see snake game); feedback sheet; promotion: Java Programming 2; homework submission deadline: 2019.3.3; |
Install JDK11 and Eclipse (or any IDE you have been familiar with) in your computer (desktop/laptop). The links of both can be found in the slides or this course page (see the installation session). You don't need to send me email for this lab unless you cannot complete the installation. We don't consider the new features of JDK11 in this class. To run your Java program in Eclipse, simply choose JDK8 when you create a new project.
Let x be any real number. Write a program which calculates the square root of x by using Bisection method. Note that you should reduce this problem to the bisection method with a natural choice for a and b (i.e., the user does not need to specify a and b). Math.pow and Math.sqrt are not allowed. Send the source code (the file with .java extension) to d00922011@ntu.edu.tw. Remember to indicate this class number, your full Chinese name, and homework number in your email title. For example, [Java304] Homework 1 盧政良. Do not attach any class file because any executable file will be ruled out by Gmail.
Write a program for number-guessing game (you may refer to Guess the Number if you have never played this game). The program first generates a secret number ranging between 0 and 99, inclusive. Then the program asks the player to guess a number. If the input value is equal to the secret number, then the player wins. If not, then update the range depending on the input accordingly. For example, the program shows (0, 49) on the screen if the player types 50 for the first time and he/she doesn't know the secret number 42. If there is only one integer left, then the player loses the game. Also, make sure that the player types a number in the feasible range; otherwise, ask the user to redo the input.
Write an AI program which plays this game. For example, the naive strategy is to guess a number in random. Also, calculate the winning rate by simulating your AI program for 1e5 times.
First, implement three sorting algorithms (bubble sort, insertion sort, and selection sort). You then compare the efficiency of these three sorting algorithms together with Array.sort (check its API) by running Monte Carlo simulation as follows: benchmark the time cost between algorithms for various sizes (doubling hypothesis), shown as below.
Let x be any real number and n be any integer (n can be negative). Write a program which calculates x ^ n by recursion. For example, 2 ^ -10 = 0.000976. Try to make your program run in O(log | n |) time. Note that you are not allowed to use Math.pow and any loop in your solution.
See the problem statement in p.7 of this slides: 程式實作題 in C++ Programming.
Rewrite the program in Lab 2 in object-oriented programming. You need to analyze the functionalities in Lab 2. You may define any number of classes if necessary. For example, you can consider two objects in this system: one for the game procedure, the other for the players (in order to change the strategies in the future). In this way, you should define a protocal so that the game object has minimal dependency on the player. If so, you can easily develop various strategies to play this game and see which strategy is more promising.
Try various strategies for this game. For example, the naive strategy is to guess a number in random, and the binary-search strategy is to return the number in the middle of the feasible range. Then compare the winning rates by simulating these strategies for 1e5 times.