Sadie  Cassin

Sadie Cassin

1611354600

Garbage Collection in Java – What is GC and How it Works in the JVM

Learn more about the Garbage Collector in Java, how it works, and the various types of GC available in Java and their advantages. Java Garbage Collection is the process by which Java programs perform automatic memory management. Java programs compile into bytecode that can be run on a Java Virtual Machine (JVM).

In my previous article, I wrote about the Java Virtual Machine (JVM) and explained its architecture. As part of the Execution Engine component, I also briefly covered the Java Garbage Collector (GC).

In this article, you will learn more about the Garbage Collector, how it works, and the various types of GC available in Java and their advantages. I will also cover some of the new experimental Garbage Collectors that are available in the latest Java releases.

What is Garbage Collection in Java?

Garbage Collection is the process of reclaiming the runtime unused memory by destroying the unused objects.

In languages like C and C++, the programmer is responsible for both the creation and destruction of objects. Sometimes, the programmer may forget to destroy useless objects, and the memory allocated to them is not released. The used memory of the system keeps on growing and eventually there is no memory left in the system to allocate. Such applications suffer from “memory leaks”.

After a certain point, sufficient memory is not available for creation of new objects, and the entire program terminates abnormally due to OutOfMemoryErrors.

You can use methods like free() in C, and delete() in C++ to perform Garbage Collection. In Java, garbage collection happens automatically during the lifetime of a program. This eliminates the need to de-allocate memory and therefore avoids memory leaks.

Java Garbage Collection is the process by which Java programs perform automatic memory management. Java programs compile into bytecode that can be run on a Java Virtual Machine (JVM).

When Java programs run on the JVM, objects are created on the heap, which is a portion of memory dedicated to the program.

Over the lifetime of a Java application, new objects are created and released. Eventually, some objects are no longer needed. You can say that at any point in time, the heap memory consists of two types of objects:

  • Live - these objects are being used and referenced from somewhere else
  • Dead - these objects are no longer used or referenced from anywhere

The garbage collector finds these unused objects and deletes them to free up memory.

#java #programming #developer

What is GEEK

Buddha Community

Garbage Collection in Java – What is GC and How it Works in the JVM
Joseph  Murray

Joseph Murray

1621559580

Collection vs Collections in Java: Difference Between Collection & Collections in Java

Introduction

This article will be looking into one of the most popular questions in Java Language – What is Collection in Java? Also, what do you mean by Collections in Java? Are Collection and Collections the same or different in Java?

What is Collection?

What is Collections?

Conclusion

#full stack development #collection #collection vs collections in java #collections in java #difference between collection and collections in java

Tyrique  Littel

Tyrique Littel

1600135200

How to Install OpenJDK 11 on CentOS 8

What is OpenJDK?

OpenJDk or Open Java Development Kit is a free, open-source framework of the Java Platform, Standard Edition (or Java SE). It contains the virtual machine, the Java Class Library, and the Java compiler. The difference between the Oracle OpenJDK and Oracle JDK is that OpenJDK is a source code reference point for the open-source model. Simultaneously, the Oracle JDK is a continuation or advanced model of the OpenJDK, which is not open source and requires a license to use.

In this article, we will be installing OpenJDK on Centos 8.

#tutorials #alternatives #centos #centos 8 #configuration #dnf #frameworks #java #java development kit #java ee #java environment variables #java framework #java jdk #java jre #java platform #java sdk #java se #jdk #jre #open java development kit #open source #openjdk #openjdk 11 #openjdk 8 #openjdk runtime environment

Seamus  Quitzon

Seamus Quitzon

1604020089

What Are Garbage Collection Logs, Thread Dumps, and Heap Dumps?

Java Virtual Machine (JVM) generates 3 critical artifacts that are useful for optimizing the performance and troubleshooting production problems. Those artifacts are:

  1. Garbage collection (GC) log
  2. Thread Dump
  3. Heap Dump

In this article, let’s try to understand these 3 critical artifacts, where to use them, how do they look, how to capture them, how to analyze them, and their differences.

1. Garbage Collection Log

a) What Is a GC Log?

GC Log contains garbage collection events related information. It will indicate how many GC events ran, what type of GC events they are (i.e. Young GC or Full GC), how long each GC event pause the application, how much objects did each GC event reclaim.

b) What Does a GC Log Look Like?

Sample garbage collection log file can be found here. 

c) Where Are GC Logs Used?

Garbage collection logs are used to study the application’s GC and memory performance. It’s used to optimize the GC pause times, it’s used to identify optimal memory size for your application, it’s also used to troubleshoot memory-related problems.

d) How to Generate a GC Log?

You can generate garbage collection logs by passing the following JVM arguments:

For Java versions until 8:

Java

xxxxxxxxxx

1

1

-XX:+PrintGCDetails

2

-XX:+PrintGCDateStamps

3

-Xloggc:<file-path>

#threading #heap dump #java threads #thread dump #garbage collection in java #heap dump analysis #java gc #garbage collectors #jvm arguments #gc log

Joseph  Murray

Joseph Murray

1623304800

Why We Need Collection Framework in Java?

A framework is a set of classes and interfaces which provide a ready-made architecture. In order to implement a new feature or a class, there is no need to define a framework. However, an optimal object-oriented design always includes a framework with a collection of classes such that all the classes perform the same kind of task. Before Collection Framework(or before JDK 1.2) was introduced, the standard methods for grouping Java objects (or collections) were Arrays or Vectors, or Hash tables. All of these collections had no common interface. Therefore, though the main aim of all the collections is the same, the implementation of all these collections was defined independently and had no correlation among them. And also, it is very difficult for the users to remember all the different methods, syntax, and constructors present in every collection class.

Collection Framework is a powerful framework in java. This framework defines the most common methods that can be used for any collection of objects. But the question arises that we have an array concept in java then why we need collection framework in java? Now let’s see that why we need collection framework in java with some valid points of difference between array and collection.

#java #java-collections #why we need collection framework in java #java collections framework #framework in java

Introduction to JAVA COLLECTIONS

In this blog we will understand basics of JAVA Collections framework.

What are JAVA Collections and Why do we need them?

The Collection in Java is a framework that provides an architecture to store and manipulate the group of objects.

Collections are like containers that group multiple items in a single unit. For example, a jar of chocolates, a list of names, etc. Collections are used in every programming language and when Java arrived, it also came with few. Let’s see how does it help us:

  • Reduces programming effort
  • Increases program speed and quality
  • Allows interoperability among unrelated APIs
  • Reduces effort to learn and to use new APIs
  • Reduces effort to design new APIs
  • Fosters software reuse

#functional programming #java #collections #functional java #java #introduction to java collections