Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Transitioning to Java

You're reading from   Transitioning to Java Kickstart your polyglot programming journey by getting a clear understanding of Java

Arrow left icon
Product type Paperback
Published in Apr 2023
Publisher Packt
ISBN-13 9781804614013
Length 354 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Ken Fogel Ken Fogel
Author Profile Icon Ken Fogel
Ken Fogel
Arrow right icon
View More author details
Toc

Table of Contents (23) Chapters Close

Preface 1. Part 1:The Java Development Environment
2. Chapter 1: Understanding Java Distributions FREE CHAPTER 3. Chapter 2: Code, Compile, and Execute 4. Chapter 3: The Maven Build Tool 5. Part 2:Language Fundamentals
6. Chapter 4: Language Fundamentals – Data Types and Variables 7. Chapter 5: Language Fundamentals – Classes 8. Chapter 6: Methods, Interfaces, Records, and Their Relationships 9. Chapter 7: Java Syntax and Exceptions 10. Chapter 8: Arrays, Collections, Generics, Functions, and Streams 11. Chapter 9: Using Threads in Java 12. Chapter 10: Implementing Software Design Principles and Patterns in Java 13. Chapter 11: Documentation and Logging 14. Chapter 12: BigDecimal and Unit Testing 15. Part 3:GUI and Web Coding in Java
16. Chapter 13: Desktop Graphical User Interface Coding with Swing and JavaFX 17. Chapter 14: Server-Side Coding with Jakarta 18. Chapter 15: Jakarta Faces Application 19. Part 4:Packaging Java Code
20. Chapter 16: Deploying Java in Standalone Packages and Containers 21. Index 22. Other Books You May Enjoy

What makes Java special?

Java was designed by Gosling and his team to address shortcomings they perceived in C++. The most significant of the shortcomings was memory management. In C++, variables of type pointer were used to allocate memory for objects. Once an object was no longer needed, the developer’s responsibility was to release or deallocate the memory. Forgetting to do so resulted in memory leaks. A leak is a block of memory marked as in use but no longer accessible by a pointer. While Java still required you to allocate memory, you did not need to deallocate it. A process called the garbage collector tracked all memory allocations. When a pointer, named a reference in Java, went out of scope, the garbage collector would release its memory automatically. There are five garbage collectors available. The Parallel Garbage Collector is the default general-purpose collector. Serial Garbage Collector, CMS Garbage Collector, G1 Garbage Collector, and Z Garbage Collector use algorithms for specific types of applications such as those requiring low latency or requiring only a single thread.

However, garbage collection is not the most significant feature of Java. What sets Java apart from its predecessors, C and C++, is that Java programs do not execute directly in the computer’s operating system. Instead, compiled Java programs, called bytecode, execute inside another process called the Java virtual machine (JVM).

The JVM is a software simulation of a computer. The bytecode is the machine language of this simulated machine. The JVM then translates the bytecode into the machine language of the underlying computer.

The JVM is responsible for optimizing the code and performing garbage collection.

Native languages such as C and C++ are directly compiled into the machine language of the CPU coupled with the computer’s operating system it will run on. Any libraries used must also have been compiled for a specific CPU and operating system. This means that a program compiled for an Intel CPU running Windows or an Apple M1 CPU running a specific version of macOS must be recompiled for an Intel CPU running Linux.

Java turns this concept on its head. Code that you write in Java and compile into bytecode can run on any hardware and operating system unchanged if there is a JVM for that computer. Java describes itself as a Write Once Run Anywhere language. This means that a Java application written on and for an Intel CPU will also run on an ARM-based system unchanged and without the need to recompile if there is a JVM for that platform.

In Chapter 4, Language Fundamentals – Data Types and Variables, and Chapter 5, Language Fundamentals – Classes, we will examine the syntax of the Java language.

Java is not the only language that runs in the JVM. More languages were developed to take advantage of the JVM while at the same time taking a different approach and syntax from Java. Here are four of the most widely used ones:

  • Scala
  • Kotlin
  • Groovy
  • Clojure

We now know what makes Java special in relation to languages that do not have a virtual machine. What can be confusing is that there is not just one version of Java distributed by just one company. Why? Let's take a look at that next.

You have been reading a chapter from
Transitioning to Java
Published in: Apr 2023
Publisher: Packt
ISBN-13: 9781804614013
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image