
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 9150 Articles for Object Oriented Programming

3K+ Views
Whenever you read an integer value into a String, you can remove leading zeroes of it using StringBuffer class, using regular expressions or, by converting the given String to character array.Converting to character arrayFollowing Java program reads an integer value from the user into a String and removes the leading zeroes from it by converting the given String into Character array.Exampleimport java.util.Scanner; public class LeadingZeroes { public static String removeLeadingZeroes(String num){ int i=0; char charArray[] = num.toCharArray(); for( ; i

5K+ Views
In Java, serialization is a concept using which we can write the state of an object into a byte stream so that we can transfer it over the network (using technologies like JPA and RMI).But, static variables belong to class therefore, you cannot serialize static variables in Java. Still if you try to do so, the program gets compiled successfully but it raises an exception at the time of execution.In the following java program, the class Student has a static variable and we are trying to serialize and desterilize its object in the another class named ExampleSerialize.Exampleimport java.io.FileInputStream; import java.io.FileOutputStream; ... Read More

5K+ Views
Interface in Java is similar to class but, it contains only abstract methods and fields which are final and static.Since all the methods are abstract you cannot instantiate it. To use it, you need to implement this interface using a class and provide body to all the abstract methods int it.Making an interface final.If you declare a class final cannot extend it. If you make a method final you cannot override it and, if you make a variable final you cannot modify it. i.e. use final with Java entities you cannot modify them further.If you make an interface final, you ... Read More

17K+ Views
No, you cannot instantiate an interface. Generally, it contains abstract methods (except default and static methods introduced in Java8), which are incomplete.Still if you try to instantiate an interface, a compile time error will be generated saying “MyInterface is abstract; cannot be instantiated”.In the following example we an interface with name MyInterface and a class with name InterfaceExample.In the interface we have an integer filed (public, static and, final) num and abstract method demo().From the class we are trying to − create an object of the interface and print the num value.Example Live Demointerface MyInterface{ public static final int num ... Read More

6K+ Views
Interface in Java is similar to a class but, it contains only abstract methods and fields which are final and static.Since all the methods are abstract you cannot instantiate it. To use it, you need to implement this interface using a class and provide body to all the abstract methods in it.Private members of an interfaceIf the members of the interface are private you cannot provide implementation to the methods or, cannot access the fields of it in the implementing class.Therefore, the members of an interface cannot be private. If you try to declare the members of an interface private, ... Read More

397 Views
In Java, serialization is a concept using which we can write the state of an object into a byte stream so that we can transfer it over the network (using technologies like JPA and RMI).While serializing an object of a class, if you want JVM to neglect a particular instance variable you need can declare it transient.public transient int limit = 55; // will not persist public int b; // will persistIn the following java program, the class Student has two instance variables name and age where, age is declared transient. In another class named EampleSerialize we are trying to ... Read More

2K+ Views
In Java final is the access modifier which can be used with a filed class and a method.When a method if final it cannot be overridden.When a variable is final its value cannot be modified further.When a class is finale it cannot be extended.Declaring final variable without initializationIf you declare a variable as final, it is mandatory to initialize it before the end of the constructor. If you don’t you will get a compilation error.ExampleIn the following java program, we a have an interface with a public, static, final variable with name num and, a public, abstract method with name ... Read More

748 Views
While a superclass method throws an exception while overriding it you need to follow the certain rules.Should throw Same exception or, sub typeIf the super-class method throws certain exception, the method in the sub-class should throw the same exception or its sub type.ExampleIn the following example, the readFile() method of the super-class throws an IOEXception and, the readFile() method of the sub-class throws FileNotFoundException exception.Since the FileNotFoundException exception is the sub type of the IOException this program gets compiled and executed without any errors.import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.util.Scanner; abstract class Super{ public String readFile(String path) throws ... Read More

559 Views
A checked exception is an exception that occurs at the compile time, these are also called as compile time exceptions. These exceptions cannot simply be ignored at the time of compilation; the programmer should take care of (handle) these exceptions.An unchecked exception is an exception that occurs at the time of execution. These are also called as Runtime Exceptions. These include programming bugs, such as logic errors or improper use of an API. Runtime exceptions are ignored at the time of compilation.Unchecked to checkedWhen a method in superclass throws an unchecked exception the method the subclass method overriding cannot throw ... Read More

3K+ Views
Interface in Java is similar to class but, it contains only abstract methods and fields which are final and static.Since all the methods are abstract you cannot instantiate it. To use it, you need to implement this interface using a class and provide body to all the abstract methods int it.Non static variables in an interfaceNo you cannot have non-static variables in an interface. By default, All the members (methods and fields) of an interface are publicAll the methods in an interface are public and abstract (except static and default).All the fields of an interface are public, static and, final ... Read More