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 |
---|---|
2018.11.24 | programs, computational solutions, computer systems (CPUs, memory, memory hierarchy), programming languages (high-level, assembly, machine code), algorithms, JDK + Eclipse, first Java program, variables, data types (int, double); |
2018.11.25 | data types (char, boolean) (see IEEE754 standard; also see some disasters attributable to numerical analysis), assignment operator (=), arithmetic operators (+, -, *, /, %), type conversion, casting, rational operators (>, <, ==), logical operators (!, &&, ||, ^), compound operators (+=, ++), reference types, Scanner object, selections (if-else if-else); |
2018.12.1 | selections (switch-case-default, ?: operator), loops (while, do-while, for; also see pp. 8-10 of the slides 20180824.pdf for programming games), jump statements; |
2018.12.2 | nested loops, analysis of algorithms (you may refer to the slides of analysis of algorithms for further details), arrays; HW1: Lab 2 due 12/8; |
2018.12.8 | for-each loops, briefing data structures, sorting algorithms, searching algorithms, higher-dimensional arrays, methods, call stack, scope of variable, method overloading, recursion (also read recursion); |
2018.12.9 | classe & object (also see what makes OOP ``good''?), fields and methods, encapsulation, constructor, this operator, static members, garbage collection, HAS-A relationship (aggregation) (you should know memory and objects); HW2: Lab 3 and 4 due 12/15; |
2018.12.15 | IS-A relationships, inheritance, super operator, method overriding (another good example: relationBetweenClasses_slides.pdf; worth to study it), subtype polymorphism, up/down casting, instanceof operator, final variable/method/class, abstract class/method, interface; |
2018.12.16 | 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); HW3: Lab 5 due 2019/1/3; Promotion: Java Programming 2, sign-up; |
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 provide a and b). Note that 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. The program asks the user to enter an integer from (0, 99). Then the program updates the range depending on the input accordingly. If the input value is equal to the secret number, then the user wins. If there is only one integer left, then the user loses the game. Make sure that the user enters a number in the feasible range. If not, 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.
Implement the bubble sort and the insertion sort. Compare the efficiency of these three sorting algorithms (including the selection sort demonstrated in class) by running a Monte Carlo simulation and calculating the timecost of each. You may use System.currentTimeMillis() or System.nanoTime() to make timestamps (remember to use long variables).
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.
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.