You need, currently, it seems, Java 1.8. You need the development kit "JDK" not the runtime environment "JRE."
If you have it you'll see the jdk1.8
blahblah shown here. You'd think they'd put Java in the package name, and yes, they used to. But no more, so grep'ing for java
will only find old versions.
rpm -qa |grep jdk
jdk1.8-1.8.0_191-fcs.x86_64
java-1_6_0-openjdk-plugin-1.6.0.0_b20.1.9.7-1.2.1.x86_64
java-1_6_0-openjdk-1.6.0.0_b20.1.9.7-1.2.1.x86_64
If not, java.com is NOT the answer--they have only the JRE it seems. Their search tool doesn't return the link you need in the top ten results with "JDK" or "download JDK 8". But Google finds it on the first hit, currently: https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
Get the x64 version for 64-bit, x86 version for 32-bit.
Firefox has a built-in installer for RPMs. If you let it install, you'll get a dialog called Downloads (informational only; close); Installation Summary (hit Finish). You'll be prompted for root password, which I don't find comforting.
Or, you can just save the RPM file anywhere, then run as root (substituting your file name)
rpm -ivh wherever/jre-8u191-linux-x64.rpm
As it runs, it will output (among other things) the package name. For further rpm commands, you use this package name, not the file name. (If you try rpm -q filename
, or rpm -e filename
, it tells you file name isn't installed, which is confusing if rpm -ivh
seemed to just tell you it was installed!)
Now where did it install the tools you need?
> rpm -ql jdk1.8-1.8.0_191-fcs.x86_64 | grep 'bin/java$'
/usr/java/jdk1.8.0_191-amd64/bin/java
/usr/java/jdk1.8.0_191-amd64/jre/bin/java
If you see them there you can delete the RPM file.
OK, it's in /usr/java/jdk1.8.0_191-amd64 . Add /usr/java/jdk1.8.0_191-amd64/bin to your PATH in your .cshrc or what have you and re-source it.
> java -version
java version "1.8.0_191"
Java(TM) SE Runtime Environment (build 1.8.0_191-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.191-b12, mixed mode)
> javac -version
javac 1.8.0_191
Great, we see 1.8!
Java keeps source code in .java files, one file per class. Those are read by the compiler, which outputs bytecode in .class files. Those then can be run.
Put this in a file called HelloWorld.java
:
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World");
}
}
In that directory, type the following. They should succeed without further output.
> javac HelloWorld.java
> java HelloWorld
You should then see the Hello, World
output.
The above may need a -cp .
or -cp ./
option.
As to bootstrapping up the learning curve:
- The line-to-line syntax is mostly like C++.
- There is no explicit "include" syntax needed; you can refer to
public classes in the same directory by name.
- public classes must have the name of their file, but a file may contain additional private classes.
- it's accurate enough as you get started to think that everything that looks like an C++ object (Thing thing) is really implemented as a pointer to a reference-counted object. The "." is like C++ "->".
- There's no passing of atomic variables by reference; always by value (int boolean double etc.)
- String is a middle ground between value and reference
- objects are passed by reference, thought the "reference" to them is being passed by value.
Method( Thing thing )
in Java is like calling Method( Thing* pthing )
in C++. Method()
's change to thing
/pthing
itself doesn't affect the caller, but thing.field
/pthing->field
changes are global.
- For more specific questions, Google should find everything you need.