My favourite 28 features in Java as it turns 28
Tags: java
Published: 2023-05-25 11:29:52

Java turned 28 this week! Here are my 28 favourite features/APIs in it. 

What are your favourite features/APIs comment below?

{% twitter 1661033899567509504 %}


## 1. Collections 

Java 2 introduced the collections framework.

> "The collections framework is a unified architecture for representing and manipulating collections... It reduces programming effort while increasing performance"

[Link to Collections](https://docs.oracle.com/en/java/javase/20/docs/api/java.base/java/util/doc-files/coll-index.html)

![code showing collections](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pi43hf8l3usv1z1rmu9k.jpeg)

P.S. Oh yeah! I used generics \o/ 

## 2. Non-Blocking Input Output (NIO)

Java 4 introduced NIO (New Input/Output) API. They were high level abstraction APIs designed to provide efficient operations on the low-level I/O operations. Later on Java 7 extended these non-blocking I/O for filesystem access. 

[Link to NIO API](https://docs.oracle.com/javase/8/docs/api/java/nio/package-summary.html) 


![code showing usage of NIO](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oc1k7y7f4bg8zhqojcqe.jpeg)


## 3. Generics 

Java 5 came with Generics. Hate it or love it. IMHO this is one of the key features to be released at that time. It reduced bugs and added an extra layer of abstraction over types. 

[Generics](https://docs.oracle.com/javase/tutorial/java/generics/types.html)


![code showing generics](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pi43hf8l3usv1z1rmu9k.jpeg)


## 4. Annotations
Annotation was another feature Java 5 came with.

> "Annotations, a form of metadata, provide data about a program that is not part of the program itself. Annotations have no direct effect on the operation of the code they annotate."

[Annotations](https://docs.oracle.com/javase/tutorial/java/annotations/index.html)


![Code showing annotations](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rvc7a2g7rpom6ytpjn49.jpeg)


## 5. Varargs...

Java 5 also introduced Varargs. They provided a short-hand for methods that support an arbitrary number of parameters of one type.

{% medium https://sendilkumarn.medium.com/safevarargs-variable-arguments-in-java-b9fdd5d996bb %}


## 6. Concurrency

Java 5 also improved concurrency.

> "APIs under java.util.concurrency, these APIs have been designed to support [concurrent programming](https://en.wikipedia.org/wiki/Concurrent_computing), and all execution takes place in the [context of threads](https://en.wikipedia.org/wiki/Thread_(computing))"


![code showing concurrency API](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mntgze1p3zdo0p29sbmd.jpeg)


## 7. Enhanced For-Each Loop

I loved this enhanced for-each loop when it was released. It was easy and who cares about the index when all you need is the value.

![Code showing enhanced for loop usage](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ddl2qwpxybxud3il73u7.jpeg)


## 8. Garbage Collection Improvements

Java 6 is all about performance there were huge performance improvements for the core platform and even on Swing. It is in Java 6 we saw a few new GC algorithms too.

[Java GC Basics](https://www.oracle.com/webfolder/technetwork/tutorials/obe/java/gc01/index.html)

## 9. TimSort 

Java 7 replaced MergeSort[1] to TimSort[2] for the Collections and Arrays sorting 🚀 


[MergeSort](https://en.wikipedia.org/wiki/Merge_sort)
[TimSort](https://en.wikipedia.org/wiki/Timsort)

## 10. Lambda 

Java 8 is an amazing release. [Project Lambda](https://openjdk.org/projects/lambda/) is the pinnacle of this release.

<a href="http://www.youtube.com/watch?feature=player_embedded&v= 1OpAgZvYXLQ" target="_blank"><img src="http://img.youtube.com/vi/1OpAgZvYXLQ/0.jpg" alt="Venkat talking about Lambda" width="240" height="180" border="10" /></a>


## 11. \<Optional\>

Java 8 introduced Optional to prevent us from NPE. 

> "A container object which may or may not contain a non-null value.  If a value is present, isPresent() will return true and  get() will return the value." 

[Optional](https://docs.oracle.com/javase/8/docs/api/java/util/Optional.html)


![Code showing optional usage](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nqk32dumsdcwcufpx9nn.jpeg)


## 12. Functional Interface

Lambda's are amazing and they organically lead to Functional interfaces. 

> "A functional interface in Java is an interface that contains only a single abstract (unimplemented) method."


![Code showing Functional Interface usage](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f0n9qvl2pgaf2yeglywq.jpeg)


## 13. JShell

Java 9 brought in JShell. 

> "JShell is a REPL tool, which evaluates  declarations, statements, and expressions as they are entered and  immediately shows the results. The tool is run from the command line."

[JEP-222](https://openjdk.org/jeps/222)


![JShell in action](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ekuqk0fhqctb6v7uewgh.jpeg)

## 14. Modules

Remember Zigsaw from Java 9. 

"The [Java Platform Module System](https://en.wikipedia.org/wiki/Java_Platform_Module_System) specifies a distribution format for collections of Java code and associated resources" 

[Jigsaw](https://openjdk.org/projects/jigsaw/)


## 15. Vars

Java 10 released with much awaited Local Variable Type inference a.k.a "var". The verbose Java becomes inferred Java.  

[JEP-286](https://openjdk.org/jeps/286)

![Code showing Var usage](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o3cnqicytg3kts2n6zmk.jpeg)


## 16. Faster Release cycles

Major release every 6 months. Reduced the release cycle duration. No long wait for newer version and features. 

[JEP-322](https://openjdk.org/jeps/322)


## 17. Flight Recorder 

Java 11 came with Flight Recorder, which provided a low-overhead data collection framework for troubleshooting Java applications and the HotSpot JVM.

[JEP-328](https://openjdk.org/jeps/328)


## 18. Single File Source 

Java 11 allowed us to launch single file Java programs via Java command. 

`Java HelloWorld.java`

[JEP-330](https://openjdk.org/jeps/330)


## 19. RIP Applets 

Java 11 bid farewell to Java Applets / Java Web Start / JavaFX and others.

## 20. Switch Expressions

Java 12 came with switch expressions 

[JEP-325](https://openjdk.org/jeps/325)


![Code showing Switch Expressions](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/utytbhhgl2dm9lbobmil.jpeg)


## 21. GC - Shenandoah 

Java 12 also introduced a new GC algorithm named Shenandoah. This amazing algorithm provided consistent pause time irrespective of your heap size.

[JEP-189](https://openjdk.org/jeps/189)

## 22. Text Blocks 

Java 13 came with Text Blocks. Multi-line texts made easy.

[JEP-355](https://openjdk.org/jeps/355)

![Code showing Text Blocks in action](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b9smo2y5l883kca6qjd1.jpeg)

## 23. Pattern Matching 

Java 14 launched with Pattern Matching for instanceof 

> JEP 305, Pattern Matching for instanceof simplifies the common case of an instanceof test being immediately followed by cast (see the code snippet)

[JEP-305](https://openjdk.org/jeps/305)


![Code showing Pattern Matching](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/up0da0hq41fr0ltcp0q4.jpeg)


## 24. Records 

Java 14 also launched with Records. 

Records allows easy creation of simple immutable Tuple-like classes.

[JEP-359](https://openjdk.org/jeps/359)


![Code showing Records in action](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gqm7v6f353rtb8ws311o.jpeg)

## 25. Sealed Classes 

Java 15 introduced sealed classes. 

[JEP-360](https://openjdk.org/jeps/360)

My blog post that talks about sealed classes and interfaces - https://sendilkumarn.com/blog/java-17

![Code showing Sealed classes](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0h4k7fxurjuicbf8cmuu.jpeg)

## 26. Vector API/SIMD

Java 16 came with Vector API.

"Single instruction, multiple data (SIMD)"

[JEP-338](https://openjdk.org/jeps/338)


## 27. Virtual Threads 

Jumping to Java21, it finalized and introduced virtual threads to the java platform. 

> "Virtual threads are lightweight threads that dramatically reduce the effort of writing, maintaining, and observing high-throughput concurrent applications."

[JEP-444](https://openjdk.org/jeps/444)

<a href="http://www.youtube.com/watch?feature=player_embedded&v=y-SXxp1Kx_Y
" target="_blank"><img src="http://img.youtube.com/vi/y-SXxp1Kx_Y/0.jpg" alt="Venkat talking about Project Loom" width="240" height="180" border="10" /></a>

## 28. Community 

Last but not least! The amazing community of #java ❤️

What are your favorite features of #java comment below?

{% twitter 1661125882013011968 %}


## My Other Posts on Java 

{% link https://dev.to/sendilkumarn/interesting-features-in-java-17-1fbc %} 

{% link https://dev.to/sendilkumarn/java-enters-its-teen-age-4626 %} 

{% link https://dev.to/sendilkumarn/9-tips-to-increase-your-java-performance-1l4d %}