Posts

Showing posts from May, 2020

Java Stack and Heap: Java Memory Allocation Lesson.

Image
    Stack Memory   Stack in java is a section of memory which contains methods, local variables, and reference variables. Local variables are created in the stack. Java Stack memory is used for the execution of a thread. They contain method-specific values that are short-lived and references to other objects in the heap that is getting referred from the method. Stack  memory is always referenced in  LIFO (Last-In-First-Out)  order. Whenever a method is invoked, a new block is created in the stack memory for the method to hold local primitive values and reference to other objects in the method. As soon as the method ends, the block becomes unused and becomes available for the next method. Stack memory size is very less compared to Heap memory. Key Features of Stack Memory Apart from what we have discussed so far, following are some other features of  Stack  memory: It grows and shrinks as new methods are called and returned respectiv...

Class Loader

Image
In this tutorial explain to What is Class Loader? Types of  Class Loader. Principle of  Class Loader. Class Loader hierarchy.      ClassLoader  The class loader concept, one of the cornerstones of the Java virtual machine , describes the behavior of converting a named class into the bits responsible for implementing that class. Because class loaders exist, the Java run time does not need to know anything about files and file systems when running Java programs. The  Java ClassLoader  is a part of the  Java Runtime Environment that dynamically loads Java classes into the  JavaVirtual Machine . The Java run time system does not need to know about files and file systems because of classloaders. Java classes aren’t loaded into memory all at once, but when required by an application. At this point, the  Java ClassLoader  is called by the  JRE  and these ClassLoaders load classes into memory dynamically. Types of C...

Java Memory Allocation.

Image
              Memory Management in Java  Memory allocation  is a process by which computer programs and services are assigned with physical or virtual  memory  space.  In Java, memory management is the process of allocation and de-allocation of objects, called Memory management. Java does memory management automatically. Java uses an automatic memory management system called a  garbage collector . Thus, we are not required to implement memory management logic in our application. Java memory management divides into two major parts: JVM Memory Structure Working of the Garbage Collector     Types of Memory areas allocated by the JVM:                      JVM creates various run time data areas in a heap. These areas are used during the program execution. The memory areas are destroyed when JVM exits, whereas the data areas are destroyed when ...

Garbage Collection in Java How Java Garbage Collection Works?

Image
         Garbage Collection   In Java, the programmers don’t need to take care of destroying the objects that are out of use. The Garbage Collector takes care of it.   Garbage Collector is a Daemon thread that keeps running in the background. Basically, it frees up the heap memory by destroying the unreachable objects.           Unreachable objects are the ones that are no longer referenced by any part of the program.            We can choose the garbage collector for our java program through JVM options,       Garbage Collector is a program that manages memory automatically wherein de-allocation of objects is handled by Java rather than the programmer. In the Java programming language, dynamic allocation of objects is achieved using the  new  operator. An object once created uses some memory and the memory remains allocated till there are...

What is JVM, JDK and JRE in Java?

Image
What is JVM? Java Virtual machine  (JVM) is the virtual machine that runs the Java bytecodes. You get this bytecode by compiling the  .java  files into  .class  files.  .class  files contain the bytecodes understood by the JVM.   In the real world, JVM is a specification that provides a runtime environment in which Java bytecode can be executed. Different vendors provide different implementations of this specification. For example, this wiki page lists down different JVM implementations. Most popular implementation of JVM is Hotspot which is owned and provided by Oracle Corporation. ( Previously by Sun Microsystems, Inc. ). JVM delivers the optimal performance for Java applications using many advanced techniques, incorporating a state-of-the-art memory model,  garbage collector , and  adaptive optimizer . JVM comes in two different flavors –  client  and  server . Although the Server and the Client VMs ar...

What is meaning of main() method in Java ? and Why is main() method public static and void in java?

public  – access modifier, meaning global visibility static  – the method can be accessed straight from the class, we don’t have to instantiate an object to have a reference and use it void  – means that this method doesn't return a value main  – the name of the method, that’s the identifier JVM looks for when executing a Java program Why is main method public static and void in Java? Will the program compile, if the main method is not static? Java program's  main  method has to be declared  static  because keyword  static  allows main to be called without creating an object of the class in which the  main  method is defined. If we omit  static  keyword before  main  Java program will successfully compile but it won't execute. For a little detailed description, look at the usual signature of Java's  main  method public static  void main (String args[]) Above code line begins defi...

What is java ? and what is java used for? and its history.

What is Java Java  is a general-purpose, concurrent, object-oriented, class-based, and the runtime environment(JRE) which consists of  JVM  which is the cornerstone of the Java platform. This blog on  What is Java  will clear all your doubts about why to learn java, features and how it works. Java is a programming language and computing platform first released by Sun Microsystems in 1995. It is an object-oriented language similar to C++, but with advanced and simplified features. Java is  free to access  and can  run  on  all platforms . Java is a write-once, run-anywhere (WORA)  programming language  For example, you can write and compile a Java program on UNIX and run it on Microsoft Windows, Macintosh, or UNIX machine without any modifications to the source code.  WORA   is achieved by compiling a Java program into an intermediate language called  bytecode . The format of bytecode is  platform-independent...