Began java section

This commit is contained in:
2025-03-25 10:23:34 -04:00
parent f619093d76
commit 6ff585e133
4 changed files with 56 additions and 8 deletions

View File

@@ -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
```

View File

@@ -0,0 +1,36 @@
# Interfaces
## Common Interfaces to Implement
### Comparator
Compares two instances of a class.
```java
class StudentGPAComparator implements Comparator<Student> {
@Override
public int compare(Student o1, Student o2) {
return (o1.gpa + o1.name).compareTo(o2.gpa + o2.name);
}
}
public static void main() {
Comparator<Student> 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<Student> {
@Override
public int compareTo(Student o) {
return this.name.compareTo(o.name);
}
}
```

View File

@@ -0,0 +1 @@
# Types

View File

@@ -1,9 +1,11 @@
[
{
"text": "Basics",
"items": [
{ "text": "Introduction", "link": "/java/" }
]
}
]
{
"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" }
]
}
]