I’ve only ever heard bad things about Java so I have steered clear of it. But, I will tell you one thing, Java’s BigInteger is nice and easy and very powerful for calculations with very large numbers.
Now that I’m spending more time with Java, I wanted to jot down a few things that I’ve learned along the way.
What I like About Java
It’s an Object-Oriented Programming
While I can handle and adapt to a flat structure consisting primarily of variables passed around and functions that have to be created to extend functionality and called to process a selection of data, being object-oriented seems to keep things more modular, cleaner, and extensible. If given an opportunity to interact with OOP I won’t shy away from it.
Low Effort Requirement to Get a Program Up and Running
If I need to whip something up, I’ll use either Python, Bash, or Java. If I want to perform simple admin tasks, Bash works just fine. If I need to perform somewhat more complex HTTP/S requests, Python works well. If I need more complex structures and decent performance, Java can let you put things together rather quickly.
Command Line Arguments
Still parsing this information myself. Looks like I ought to try JCommander
Importing Packages
You may run into this when you’re working on a Java project:
SmallProjectThree.java:8: error: package org.bouncycastle.math.ec does not exist
This means your environment is not familiar with a package called bouncycastle.math.ec
. The reason this error is thrown is because I am attempting to do some Elliptic-curve calculations and am using a snippet from im-infamou5 on GitHub.com
In general, to use a non-standard library, you need to find the *.jar
file yourself, download it, and drop it in your CLASSPATH
(if this doesn’t exist or you want to redefine it, you can do so; see -cp
below)
Specific to Bouncy Castle, these are the steps I took.
- Download the
.jar
file from the org’s download page directly. Now, there are a ton of options available to you on that page.- Trust but verify. I recommend using signed jar files so you can digitally trust the source. Once the package has been downloaded check the sha hash.
- What JDK is installed on your system? Your system probably has Java installed (java -version) but the JDK is separate. Only one Java can exist but several JDKs can exist (in a given environment at a time). I am currently running Java build
13.0.2+8
and have13.0.3
and1.8.0_241
JDK present on my system. I am downloading JDK14
and dropping it into the same directory.-
$ java -version java version "13.0.2" 2020-01-14 Java(TM) SE Runtime Environment (build 13.0.2+8) Java HotSpot(TM) 64-Bit Server VM (build 13.0.2+8, mixed mode, sharing)
-
$ pwd /System/Volumes/Data/Library/Java/JavaVirtualMachines $ ls jdk-13.0.2.jdk jdk-14.jdk jdk1.8.0_241.jdk
-
- Which .jar file do you need? I looked through the documentation and found that the “provider” had the math.ec library so I need the “provider” .jar
- Add the
*.jar
file to my project’s directory tree.- Download it to the same directory that contains my
SmallProject3.java
program.
- Download it to the same directory that contains my
- Compile my program using
-cp
or--classpath
-
$ javac -cp ./org/bouncycastle/bcprov-jdk14-164.jar SmallProjectThree.java
MAKEFILE
An expert in neither Java nor Make dropped this off.
JAVAC=javac JAVA=java sources = $(wildcard *.java) classes = $(sources:.java=.class) all : $(classes) run : all $(JAVA) PrimitiveRoots clean : rm -f *.class %.class : %.java $(JAVAC) $<