Changes

Jump to navigation Jump to search
433 bytes added ,  08:19, 28 April 2022
m
Line 3: Line 3:  
===With apt===
 
===With apt===
 
  <nowiki>sudo apt-add-repository ppa:webupd8team/java
 
  <nowiki>sudo apt-add-repository ppa:webupd8team/java
                                        sudo apt-get update
+
                                        sudo apt-get update
                                        sudo apt-get install oracle-java8-installer</nowiki>
+
                                        sudo apt-get install oracle-java8-installer</nowiki>
    
Also ensure your JAVA_HOME variable has been set to:
 
Also ensure your JAVA_HOME variable has been set to:
Line 974: Line 974:  
}
 
}
 
}</source>
 
}</source>
 +
 +
=== Try with resources (similar to python with) ===
 +
<syntaxhighlight lang="java">
 +
import java.util.Scanner;
 +
 +
public class TryWithResourcesRunner {
 +
    public static void main(String[] args){
 +
        try (Scanner scanner = new Scanner(System.in)){
 +
            int[] numbers = {12, 3, 4, 5};
 +
            int number = numbers[21];
 +
        }
 +
    // this will throw an exception but scanner will be closed
 +
    }
 +
}
 +
</syntaxhighlight>
 +
 
===Runtime exceptions===
 
===Runtime exceptions===
 
The compiler does not force you to handle them.
 
The compiler does not force you to handle them.

Navigation menu