I landed in the Java universe again, after evolving through a few JavaScript frameworks and a bit of C++ and a ton of Python. I had given up on Java sometime in the past and I don't really know why.
The Java Buzzwords
I used the Java SE Development Kit (JDK) 8 (developer version 1.8) by Oracle. OpenJDK is the same sans proprietary issues. Once past that, I set the environment variables JAVA_HOME
and PATH
to point to the directories where the binaries of the Java toolchain reside.
Personal Preference. VS Code as an editor and IntelliJ IDEA as an IDE are great choices. I use both
Executing java -version && javac -version
outputs whatever is given below:
$ java -version && javac -version
java version "1.8.0_231"
Java(TM) SE Runtime Environment (build 1.8.0_231-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.231-b11, mixed mode)
javac 1.8.0_231
Overview
Here's a flowchart!
I wrote text file with a .java
extension containing some lines of code and compilde it to Java Bytecode with the javac
compiler. Compilation resulted in a binary .class
file that will be used for interpretation.
The .class
file is loaded to the Java Virtual Machine using a Class Loader in the JVM. The .class
files are vulnerable and using a hex editor, an attacker can change the behaviour of a program. To overcome this issue, the bytecode is then verified using the Bytecode Verifier in the JVM. The Java Just-In-Time (JIT) Compiler or Runtime Interpreter then interprets the bytecode and produces machine code depending on the system architecture which can then be loaded into memory for execution.
Here's how a "Hello, World!" would look like in Java. Classes, I know, yes, there is some overhead involved but walk along. And yes, it is a little verbose.
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
But I should add comments! So the final source code could be something like:
// HelloWorld.java
/**
* Hello World Application
* @author sudipto@ghosh.pro
*/
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
To compile my HelloWorld.java
file to bytecode, I ran the javac
compiler with a CLI argument.
$ javac HelloWorld.java
This created a HelloWorld.class
file in the same directory. Opening it in a text editor was not of much use as it is a binary file but you can surely see a few symbols here and there.
Using the Java Class File Disassembler, we can see some interpreted assembly code. To view that, I used the javap
tool in the JDK. Running javap -c HelloWorld
outputted some code which also points to the fact that if there is no default constructor, the compiler puts it there!
To load my HelloWorld.class
into the JVM and execute it, I invoked java
with a command-line argument that matches the base name of the .class
file.
$ java HelloWorld
Once this command was executed, the message Hello, World!
correctly printed onto the screen, technically console.
I referred to Java: The Complete Reference (9th ed.) by Herbert Schildt and the Oracle documentation for getting around the intricacies of the language.
A basic text editor that can open and save text files. It also features a word counter and character counter. Learnt about StringTokenizer
, FileReader
, FileWriter
, BufferredReader
, BufferredWriter
and StringBuilder
. The GUI was designed with Swing and the IntelliJ IDEA GUI Designer.
Used the SQLite JDBC Driver to interface with a database and manage customers, inventory items and process orders of a dummy store. The GUI was designed with Swing and the IntelliJ IDEA GUI Designer. Had to struggle a bit with JTable
but figured it out at last.
Special thanks to our guest blogger Sudipto Ghosh for his contribution to the Ronald James Blog this week.
Visit the original link for this blog here.
We are a leading niche digital & tech recruitment specialist for the North East of England. We Specialise in the acquisition of high-performing technology talent across a variety of IT sectors including Digital & Technology Software Development.
Our ultimate goal is to make a positive impact on every client and candidate we serve - from the initial call and introduction, right up to the final delivery, we want our clients and candidates to feel they have had a beneficial and productive experience.
If you’re looking to start your journey in sourcing talent or find your dream job, you’ll need a passionate, motivated team of experts to guide you. Check out our Jobs page for open vacancies. If interested, contact us or call 0191 620 0123 for a quick chat with our team.
Follow us on our blog, Facebook, LinkedIn, Twitter or Instagram to follow industry news, events, success stories and new blogs releases.
Back to Blog