Java 9 Key Features ( Module System, JShell, JVM Performance )
Alright, Java developers, buckle up—because Java 9 wasn’t just another version with a couple of bug fixes and small tweaks.
Java 9 was all about taking Java to the next level with modularity, interactive development, and some serious performance boosts. So let’s break down these features, and I promise we’ll make them fun and simple to grasp!
Overview
├── 📦 Java 9 (2017)
│ ├── 📦 Module System
│ │ ├── 🔧 Project Jigsaw
│ │ └── 🔍 Modularization (JEP 193)
│ ├── 💻 JShell (Interactive REPL)
│ └── 🚀 Improved JVM Performance
Module System – Project Jigsaw 🧩
Imagine your Java application is a cool city, and inside this city, you’ve got different districts: a district for your user services, another one for your database logic, maybe even a district for security features. In the past, Java was like one big, unorganized city—everything was mixed together and you had to drag around the entire city just to get to the district you needed.
But Java 9 comes in like the Urban Planner of your dreams 🏙️. Enter Project Jigsaw, which splits the big city (the JDK) into smaller, more manageable districts (aka modules). Each district (or module) focuses on a specific area of functionality. Now, instead of bringing the entire city with you, you can grab just the district you need. 😎
This modularization makes your Java apps more efficient because you only import what you need and keep the weight down. You don’t need to carry around the whole city to just visit the user services district!
Example: How Does It Work?
Now, let’s take a look at how this actually works in code:
module com.myapp {
requires java.base; // This module requires the 'java.base' module (the core of Java)
exports com.myapp.services; // This module "exports" the 'services' package for use outside
}
breakdown:
module com.myapp
: This is where you declare your module—basically, you're saying, "Hey, this is my module, and it's calledcom.myapp
."requires java.base;
: This is saying, "My module needs the java.base module to work." Thejava.base
module is like Java’s core functionality (e.g., basic utilities like collections, exceptions, etc.). By declaring this, you're letting the JVM know that your module relies on Java’s core tools. No need to import every single class fromjava.base
; Java knows you’ll need it by default. Easy, right?exports
com.myapp.services
;
: This part is crucial! You're saying, "I want to export thecom.myapp.services
package so other modules or applications can use it." In other words, if someone else needs to use the services provided by your module, they can simply access thecom.myapp.services
package. It’s like opening up the door to your cool services district for the outside world to use. 🌍
Why Is This Cool?👌
Think of modules like setting up a cool neighborhood for your app. You can isolate pieces of functionality (e.g., services, database access, authentication) into distinct neighborhoods and only share what’s needed. If you’re building a massive app, this will make it easier to maintain, improve security (because not everything is exposed), and help with dependencies (no more dragging around unnecessary parts).
Modularization (JEP 193)
JEP 193 is about modularizing the JDK itself. The JDK was massive, so splitting it into smaller, focused modules helps developers optimize applications and avoid unnecessary dependencies.
Now, instead of importing the whole JDK, you can just import the exact modules you need. Less bloat, more speed! ⚡
TL;DR
Java 9's module system is a huge win for making apps cleaner and more efficient. By using Project Jigsaw, Java allows developers to split up their applications into modules, each focused on a specific function. You import only what you need, making your app lighter and faster. With the requires
and exports
keywords, you control what your app depends on and what it shares with the world. 🌍
💻 JShell (Interactive REPL) – Java's New Play Area 🎮
JShell: The REPL (Read-Eval-Print Loop)
Java isn’t known for being the fastest when it comes to interactive development. You had to write your code, compile it, run it... rinse and repeat. But Java 9 stepped up with JShell—the first official interactive REPL for Java.
Think of JShell like your personal Java playground. You can type in Java code and immediately see the results, making it perfect for testing, learning, or just experimenting with ideas without needing to write a full program
wanna play a lil bit ? open uo your terminal and jshell to launch the REPL
jshell> int sum = 5 + 10
sum ==> 15
jshell> System.out.println(sum)
15
You didn’t need to create a class, write a main
method, or compile anything. Just type in some code and boom—instant feedback. 🚀
JShell makes Java feel less rigid, and more like a quick, fun experiment zone. Whether you're testing small pieces of logic or just playing around, JShell's here to make things faster and more engaging.
Improved JVM Performance – Java 9 Gets Faster 🚀
Java 9 wasn’t just about cool features like modules and JShell—it also brought some serious upgrades to the JVM (Java Virtual Machine) to make your apps run faster, smoother, and more efficiently. It’s like giving the engine of a sports car a turbo boost 🚗💨—everything works quicker, uses less fuel (memory), and gets to the finish line faster.
Breakdown
⚡ Faster Startup Times - Java apps used to take a bit of time to start up. You know the feeling—you click "run" and then… wait. 😅 But in Java 9, the JVM has been optimized so that your apps can start faster. Less waiting around for your code to launch means more productivity and quicker testing, which is always a win!
🧹 Optimized Garbage Collection (G1 Garbage Collector) - Okay, so imagine your app is like a big, messy room. Over time, you accumulate a bunch of stuff you no longer need. In the past, Java’s garbage collector would sometimes take a while to clean up the mess—think of it as a cleaning robot that didn’t move very fast. 🧑💻
But with Java 9, the G1 Garbage Collector got a serious upgrade. It now runs with low-latency operations, meaning it can clean up memory much faster without interrupting the app’s performance. Your app runs smoothly, and the JVM uses less memory overall. No more pauses or slowdowns while it clears out the junk—everything just keeps moving! 💨
🔧 JVM Logging Improvements - Java 9 also made it easier to diagnose performance issues. With the new JVM logging improvements, you can track down any performance bottlenecks in your application and figure out exactly where things are slowing down. It’s like having a super-smart mechanic who can tell you where your engine’s misfiring and help you fix it quickly. 🛠️
In Short🔹 :
Java 9 didn’t just make things modular and interactive—it made Java apps run faster and use memory more efficiently! With faster startup times, improved garbage collection, and better tools for tracking performance, Java 9 is like a performance upgrade for your app. Less waiting, more doing. 🚀735