JAVA

Memory Leak in Java

Memory Leak The standard definition of a memory leak is a scenario that occurs when objects are no longer being used by the application, but the Garbage Collector is unable to remove them from working memory – because they’re still being referenced. As a result, the application consumes more and more resources – which eventually leads to a fatal OutOfMemoryError. We will see few scenarios. Autoboxing Instead of taking the primitive long for the sum, Read more…

By Ashish, ago
JAVA

Java Garbage Collection

Java Garbage Collection is the process to identify and remove the unused objects from the memory and free space to be allocated to objects created in the future processing. One of the best feature of java programming language is the automatic garbage collection, Garbage Collector is the program running in the background that looks into all the objects in the memory and find out objects that are not referenced by any part of the program. Read more…

By Ashish, ago
JAVA

Difference between Java Heap Space and Stack Memory

Based on my previous post related to Java Memory Allocation – Heap and Stack let’s see the difference. Heap Space Stack Memory Heap memory is used by all the parts of the application. Stack memory is used only by one thread of execution. Whenever an object is created, it’s always stored in the Heap space and stack memory contains the reference to it. Stack memory only contains local primitive variables and reference variables to objects in heap Read more…

By Ashish, ago
JAVA

Java Memory Allocation – Heap and Stack

When a Java program starts Java Virtual Machine gets some memory from Operating System. Java Virtual Machine or JVM uses this memory for all its need. This memory is basically divided into two part Java Heap Space Java Stack Memory Java Heap Space Java Heap space is used by java runtime to allocate memory to Objects and JRE classes. Whenever we create any object using new keyword, it’s always created in the Heap space. Any Read more…

By Ashish, ago
JAVA

Memory Management in Java – JVM Memory Model

Java (JVM) Memory Model At broad level, JVM Heap memory is physically divided into two parts – Young Generation and Old Generation. Young Generation Young generation is the place where all the new objects are created. When young generation is filled, garbage collection is performed. This garbage collection is called Minor GC. Young Generation is divided into three parts – Eden Memory and two Survivor Memory spaces. Important Points about Young Generation Spaces: Most of Read more…

By Ashish, ago
JAVA

Java is Pass by Value

One of the biggest confusion in Java programming language is whether java is Pass by Value or Pass by Reference. First of all we should understand what is meant by pass by value or pass by reference. Pass by Value: The method parameter values are copied to another variable and then the copied object is passed, that’s why it’s called pass by value. Pass by Reference: An alias or reference to the actual parameter is Read more…

By Ashish, ago
JAVA

Reverse a String is Java

There are many ways to reverse a String in Java. We will see traditional ways and using classes which provide in-build function. 1. Storing in reverse Order In above piece of code. We have assigned a char of length of String passed to it. In loop we are taking character from start index and adding it to last index of above assigned array. Finally we combine all Character as String and return 2. Dividing into Read more…

By Ashish, ago
JAVA

Difference between StringBuffer and StringBuilder

Based on my previous posts related to StringBuffer and StringBuilder let’s see the difference. StringBuffer StringBuilder StringBuffer was the only choice for String manipulation till Java 1.4 StringBuilder came into picture from Java 1.5. all of its public methods are synchronized all of its public methods are not synchronized StringBuffer provides Thread safety. StringBuilder doesnt provides Thread safety StringBuilder is slower because of synchronization. StringBuilder is faster and preferred.

By Ashish, ago
JAVA

StringBuffer in Java

We will find answer for following questions What is StringBuffer Available Constructors Commonly used methods StringBuffer Java StringBuffer class is used to create mutable (modifiable) string. The StringBuffer class in java is same as String class except it is mutable i.e. it can be changed. The Java StringBuffer class is same as StringBuilder class except that this one is synchronized. So its thread safe and can be used if Object are shared among multiple thread. Read more…

By Ashish, ago
JAVA

StringBuilder in Java

We will find answer for following questions What is StringBuilder Available Constructors Commonly used methods StringBuilder Java StringBuilder class is used to create mutable (modifiable) string. The Java StringBuilder class is same as StringBuffer class except that it is non-synchronized. So its not thread safe and can’t be used if Objects are shared among multiple thread. It is available since JDK 1.5. If sb refers to an instance of a StringBuilder, then sb.append(x) has the same Read more…

By Ashish, ago