Java

Revision as of 16:44, 31 January 2022 by David (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
\( \newcommand{\P}[]{\unicode{xB6}} \newcommand{\AA}[]{\unicode{x212B}} \newcommand{\empty}[]{\emptyset} \newcommand{\O}[]{\emptyset} \newcommand{\Alpha}[]{Α} \newcommand{\Beta}[]{Β} \newcommand{\Epsilon}[]{Ε} \newcommand{\Iota}[]{Ι} \newcommand{\Kappa}[]{Κ} \newcommand{\Rho}[]{Ρ} \newcommand{\Tau}[]{Τ} \newcommand{\Zeta}[]{Ζ} \newcommand{\Mu}[]{\unicode{x039C}} \newcommand{\Chi}[]{Χ} \newcommand{\Eta}[]{\unicode{x0397}} \newcommand{\Nu}[]{\unicode{x039D}} \newcommand{\Omicron}[]{\unicode{x039F}} \DeclareMathOperator{\sgn}{sgn} \def\oiint{\mathop{\vcenter{\mathchoice{\huge\unicode{x222F}\,}{\unicode{x222F}}{\unicode{x222F}}{\unicode{x222F}}}\,}\nolimits} \def\oiiint{\mathop{\vcenter{\mathchoice{\huge\unicode{x2230}\,}{\unicode{x2230}}{\unicode{x2230}}{\unicode{x2230}}}\,}\nolimits} \)

Java is a popular object-oriented programming language taught in many high-schools and introductory computer science courses. Java programs (.java) are compiled into Java bytecode (.class) files which are then interpreted by the Java virtual machine (JVM). Java programs and libraries (both .java and .class files) can be bundled into a Java archive (.jar) file. These are zip files with a manifest. 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

Installation

I recommend downloading an IDE such as Intellij IDEA.

Linux

I recommend using OpenJDK.
Link

Features

AutoCloseable

StackOverflow Reference
AutoCloseable Java 8
Since Java does not have destructors and thus no RAII objects, you will need to close any resources 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