JAVA

Arrays class in Java

Arrays class of the java.util package contains several static methods that we can use to fill, sort, search, etc in arrays. Commonly uses API of this class :- public static String toString(int[] a) : String representation consists of a list of the array’s elements, enclosed in square brackets (“[]”). Adjacent [...]

2018-09-27T21:56:04+05:30Categories: Programming|Tags: |

Assigning an object to an interface reference

When you define a new interface, you are defining a new reference data type. You can use interface names anywhere you can use any other data type name. If you define a reference variable whose type is an interface, any object you assign to it must be an instance of a class [...]

2018-03-31T12:58:37+05:30Categories: Programming|Tags: |

Super Class vs Sub Class | Java

A sub class has an 'is a' relationship with its superclass. In terms of objects, a sub class object can also be treated as a super class object. And hence, we can assign the reference of a sub class object to a super class variable type. However, the reverse is [...]

2020-02-02T14:00:12+05:30Categories: Programming|Tags: |

Enums | Java

Enum data type contains fixed set of constants. Enum are static and final implicitly. Points to remember for Enum enum improves type safety enum can be easily used in switch enum can be traversed enum can have fields, constructors and methods enum may implement many interfaces but cannot extend any [...]

2019-03-24T21:09:47+05:30Categories: Programming|Tags: |

instanceof operator | JAVA

instanceof operator is used to check the type of an object at runtime. It is the means by which your program can obtain run-time type information about an object. instanceof operator return boolean value, if an object reference is of specified type then it return true otherwise false. Example interface [...]

2019-11-28T22:50:07+05:30Categories: Programming|Tags: |

Interface | Java

Interface Abstract class is used for achieving partial abstraction. Unlike abstract class an interface is used for full abstraction. Abstraction is a process where you show only “relevant” data and “hide” unnecessary details of an object from the user. A class extends another class, an interface extends another interface but [...]

2019-01-27T18:21:55+05:30Categories: Programming|Tags: |

Polymorphism | Java

Introduction Polymorphism is one of the OOPs feature that allows us to perform a single action in different ways. For example, lets say we have a class Animal that has a method sound(). public class Animal{ public void sound(){ System.out.println("Animal is making a sound"); } } public class Horse extends [...]

2019-04-04T23:08:24+05:30Categories: Programming|Tags: |

Inheritance in Java

Inheritance provided mechanism that allowed a class to inherit property of another class. When a Class extends another class it inherits all non-private members including fields and methods. When subclass object is created, a separate object of super class object will not be created. Only a subclass object is created that [...]

2018-09-10T13:37:18+05:30Categories: Programming|Tags: |

Regular Expression | Java

Introduction A regular expression, or regex, is a sequence of characters that specifies a pattern which can be searched for in a text. A regex defines a set of strings, usually united for a given purpose. Suppose you need a way to formalize and refer to all the strings that [...]

2020-04-18T23:30:31+05:30Categories: Programming|Tags: , |

Java Hacks

PriorityQueue/ Queue to List conversion List<String> array_list = new ArrayList<String>(pq1); Split string based on spaces/tab // \s is regular expression for space. + stands for more than one space str.split("\\s+"); Compare two double Double.compare(doubel, double2) Dimesnsion of 2D array // 2 D array arr[][] int rows = arr.length; // Numbers [...]

2020-05-13T18:04:32+05:30Categories: Programming|Tags: |
Go to Top