Learnitweb

Category: Java tutorial

  • Selecting a garbage collector for application in Java

    Introduction In this tutorial, we’ll discuss why there could be need to define the garbage collector for your application. What are the factors which help in decision making for selecting the garbage collector. Java can be run on different types of machines and devices. Java HotSpot VM provides multiple garbage collectors to meet different requirements.…

  • Maximum pause-time and throughput garbage collection in Java

    1. Introduction In this tutorial, we’ll discuss two important terms in relation to garbage collection in Java – pause time and throughput. Understanding of these two terms is very important as understanding of these two terms helps in adjusting various parameters related to garbage collection for application performance. 2. Pause time in garbage collection During…

  • Garbage collection in Java and types of garbage collectors

    1. Introduction If you have used C programming language then you must be aware that it is the responsibility of the programmer to release the used memory at the end of the program. This memory management is very important as a system has limited memory and if not properly managed could lead to memory related…

  • An introduction to ThreadLocal in Java

    ThreadLocal class is one of the classes provided by Java which helps programmers in writing thread safe code. When sensitive data is accessed by multiple threads, it needs to be synchronized. ThreadLocal works in a different manner. Rather than synchronizing the shared data, we are providing each thread with its own copy of data. ThreadLocal…

  • volatile keyword in Java

    Marking a variable as volatile is a weaker form of synchronization. Volatile variable always returns the most recent value of the variable written by any thread as volatile variables are not cached in registers or in caches. Volatile variables may look like to behave like Synchronized classes (for example, SynchronizedInteger), but it is not. Synchronized…

  • Static Nested Class in Java

    A static nested class is an inner class marked with static modifier. A static nested class is sometimes called as static inner class. A static nested class does not have a relationship with the outer class as it can not access instance non static members of the outer class. This is because the nested class…

  • Anonymous Inner Class in Java

    Anonymous inner class is an inner class without a name. Anonymous class is commonly used to create implementation classes of listener interfaces. Anonymous class is very useful while creating an instance of subclass(of a class) or implementing an interface without actually extending and with less code. The main purpose of creating anonymous inner class is…

  • Local class in Java

    A local class is a class defined in a block. A block is a group of zero or more statements enclosed between braces. Note: A local class can be defined inside any block, like a for loop, or if clause. A very common place of defining a local class is within a method. 1.1. Local…

  • Inner class in Java

    An Inner class is one class defined in another class. So inner class is a member of another class just like member variables and methods. 1.1 Types of inner class There are four types of inner classes depending on where you define the inner class: 1.2 Use case and example of inner class A class…

  • Thread priority and yield method

    In this tutorial we’ll understand what is a thread priority. We’ll see how to get and set a thread’s priority. We’ll then look into the yield() method. Thread priority In JVM there is a pool of runnable threads. Thread scheduler picks one thread from the pool and provides it time to run. Different JVMs use…