Category Archives: Java

Output of Java Program | Set 10

Predict the output of following Java programs: Question 1 : a) 6 b) 5 c) Compile time error d) Run time error Answer (c) Explanation: When overriding a method of superclass, the method declaration in subclass cannot be more restrictive than that declared in the superclass. Question 2 : a) Either Compile time or Runtime… Read More »

Enum with Customized Value in Java

Prerequisite : enum in Java By default enums have their own string values, we can also assign some custom values to enums. Consider below example for that. Examples: enum Fruits { APPLE(“RED”), BANANA(“YELLOW”), GRAPES(“GREEN”); } In above example we can see that the Fruits enum have three members i.e APPLE, BANANA and ORANGE with have… Read More »

Java.lang.Compiler Class in Java

Compiler Class provides support and related services to Java code to Native Code. Native code is a form of code that can be said to run in a virtual machine (for example, [JVM]Java Virtual Machine). Declaration : public final class Compiler extends Object Methods : command() : java.lang.Compiler.command() tests the argument type and performs some… Read More »

Java.lang.Void Class in Java

Java.lang.Void class is a placeholder which holds a reference to a class object if it represents void keyword. It is a uninstantiable placeholder. Well, uninstantiable means that this class have a private constructor and no other constructor that we can access from outside. Methods of lang.void class are all inherited from Object class in Java:… Read More »

Java.lang.Character.UnicodeBlock Class in Java

Character.UnicodeBlock Class represents particular Character blocks of the Unicode(standards using hexadecimal values to express characters – 16 bit) specifications. Character Blocks define characters used for specific purpose. Declaration : public static final class Character.UnicodeBlock extends Character.Subset Methods of Character.UnicodeBlock Class : forName() : java.lang.Character.UnicodeBlock.forName() returns the name of Unicode Blocks, which are determined by the… Read More »

Java.lang.Math Class in Java | Set 2

Java.lang.Math Class in Java | Set 1 More Methods: cosh() : java.lang.Math.cosh() method returns the hyperbolic cosine of the argument passed. Special cases : Result is NaN, if argument is NaN. Result is 1.0, if the argument is zero. Result is +ve infinity, if argument is infinite. Syntax: public static double cosh(double arg) Parameters: arg… Read More »

Java.lang.Math Class in Java | Set 1

Math Class methods helps to perform the numeric operations like square, square root, cube, cube root, exponential and trigonometric operations Declaration : public final class Math extends Object What is NaN argument ? A constant holding a Not-a-Number (NaN) value of type double. It is equivalent to the value returned by Double.longBitsToDouble(0x7ff8000000000000L). Methods of lang.math… Read More »

Hashmap vs WeakHashMap in Java

HashMap Java.util.HashMap class is a Hashing based implementation. In HashMap, we have a key and a value pair. Even though the object is specified as key in hashmap, it does not have any reference and it is not eligible for garbage collection if it is associated with HashMap i.e. HashMap dominates over Garbage Collector. Output:… Read More »

Instance Initialization Block (IIB) in Java

In a Java program, operations can be performed on methods, constructors and initialization blocks. Instance Initialization Blocks or IIB are used to initialize instance variables. IIBs are executed before constructors. They run each time when object of the class is created. Initialization blocks are executed whenever the class is initialized and before constructors are invoked.… Read More »

Java.lang.Character.Subset Class in Java

Character.Subset Class represents particular subsets of the Unicode(standards using hexadecimal values to express characters – 16bit) character set. The subset, it defines in Character set is UnicodeBlock. Declaration : public static class Character.Subset extends Object Constructors : protected Character.Subset(String str) : Constructs new subset instance. Methods: equals() : java.lang.Character.Subset.equals() tells wheteher the two Subset Object… Read More »

StAX XML Parser in Java

This article focuses on how one can parse a XML file in Java. XML : XML stands for eXtensible Markup Language. It was designed to store and transport data. It was designed to be both human- and machine-readable. That’s why, the design goals of XML emphasize simplicity, generality, and usability across the Internet. Why StAX… Read More »