or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Do you want to remove this version name and description?
Syncing
xxxxxxxxxx
Week 6
Java: Generics
Box
class allows you to define what type of elements will be put in the Box. For example, you can instantiate aBox
object to keepInteger
elements so that any attempt to put a non-Integer
object in thatBox
object will result in a compile error.Box
class from within your code, you must perform a generic type invocation, which replacesT
with some concrete value, such as Integer. It is similar to an ordinary method invocation, but instead of passing an argument to a method, you are passing a type argument enclosed within angle brackets — e.g., <Integer> or <String, Integer> — to the generic class itself. Note that in some cases you can omit the type parameter i.e., <> if the type parameter can be inferred from the context.Java: Collections
Interfaces: These are abstract data types that represent collections. Interfaces allow collections to be manipulated independently of the details of their representation.
List<E>
interface can be used to manipulate list-like collections which may be implemented in different ways such asArrayList<E>
orLinkedList<E>
.Implementations: These are the concrete implementations of the collection interfaces. In essence, they are reusable data structures.
ArrayList<E>
class implements theList<E>
interface while theHashMap<K, V>
class implements theMap<K, V>
interface.Algorithms: These are the methods that perform useful computations, such as searching and sorting, on objects that implement collection interfaces. The algorithms are said to be polymorphic: that is, the same method can be used on many different implementations of the appropriate collection interface.
sort(List<E>)
method can sort a collection that implements theList<E>
interface.Collection — the root of the collection hierarchy. A collection represents a group of objects known as its elements. The Collection interface is the least common denominator that all collections implement and is used to pass collections around and to manipulate them when maximum generality is desired. Some types of collections allow duplicate elements, and others do not. Some are ordered and others are unordered. The Java platform doesn't provide any direct implementations of this interface but provides implementations of more specific subinterfaces, such as Set and List. Also see the Collection API.
Set — a collection that cannot contain duplicate elements. This interface models the mathematical set abstraction and is used to represent sets, such as the cards comprising a poker hand, the courses making up a student's schedule, or the processes running on a machine. Also see the Set API.
List — an ordered collection (sometimes called a sequence). Lists can contain duplicate elements. The user of a List generally has precise control over where in the list each element is inserted and can access elements by their integer index (position). Also see the List API.
Queue — a collection used to hold multiple elements prior to processing. Besides basic Collection operations, a Queue provides additional insertion, extraction, and inspection operations. Also see the Queue API.
Map — an object that maps keys to values. A Map cannot contain duplicate keys; each key can map to at most one value. Also see the Map API.
Others: Deque, SortedSet, SortedMap
The
ArrayList
Class:ArrayList
class is a resizable-array implementation of theList
interface.->
The
HashMap
Class:HashMap
is an implementation of theMap
interface. It allows you to store a collection of key-value pairs.->
Java: File Access
java.io.File
class to represent a file object. It can be used to access properties of the file object.->
Scanner
object that uses a File object as the source of data.->
java.io.FileWriter
object to write to a file.->
FileWriter
object that appends to the file (instead of overwriting the current content) by specifying an additional boolean parameter to the constructor.java.nio.file.Files
is a utility class that provides several useful file operations. It relies on thejava.nio.file.Paths
file to generate Path objects that represent file paths.Java: JAR Files
Java applications are typically delivered as JAR (short for Java Archive) files. A JAR contains Java classes and other resources (icons, media files, etc.).
An executable JAR file can be launched using the java -jar command.
Requirements: Intro
Requirements: Specifying
IDEs: Intermediate Features