diff --git a/docs/java/basics/classes.md b/docs/java/basics/classes.md new file mode 100644 index 0000000..16fb492 --- /dev/null +++ b/docs/java/basics/classes.md @@ -0,0 +1,9 @@ +# Classes + +## Generics + +Generics allow you to create a class that can hold many different kinds of data types, and specify an upper bound for what kind of interfaces are allowed to be stored and manipulated. + +```java + +``` diff --git a/docs/java/basics/interfaces.md b/docs/java/basics/interfaces.md new file mode 100644 index 0000000..5e61224 --- /dev/null +++ b/docs/java/basics/interfaces.md @@ -0,0 +1,36 @@ +# Interfaces + +## Common Interfaces to Implement + +### Comparator + +Compares two instances of a class. + +```java +class StudentGPAComparator implements Comparator { + @Override + public int compare(Student o1, Student o2) { + return (o1.gpa + o1.name).compareTo(o2.gpa + o2.name); + } +} + +public static void main() { + Comparator gpaSorter = new StudentGPAComparator(); + Arrays.sort(students, gpaSorter); + Arrays.sort(students, gpaSorter.reversed()); +} + +``` + +### Comparable + +Similar to Comparator, except this is implemented directly on the classes you are comparing. Without specificing a type, you will receive an `Object` to your `compareTo` function. + +```java +class Student implements Comparable { + @Override + public int compareTo(Student o) { + return this.name.compareTo(o.name); + } +} +``` diff --git a/docs/java/basics/types.md b/docs/java/basics/types.md new file mode 100644 index 0000000..f54cd23 --- /dev/null +++ b/docs/java/basics/types.md @@ -0,0 +1 @@ +# Types diff --git a/docs/java/sidebar.json b/docs/java/sidebar.json index 32bf35d..e5b3e84 100644 --- a/docs/java/sidebar.json +++ b/docs/java/sidebar.json @@ -1,9 +1,11 @@ [ - { - "text": "Basics", - "items": [ - { "text": "Introduction", "link": "/java/" } - ] - } - ] - \ No newline at end of file + { + "text": "Basics", + "items": [ + { "text": "Introduction", "link": "/java/" }, + { "text": "Types", "link": "/java/basics/types" }, + { "text": "Classes", "link": "/java/basics/classes" }, + { "text": "Interfaces", "link": "/java/basics/interfaces" } + ] + } +]