Java

Annotations
Collections
Exception Handling
Flow of control
Garbage Collection
Generics
Interfaces and Inheritance
IO
Java Type System
Lambdas
Questions
.https://docs.oracle.com/javase/tutorial/java/generics/bounded.html
Weak reference
.https://docs.oracle.com/javase/8/docs/api/java/lang/ref/WeakReference.html
public class Main {
  public static void main(String[] args) {
    System.out.print("hi");
  }
  static { System.out.print("how"); }    
}
// howhiReflection
.https://www.oracle.com/technical-resources/articles/java/javareflection.html
import java.lang.reflect.*;
   public class Main {
      private int f1(
       Object p, int x) throws NullPointerException
      {
         if (p == null)
            throw new NullPointerException();
         return x;
      }
      public static void main(String args[])
      {
         try {
           Class cls = Class.forName("Main");
            Method methlist[] 
              = cls.getDeclaredMethods();
            for (int i = 0; i < methlist.length;
               i++) {  
               Method m = methlist[i];
               System.out.println("name = " + m.getName());
               System.out.println("decl class = " +
                              m.getDeclaringClass());
               Class pvec[] = m.getParameterTypes();
               for (int j = 0; j < pvec.length; j++)
                  System.out.println("param #" + j + " " + pvec[j]);
               Class evec[] = m.getExceptionTypes();
               for (int j = 0; j < evec.length; j++)
                  System.out.println("exc #" + j 
                    + " " + evec[j]);
               System.out.println("return type = " +
                                  m.getReturnType());
               System.out.println("-----");
            }
         }
         catch (Throwable e) {
            System.err.println(e);
         }
      }
   }
// name = main
// decl class = class Main
// param #0 class [Ljava.lang.String;
// return type = void
// -----
// name = f1
// decl class = class Main
// param #0 class java.lang.Object
// param #1 int
// exc #0 class java.lang.NullPointerException
// return type = int
// -----StringBuffer and StringBuilder
.https://docs.oracle.com/javase/tutorial/essential/exceptions/runtime.html``
// x byte
// y int
z = x/y * 2.0;You want subclasses in any package to have access to members of a superclass. Which is the most restrictive access that accomplishes this objective?
Polymorphism, Typecasting, Encapsulation, or Abstraction?
Object.wait() method does?
Interface vs Abstract?
Lambda Expressions
.https://docs.oracle.com/javase/tutorial/java/javaOO/lambdaexpressions.html
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
public class StoreInventory {
    Set<String> superCycleSet = new TreeSet<>();
    List<String> myStoreList = new ArrayList<>();
    public StoreInventory() {
        myStoreList.add("Bicycle");
        myStoreList.add("Tricycle");
        myStoreList.add("Scooter");
    }
    public void printStoreInventory() {
        myStoreList.forEach(i -> System.out.println("My Store item: " + i));
    }
}import java.util.Map;
import java.util.TreeMap;
public class FruitStand {
    private Map<String, Integer> prices = new TreeMap<>();
    public FruitStand(){
        prices.put("Apple", 1);
        prices.put("Avocado", 2);
        prices.put("Banana", 1);
        prices.put("Mango", 2);
        prices.put("Starfruit", 4);
    }
    public void printPrices() {
        prices.forEach((key, value) -> System.out.println("Fruit: " + key + ", $" + value));
    }
}public class MultithreadApp {
    Thread thread1;
    Thread thread2;
    public MultithreadApp() {
        thread1 = new Thread(new Runnable() {
            @Override
            public void run(){
                System.out.println("Thread #1 is running");
            }
        });
        // Task 1
        thread2 = new Thread(() -> System.out.println("Thread #2 is running"));
    }
    public void startThreads() {
        thread1.start();
        // Task 2
        thread2.start();
    }
}Last updated
Was this helpful?