Java: Difference between revisions
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
Java is a popular object-oriented programming language. | Java is a popular object-oriented programming language taught in many high-schools and introductory computer science courses. | ||
Java programs (.java or .jar for java archive) are compiled into Java bytecode (.class) files which are then interpreted by the Java virtual machine (JVM). To run Java programs, you will need to get the JVM by installing the Java runtime environment (JRE) or the Java development kit (JDK). | |||
==Usage== | ==Usage== |
Revision as of 13:11, 1 November 2019
Java is a popular object-oriented programming language taught in many high-schools and introductory computer science courses. Java programs (.java or .jar for java archive) are compiled into Java bytecode (.class) files which are then interpreted by the Java virtual machine (JVM). To run Java programs, you will need to get the JVM by installing the Java runtime environment (JRE) or the Java development kit (JDK).
Usage
Features
AutoCloseable
StackOverflow Reference
AutoCloseable Java 8
Since Java does not have destructors and thus no RAII objects, you will need to close anything you open manually.
One way to automate this is to use autocloseable classes introduced in Java 7.
These classes, which implement that AutoCloseable interface, can be wrapped in a try block
This is similar to using
in Python and C#.
try (Scanner scanner = new Scanner(s)) {
while (scanner.hasNext()) {
// do something
}
} // close will be implicitly called