Found 7442 Articles for Java

Java Naming Conventions

Ankitha Reddy
Updated on 22-Aug-2024 12:12:47

3K+ Views

All Java components require names. Names used for classes, variables and methods are called identifiers. The naming conventions for different Java components are as follows: Package Naming Convention Class Naming Convention Interfaces Naming Convention Method Naming Convention Constants Naming Convention Variables Naming Convention Quick Summary Package Naming Convention Naming conventions for Java packages typically involve using lowercase letters. It's common to use ... Read More

What is the purpose of private constructor in Java?

Alshifa Hasnain
Updated on 26-Mar-2025 12:05:52

864 Views

In this article, we will learn about the purpose of private constructor in Java. Constructor is a unique method used to initialize objects. Constructors are public or protected by default, which allows outside classes to create instances Why Use a Private Constructor? Private constructor is mainly applied to manage object creation. It does not allow other classes to instantiate the class, creating particular design patterns or restrictions. Purpose of a Private Constructor The private constructor is useful in case we want to restrict the object creation. For example − Singleton pattern can be implemented using ... Read More

What is the purpose of private constructor in Java?

Alshifa Hasnain
Updated on 26-Mar-2025 12:05:52

864 Views

In this article, we will learn about the purpose of private constructor in Java. Constructor is a unique method used to initialize objects. Constructors are public or protected by default, which allows outside classes to create instances Why Use a Private Constructor? Private constructor is mainly applied to manage object creation. It does not allow other classes to instantiate the class, creating particular design patterns or restrictions. Purpose of a Private Constructor The private constructor is useful in case we want to restrict the object creation. For example − Singleton pattern can be implemented using ... Read More

How is down-casting possible in Java?

Syed Javed
Updated on 12-Mar-2020 10:34:57

179 Views

Yes, a variable can be downcast to its lower range substitute by casting. It may lead to data loss although. See the example below −ExampleLive Demopublic class Tester {      public static void main(String[] args) {       int a = 300;         byte b = (byte)a;         System.out.println(b);    }   }OutputIt will print output as −44

How is down-casting possible in Java?

Syed Javed
Updated on 12-Mar-2020 10:34:57

179 Views

Yes, a variable can be downcast to its lower range substitute by casting. It may lead to data loss although. See the example below −ExampleLive Demopublic class Tester {      public static void main(String[] args) {       int a = 300;         byte b = (byte)a;         System.out.println(b);    }   }OutputIt will print output as −44

What is runtime polymorphism or dynamic method overloading?

Ankitha Reddy
Updated on 05-Mar-2020 12:29:43

1K+ Views

Polymorphism is the ability of an object to take on many forms. The most common use of polymorphism in OOP occurs when a parent class reference is used to refer to a child class object. Method overriding by a subclass is termed as runtime polymorphism. JVM determines the method to be executed at runtime instead of compile time. exampleLive Democlass SuperClass {    SuperClass get(){       System.out.println("SuperClass");       return this;    } } public class Tester extends SuperClass {    Tester get(){       System.out.println("SubClass");       return this;    }    public static void main(String[] args) {       SuperClass tester = new Tester();         tester.get();    }   }OutputSubClass

What is runtime polymorphism or dynamic method overloading?

Ankitha Reddy
Updated on 05-Mar-2020 12:29:43

1K+ Views

Polymorphism is the ability of an object to take on many forms. The most common use of polymorphism in OOP occurs when a parent class reference is used to refer to a child class object. Method overriding by a subclass is termed as runtime polymorphism. JVM determines the method to be executed at runtime instead of compile time. exampleLive Democlass SuperClass {    SuperClass get(){       System.out.println("SuperClass");       return this;    } } public class Tester extends SuperClass {    Tester get(){       System.out.println("SubClass");       return this;    }    public static void main(String[] args) {       SuperClass tester = new Tester();         tester.get();    }   }OutputSubClass

What is a marker or tagged interface in Java?

Debarpito Sarkar
Updated on 05-Sep-2022 12:14:41

3K+ Views

This article will help you understand what a Marker or Tagged Interface in Java is. Before understanding marker interface, let’s revise on Interface. INTERFACE Similar to an object, an Interface is a blueprint of a class. It consists of static constants and abstract methods. It is a mechanism to achieve abstraction and multiple inheritance in Java. It is declared using the interface keyword. It provides total abstraction, meaning all methods in an interface must be declared with empty body, and all fields must be public, static and final by default. Syntax interface { // constant fields declaration ... Read More

What is a marker or tagged interface in Java?

Debarpito Sarkar
Updated on 05-Sep-2022 12:14:41

3K+ Views

This article will help you understand what a Marker or Tagged Interface in Java is. Before understanding marker interface, let’s revise on Interface. INTERFACE Similar to an object, an Interface is a blueprint of a class. It consists of static constants and abstract methods. It is a mechanism to achieve abstraction and multiple inheritance in Java. It is declared using the interface keyword. It provides total abstraction, meaning all methods in an interface must be declared with empty body, and all fields must be public, static and final by default. Syntax interface { // constant fields declaration ... Read More

What is static blank final variable in Java?

Syed Javed
Updated on 30-Jul-2019 22:30:22

471 Views

No. It is not allowed in Java. Compiler will fail the compilation throwing error that the blank final field may not have been initialized.

Advertisements