What are arrays in java?
An array is an object containing a fixed number of values of the same type
What are varargs?
What is the disadvantage of varargs?
They can lead to Heap Pollution
What does the static keyword mean?
The static keyword means that the particular member belongs to a type itself, rather than to an instance of that type
What is important about static fields (class variables)?
A SINGLE copy of that field is created and shared among all instances of that class, this static variable is stored in the heap memory
When to use static fields?
What is important about static methods?
When to use static methods?
Static methods are used to access or manipulate static variables and other static methods that do not depend upon objects; static methods are widely used in utility and helper classes
What is the benefit of static classes?
A static class allows to create a class within a class and provides a way of grouping elements that are only used in one place -> keeps the code more organized and readable
In what two types can nested class architecture be divided?
What is the difference between inner classes and static nested classes?
Inner classes have access to all members of the enclosing class, whereas static nested classes only have access to static members of the outer class
Why to use static nested classes?
What are enums?
What are implementation design patterns using enums?
What does the final keyword mean?
What is the aim of generics?
The aim of generics is to reduce bugs and add an extra layer of abstraction over types
When are generics useful?
Generics are useful if you would run into a code duplication like e.g. an IntegerPrinter class or a StringPrinter class where all classes would hold the exact same code only the types of the variables would be different -> What we want is one class that is flexible for many different types
What are generic wildcards?
Todo is to print a list containing any type of thing -> Use a ? as a type parameter in the angle brackets
What is one restriction of generics in java?
One restriction is that the type parameter cannot be a primitive type, because generics are a compile-time feature, meaning the type parameter is erased and all generic types are implemented as type object
How to read and write user input in java?
What are checked exceptions?
What are unchecked exceptions?
What are common unchecked exceptions?
NullpointerException, ArrayIndexOutOfBoundsException and IllegalArgumentException
How to remember when to use checked and unchecked exceptions?
If a client can reasonably be expected to recover from an exception, make it a checked exception. If a client cannot do anything to recover from the exception, make it an unchecked exception