AmitDiwan has Published 10740 Articles

Examples of soft references and phantom references?

AmitDiwan

AmitDiwan

Updated on 17-Aug-2020 09:17:59

323 Views

Soft references are often used to implement memory-sensitive caches. Let us see an example of soft references in Java −Example Live Demoimport java.lang.ref.SoftReference; class Demo{    public void display_msg(){       System.out.println("Hello there");    } } public class Demo_example{    public static void main(String[] args){       Demo ... Read More

Unreachable statement using the non-final variable in Java

AmitDiwan

AmitDiwan

Updated on 17-Aug-2020 09:06:35

169 Views

Following is an example, wherein we will see unreachable statement using the non-final variable −Exampleclass Demo_example {    int a = 2, b = 3;    void display_msg(){       while (a < b){          System.out.println("The first variable is greater than the second");       ... Read More

Unreachable statement using final variable in Java

AmitDiwan

AmitDiwan

Updated on 17-Aug-2020 09:04:48

231 Views

Unreachable statements are those that don’t get executed when the code is being executed. This could be so because −There is a return statement before the code.There is an infinite loop in the code.The execution of the code is terminated forcibly before it executes.Here, we will see how the unreachable ... Read More

Types of References in Java

AmitDiwan

AmitDiwan

Updated on 17-Aug-2020 09:02:34

915 Views

There are four different kinds of references based on the way in which the data is garbage collected.Strong referencesWeak referencesSoft referencesPhantom referencesStrong referenceIt is the default type of reference object. An object that has active strong reference can’t be garbage collected. It is possible only if the variable that is ... Read More

Type Erasure in Java

AmitDiwan

AmitDiwan

Updated on 17-Aug-2020 08:59:55

202 Views

To support generic programming, as well as perform a stricter type check, Java implements type erasure.All type parameters in generic types are replaced with the bound (if unbounded) or object type. This way, the bytecode will only contain classes, methods, and interfaces.Type casts to preserve the type.Bridge methods are generated ... Read More

Shuffle or Randomize a list in Java

AmitDiwan

AmitDiwan

Updated on 17-Aug-2020 08:56:23

322 Views

To shuffle a list in Java, the code is as follows −Example Live Demoimport java.util.*; public class Demo{    public static void main(String[] args){       ArrayList my_list = new ArrayList();       my_list.add("Hello");       my_list.add(", ");       my_list.add("this");       my_list.add("is");     ... Read More

What is the maximum possible value of an integer in Java ?

AmitDiwan

AmitDiwan

Updated on 17-Aug-2020 08:50:41

3K+ Views

The MAX_VALUE is used to find the maximum possible value for an integer in Java. Let us see an example −Example Live Demopublic class Demo{    public static void main(String[] args){       System.out.println("The type is");       System.out.println(Integer.TYPE);       System.out.println("The size is");       System.out.println(Integer.SIZE); ... Read More

Java Program for Longest Palindromic Subsequence

AmitDiwan

AmitDiwan

Updated on 17-Aug-2020 08:42:15

283 Views

For longest Palindromic subsequence, the Java code is as follows −Example Live Demopublic class Demo{    static String longest_seq(String str_1, String str_2){       int str_1_len = str_1.length();       int str_2_len = str_2.length();       char str_1_arr[] = str_1.toCharArray();       char str_2_arr[] = str_2.toCharArray();   ... Read More

How to add properties and methods to an existing object in JavaScript?

AmitDiwan

AmitDiwan

Updated on 22-Jul-2020 08:04:08

287 Views

Following is the code for adding properties and methods to an existing object in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 20px;       font-weight: ... Read More

Currying VS Partial Application in JavaScript.

AmitDiwan

AmitDiwan

Updated on 22-Jul-2020 08:02:59

296 Views

Currying − In currying a function takes another function and some arguments. The function then returns one function with one parameter only. It returns the function with one argument which can be chained together.Partial application − In partial application some of the arguments can be bind to some values to ... Read More

Advertisements