--- tags: computer science, java --- @Depreciated <center> # **Java Programming 2** :::info Location: Room 108, 德田館 Time: 1300 ~ 1600 ::: </center> <div style="text-align: right">``Simplicity is the ultimate sophistication.''<br>-- Leonardo da Vinci</div> <br> <div style="text-align: right">``... it is always a good practice first to make your code right, <br>and then make it fast.''<br>-- Brian Goetz</div> ## **Class Information** ### Instructor - Name: 盧政良 (Zheng-Liang Lu, Arthur) - Email: arthurzllu@gmail.com ### Objectives - Comprehend design patterns widely used in large-scale projects - Learn generics, annotations, and reflection, Stream APIs (with lambdas), and Optional APIs - Start your first web application powered by Spring Boot - Exploit concurrent programming with Concurrency API ### Prerequisites - Java, especially the OOP chapters - https://www.csie.ntu.edu.tw/~d00922011/java.html ### Working Environment - Spring Tools 4 for Eclipse https://spring.io/tools#suite-three - (Alternative) IntelliJ IDEA Ultimate https://www.jetbrains.com/idea/download/ :::danger Download and install the ultimate version because that version supports the Spring framework. You could take a free 30-day trial to evaluate IntelliJ IDEA. ::: ### Recording Classroom Lectures Policy :::warning Recording of classroom lectures is <font color="red">**prohibited**</font> unless advance written permission is obtained from the class instructor and any guest presenter(s). ::: ## **Overview** ### Design Patterns - Creational patterns: singleton, factory method, abstract factory - Structural patterns: adapter, bridge, proxy, decorator, sharing (interning, flyweight) - Behavioral patterns: iterator, strategy, observer (publish/subscribe) - Model-control-view (MVC) model ### Advanced Java - Generics - Collections: List (ArrayList & LinkedList), Map (TreeMap & HashMap), Set (TreeSet & HashSet) - Anonymous function (lambda) - Stream API: upgraded collections with functional programming - Optional API: alternative to null (a billion-dollar mistake) - Reflection and annotation ### Concurrent Programming - Java Virtual Machine (JVM) - Basic concepts of operating systems (OS) - Process & thread - Job scheduling: round-robin (RR) - Thread & Runnable - Race condition, mutual exclusion & synchronized methods/blocks - Producer-consumer problem (bounded-buffer problem) & semaphores - Dining philosophers: deadlock, livelock, starvation - High-level concurrency framework: - Thread pools - Fork-join pools - Asynchronous computation - Concurrent data structures, atomic variables, synchronizers, monitor locks ### Web Development - Databases & JDBC - Dependency management: Maven/Gradle - Core concepts of Spring Framework: Inversion of Control (IoC) & Aspect-Oriented Programming (AOP) - Catchup of front-end techniques: HTML, CSS, and React.js - Project: shopping cart - Virtualization: Docker - DevOp? :::info All live codes can be found here: https://www.csie.ntu.edu.tw/~d00922011/java2/340/code/ ::: ## **Schedule** ### ++Warm Up++ - A quick review on OOP: [pdf](https://www.csie.ntu.edu.tw/~d00922011/java2/java2_oop.pdf) [stanford](https://web.stanford.edu/class/archive/cs/cs106a/cs106a.1152/lectures/Memory.pdf) - Java 面試 - JVM 的 Stack 和 Heap [link](https://blog.marklee.tw/java-interview-jvm-stack-heap/) - (FYR) Josh Ko, [物件導向編程精要](https://www.csie.ntu.edu.tw/~htlin/course/oop13spring/doc/EssentialOOP), 2007 ### ++Selected Design Patterns++ - Delegation and strategy pattern: [pdf](https://www.cs.colorado.edu/~kena/classes/5448/f12/lectures/07-designpatterns.pdf) [code](https://home.cs.colorado.edu/~kena/classes/5448/f12/code/lecture07examples.zip) - Bridge pattern, adapter pattern, proxy pattern, decorator pattern, factory method, and abstract factory pattern: [pdf](https://www.cs.colorado.edu/~kena/classes/5448/f12/lectures/10-strategybridgefactory.pdf) [code](https://home.cs.colorado.edu/~kena/classes/5448/f12/code/lecture10examples.zip) - Observer pattern, template method, state pattern, flyweight pattern: [pdf](https://home.cs.colorado.edu/~kena/classes/5448/f12/lectures/25-moredesignpatterns.pdf) [code](https://home.cs.colorado.edu/~kena/classes/5448/f12/code/lecture25examples.zip) - Model-View-Control (MVC) model [pdf](https://home.cs.colorado.edu/~kena/classes/5448/f12/lectures/27-patternsofpatterns.pdf) [code](https://home.cs.colorado.edu/~kena/classes/5448/f12/code/lecture27examples.zip) - (FYR) 深入淺出設計模式精簡版 [link](https://github.com/kib06277/Head-First-Design-Patterns) ### ++Advanced Java++ - Generics [pdf](https://courses.cs.washington.edu/courses/cse331/19au/lectures/lec13-generics.pdf) - More articles about generics: [link1](https://www.oracle.com/technical-resources/articles/java/juneau-generics.html) [link2](https://www.journaldev.com/1663/java-generics-example-method-class-interface) - (FYR) How to use wildcards [link](https://docs.oracle.com/javase/tutorial/java/generics/wildcardGuidelines.html) - Case study: comparable objects [code](https://www.csie.ntu.edu.tw/~d00922011/java2/ComparableDemo.zip) - Lambda expressions and Stream API [pdf](https://www.cs.cmu.edu/~charlie/courses/15-214/2014-fall/slides/26-java8.pdf) [code](https://www.csie.ntu.edu.tw/~d00922011/java2/StreamDemo.zip) - Marius Herring, [Java 8: No more loops](http://www.deadcoderising.com/Java-8-no-more-loops/), 2015.1.25 - Optional API: [link](http://www.oracle.com/technetwork/articles/java/java8-optional-2175753.html) - (FYR) More about lambdas - Ted Neward, [Java 8: lambdas part 1](https://www.oracle.com/technical-resources/articles/java/architect-lambdas-part1.html) and [Java 8: lambdas part 2](https://www.oracle.com/technetwork/articles/java/architect-lambdas-part2-2081439.html), Oracle, 2013 - Richard Warburton, Raoul Urma, and Mario Fusco, [Java 8 Lambdas - A Peek Under the Hood](https://www.infoq.com/articles/Java-8-Lambdas-A-Peek-Under-the-Hood/), 2014 - Case study - [ParallelStreamWordCount.java](https://www.csie.ntu.edu.tw/~d00922011/java2/ParallelStreamWordCount.java) with a text file [The King James Bible](http://www.gutenberg.org/cache/epub/10/pg10.txt) - (FYR) 林信良, [神秘的Monad不神秘](https://www.ithome.com.tw/voice/86448), 2014.4.11 - Reflection & annotation [pdf](https://userpages.uni-koblenz.de/~laemmel/pttcourse/slides/meta.pdf) [code](https://www.csie.ntu.edu.tw/~d00922011/java2/ReflectionDemo2.zip) - (FYR) Glen McCluskey, [Using Java Reflection](https://www.oracle.com/technical-resources/articles/java/javareflection.html), 1998 - (FYR) Jakob Jenkov, [Java Reflection - Arrays](http://tutorials.jenkov.com/java-reflection/arrays.html), 2014 - Case study - Unit test [code](https://www.csie.ntu.edu.tw/~d00922011/java2/TinyJUnitDemo.zip) - Dynamic proxy [link](http://tutorials.jenkov.com/java-reflection/dynamic-proxies.html) ### ++Concurrent Programming++ - Basics of operating systems (OS) - Jerry Breecher, <a href="https://web.cs.wpi.edu/~cs3013/c07/lectures/Section03-Processes.pdf">processes</a> and <a href="https://web.cs.wpi.edu/~cs3013/c07/lectures/Section04-Threads.pdf">threads</a> - (FYR) Jserv, <a href = "https://hackmd.io/@sysprog/linux-concepts">Linux 核心設計: 作業系統術語及概念</a>, 2020 - Remzi H. Arpaci-Dusseau and Andrea C. Arpaci-Dusseau, <a href = "http://pages.cs.wisc.edu/~remzi/OSTEP/">Operating Systems: Three Easy Pieces</a>, 2018 (online version) - (FYR) Virtual memory - Elaine's Blog , [CH8 記憶體管理 (Memory Management Strategies)](https://kim85326.github.io/2018/01/09/CH8-%E8%A8%98%E6%86%B6%E9%AB%94%E7%AE%A1%E7%90%86-(Memory-Management-Strategies)/), 2018.1.9 - Elaine's Blog , [CH9 虛擬記憶體管理 (Virtual-Memory Management)](https://kim85326.github.io/2018/01/09/CH9-%E8%99%9B%E6%93%AC%E8%A8%98%E6%86%B6%E9%AB%94%E7%AE%A1%E7%90%86-(Virtual-Memory-Management)/), 2018.1.9 - Translation lookaside buffer (TLB) https://en.wikipedia.org/wiki/Translation_lookaside_buffer - Java threads [pdf](https://www.csie.ntu.edu.tw/~d00922011/java2/multithreading/JavaThreads.pdf) - (FYR) Java concurreny tutorial [link](https://docs.oracle.com/javase/tutorial/essential/concurrency/) - Race condition: [code](https://www.csie.ntu.edu.tw/~d00922011/java2/multithreading/RaceConditionDemo.zip) - https://people.engr.tamu.edu/hlee42/csce314/lec17-JVM.pdf - Parallelism is always good? [code](https://www.csie.ntu.edu.tw/~d00922011/java2/multithreading/MapReduceDemo.java) and [Amdahl's law](https://en.wikipedia.org/wiki/Amdahl%27s_law)</li> - Application (feat. parallel stream) [code](https://www.csie.ntu.edu.tw/~d00922011/java2/multithreading/MonteCarloMultiThreadDemo.zip) - Sychronization [pdf](https://www.csie.ntu.edu.tw/~d00922011/java2/multithreading/Synchronisation.pdf) [code](https://www.csie.ntu.edu.tw/~d00922011/java2/multithreading/SemaphoreDemo.java) - Jserv, [作業系統概念: Concurrency 程式設計篇](https://youtu.be/3mkug2ygdIs) - Linus Torvalds, a reply to discussion about spinlock implementation and Linux scheduler ([1](https://www.realworldtech.com/forum/?threadid=189711&curpostid=189723), [2](https://www.realworldtech.com/forum/?threadid=189711&curpostid=189752), [3](https://www.realworldtech.com/forum/?threadid=189711&curpostid=189755), [4](https://www.realworldtech.com/forum/?threadid=189711&curpostid=189759)), 2020.1.3 (also read [news](https://www.ithome.com.tw/news/135226)) - (FYR) [How to implement synchronized methods/blocks in Java?](https://www.itread01.com/content/1544398054.html), 2018 - (FYR) [An Introduction to Lock-Free Programming](https://preshing.com/20120612/an-introduction-to-lock-free-programming/), 2012 - Concurrent application [pdf](https://www.csie.ntu.edu.tw/~d00922011/java2/multithreading/MultithradedServer.pdf) [code](https://www.csie.ntu.edu.tw/~d00922011/java2/multithreading/client_server_model_sample.zip) - More Java socket programming examples: [link](https://cs.lmu.edu/~ray/notes/javanetexamples/) - Java concurrency framework - Popcorny Lu, [Java 多執行緒的基本知識](https://popcornylu.gitbooks.io/java_multithread/content/) [code](https://www.csie.ntu.edu.tw/~d00922011/java2/multithreading/ConcurrentFramework.zip) - 20 Examples of Using Java’s CompletableFuture [link](https://dzone.com/articles/20-examples-of-using-javas-completablefuture) - Multi-Threading in Spring Boot Using CompletableFuture [link](https://dzone.com/articles/multi-threading-in-spring-boot-using-completablefu) - (FYR) Dmitry Aleksandrov, Programming the GPU in Java, 2020 [link](https://blogs.oracle.com/javamagazine/programming-the-gpu-in-java) ### ++Java Web: Introduction to Spring Framework++ - Introduction to Java EE [link](https://cw.fel.cvut.cz/b201/_media/courses/ear/lectures/lecture-01-intro-s.pdf) - https://javaee.github.io/javaee-spec/download/JavaEE8_Platform_Spec_FinalRelease.pdf - Introduction to Spring [link](https://cw.fel.cvut.cz/b201/_media/courses/ear/lectures/lecture-04-spring-s.pdf) - You could follow the course content [here](https://cw.fel.cvut.cz/b201/courses/ear/lectures/start). - Difference between Java EE and Spring Framework [link](https://www.educba.com/java-ee-vs-spring/) - Building an Application with Spring Boot [link](https://spring.io/guides/gs/spring-boot/) - Git: https://git-scm.com/docs/gittutorial - [W3C Schools](https://www.w3schools.com/) for HTML/CSS/JavaScript - ==https://github.com/Bakery-Jay/example/tree/master== - Databases - https://en.wikipedia.org/wiki/List_of_in-memory_databases - MySQL Tutorial [pdf](http://www.di.uniba.it/~cdamato/corsi/BasiDiDati-Materiale/Intro%20a%20MySQL.pdf) - [How to Use MySQL](https://hackmd.io/mJlsrhYCR_WfQ5FZ-tD8EQ) - (FYR) [MySQL by Examples for Beginners](https://www3.ntu.edu.sg/home/ehchua/programming/sql/MySQL_Beginner.html) - Linux server - [Ubuntu 20.04](https://ubuntu.com/#download) - [VirtualBox](https://www.virtualbox.org/) - [Short Note for Linux Commands](https://hackmd.io/@arthurzllu/HkvOPPCOD) - [How to Use vim and tmux?](https://hackmd.io/@arthurzllu/Syaafb-aw) - Virtualization - [How to Use Docker](/MquTvBXqR4eG4998xZ1Fuw) - http://www.cs.rpi.edu/academics/courses/spring21/csci4960/lecture_notes.html ### ++Data Structures & Algorithms++ - See [Algorithm Labs](https://hackmd.io/@arthurzllu/SkZBc7GoI). #### Gradebook <center> <iframe src="https://docs.google.com/spreadsheets/d/e/2PACX-1vTF-4AZbjJ9m1rT1IRuGC5A62FhR35trPtvM0vp2a4s1MzRxbcTnvr7U5JNA8mhJheyt5HWaK3M35Lb/pubhtml?gid=336629147&amp;single=true&amp;widget=true&amp;headers=false" width = "800px" height = "500px"></iframe> </center> ## **References** ### ++Java++ - Raoul-Gabriel Urma, Mario Fusco, Alan Mycroft, <a href="https://www.manning.com/books/modern-java-in-action">Modern Java in Action</a>, 2018 ![](https://i.imgur.com/T5MAJMF.png =100x) - Patrick Niemeyer and Daniel Leuck, <a href = "https://www.oreilly.com/library/view/learning-java-5th/9781492056263/">Learning Java</a>, 5/e, 2020 ![](https://i.imgur.com/1vomEDv.png =100x) - Benjamin J Evans and David Flanagan, <a href="http://shop.oreilly.com/product/0636920030775.do">Java in a Nutshell</a>, 6/e, 2014 ![](https://i.imgur.com/gvdEjcw.png =100x) - Joshua Bloch, <a href="https://www.amazon.com/Effective-Java-Joshua-Bloch/dp/0134685997">Effective Java</a>, 3/e, 2018 ([note](https://github.com/ekis/effective-java-3rd-edition)) ![](https://i.imgur.com/w2Cd3eo.png =100x) - Scott Oaks, <a href="http://shop.oreilly.com/product/0636920028499.do">Java Performance: The Definitive Guide</a>, 2014 ![](https://i.imgur.com/wl2K3Hg.png =100x) ### ++Design Patterns++ - Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides, Grady Booch, [Design Patterns: Elements of Reusable Object-Oriented Software](https://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented-ebook/dp/B000SEIBB8), 1994 ![](https://i.imgur.com/i5MbOYr.png =100x) - Eric Freeman and Elisabeth Robson, [Head First Design Patterns: Building Extensible and Maintainable Object-Oriented Software](https://www.amazon.com/Head-First-Design-Patterns-Object-Oriented/dp/149207800X/), 2/e, 2020 ([code](https://resources.oreilly.com/examples/9780596007126)) ![](https://i.imgur.com/Bzp4VGs.png =120x) - Robert C. Martin, [Agile Software Development, Principles, Patterns, and Practices](https://www.amazon.com/Software-Development-Principles-Patterns-Practices/dp/0135974445), 2005 ![](https://i.imgur.com/d89wcG2.png =100x) - Alexander Shvets, Gerhard Frey, and Marina Pavlova, [Dive Into Design Patterns](https://sourcemaking.com/design-patterns-ebook), 2018 ![](https://i.imgur.com/zpAUht2.png =100x) - 蔡昇達, [設計模式與遊戲開發的完美結合](https://www.books.com.tw/products/0010703628), 2016 ([github](https://github.com/sttsai/PBaseDefense_Unity3D)) ![](https://i.imgur.com/f34cvmr.png =140x) - Kenneth M. Anderson, [Object-Oriented Analysis & Design](https://www.cs.colorado.edu/~kena/classes/5448/f12/), Department of Computer Science, University of Colorado, 2012fa - Zach Tatlock, [CSE 331: Software Design and Implementation](https://courses.cs.washington.edu/courses/cse331/17wi/), Computer Science & Engineering, University of Washington, 2017 winter - Max Goldman and Armando Solar-Lezama, [6.005: Software Construction](http://web.mit.edu/6.005/www/fa16/), EECS, Massachusetts Institute of Technology, 2016fa - Josh Bloch and Charlie Garrod, [Principles of Software Construction: Objects, Design, and Concurrency](http://www.cs.cmu.edu/~charlie/courses/15-214/2016-fall/), Carnegie Mellon School of Computer Science, 2016fa - Stephen Wong, [Comp310: Advanced Object-Oriented Programming and Design](https://www.clear.rice.edu/comp310/s19/), Rice University, 2019sp - Andrew Myers, [CS 2112: Object-Oriented Design and Data Structures - Honors](http://www.cs.cornell.edu/courses/cs2112/), Department of Computer Science, Cornell University, 2020 ### ++Concurrent Programming++ - Brian Goetz, [Java Concurrency in Practice](https://www.amazon.com/Java-Concurrency-Practice-Brian-Goetz/dp/0321349601), 2006 ![](https://i.imgur.com/syDGooT.png =100x) - Maurice Herlihy, Nir Shavit, Victor Luchangco, and Michael Spear, [The Art of Multiprocessor Programming](https://www.amazon.com/Art-Multiprocessor-Programming-Maurice-Herlihy/dp/0124159508/), 2/e, 2020 ![](https://i.imgur.com/XC22Jsp.png =110x) - Carlo A. Furia, [Concurrent Programming - TDA383/DIT390](http://www.cse.chalmers.se/edu/year/2016/course/TDA383_LP3/), Chalmers University of Technology, 2017 - Shan He, [SSC: Networks/Concurrency 2014/2015](https://www.cs.bham.ac.uk/~szh/teaching/ssc/), School of Computer Science, University of Birmingham - Jeff Preshing, [An Introduction to Lock-Free Programming](https://preshing.com/20120612/an-introduction-to-lock-free-programming/), 2012 - Liam O'Connor, [COMP3151/9154 Foundations of Concurrency](http://www.cse.unsw.edu.au/~cs3151/20T2/), 2020 #### Operating System - https://www.linux.org/ ![](https://i.imgur.com/tRyM5V8.png) - Jserv, [Linux Kernel Internals](http://wiki.csie.ncku.edu.tw/linux/schedule), NCKU [fb](https://www.facebook.com/groups/system.software2021/) ### ++Spring Framework++ - Rod Johnson, [Expert One-on-One J2EE Design and Development](https://www.amazon.com/Expert-One-One-Design-Development/dp/0764543857), 2002 ==father of Spring== ![](https://i.imgur.com/Mmmn2aR.png =100x) - https://spring.io/projects/spring-framework ![](https://i.imgur.com/F0D0iwC.png) - Iuliana Cosmina, Rob Harrop, Chris Schaefer, Clarence Ho, [Pro Spring 5](https://www.apress.com/gp/book/9781484228074), 5/e, 2017 ![](https://i.imgur.com/RI0NAyl.png =100x) #### Spring Boot - Craig Walls, [Spring Boot in Action](https://www.manning.com/books/spring-boot-in-action), 2015 ![](https://i.imgur.com/mAYKhsd.png =100x) - M.K Yong, [Spring Boot Tutorials](https://mkyong.com/tutorials/spring-boot-tutorials/), 2019 #### Dependency Management - http://maven.apache.org/ ![](https://i.imgur.com/qLTHlJb.png =100x) - https://gradle.org/ ![](https://i.imgur.com/jgFmkPT.png) #### Database - Abraham Silberschatz, Henry Korth, and S. Sudarshan, [Database System Concepts](https://www.amazon.com/Database-System-Concepts-Computer-Science/dp/0073523321), 6/e, 2010 ![](https://i.imgur.com/ybQi2Li.png =100x) - Donnie Pinkston, [Introduction to Relational Database Systems](http://users.cms.caltech.edu/~donnie/cs121/), Caltech Computer Science, 2018fa - Markus Krötzsch, [Database Theory, International Center for Computational Logic](https://iccl.inf.tu-dresden.de/web/Foundations_of_Databases_and_Query_Languages_(SS2015)/en), TU Dresden, 2015 - Andy Pavlo, [15-445/645 DATABASE SYSTEMS](https://15445.courses.cs.cmu.edu/fall2020/), Carnegie Mellon University, 2020fa - MySQL https://www.mysql.com/ ![](https://i.imgur.com/unxXFyR.png =100x) - PostgreSQL https://www.postgresql.org/ ![](https://i.imgur.com/IeottwR.png =80x) - InfluxDB https://www.influxdata.com/ ![](https://i.imgur.com/OWJVUsL.png) - DBeaver https://dbeaver.io/ ![](https://i.imgur.com/08k4aXl.png =100x) #### Case Study * Open source e-commerce in Java https://www.shopizer.com/ ![](https://i.imgur.com/AwH7SBZ.png =200x) * A complete online judge from China https://sduoj.online/