
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

2K+ Views
While working with client-server programming in Java (JSE), if you are using java.net.URL class object in your program, you need to instantiate this class by passing a string representing required URL to which you need to establish connection. If the url you have passed in the string which cannot be parsed or, without legal protocol a MalformedURLException is generated.ExampleIn the following Java example we are tring to get establish a connection to a page and publishing the response.We have tampered the protocol part, changed it to htt, which should be http or, https.import java.util.Scanner; import java.io.IOException; import java.net.HttpURLConnection; import java.net.URL; ... Read More

173 Views
The parseBoolean() method is an important method of a Boolean class. The parseBoolean() is a static method and can parse the String method argument into a Boolean object. The parseBoolean() method of Boolean class returns the boolean represented by the string argument.Syntaxpublic static boolean parseBoolean(String s)Exampleimport java.util.Scanner; public class ParseBooleanMethodTest { public static void main(String[] args) { System.out.print("Are you ready to play cricket(true/false)?"); Scanner scanner = new Scanner(System.in); String str = scanner.nextLine(); scanner.close(); // Convert the user input into boolean boolean answer ... Read More

1K+ Views
What is the cause of NoSuchElementException and how can we fix it in java?An exception is an issue (run time error) occurred during the execution of a program. When an exception occurred the program gets terminated abruptly and, the code past the line that generated the exception never gets executed. Each exception is represented by its respective class.Cause for NosuchElementExceptionThis is a Runtime exception i.e. it occurs at the execution time.While accessing the contents of a collection, array or other objects using the accessor methods of an Enumeration, Iterator or, tokenizer, such as next() or nextElement(), if you try to ... Read More

236 Views
When you call a method at illegal or inappropriate time an IlleagalStateException is generated.For example, the remove() method of the ArrayList class removes the last element after calling the next() or previous methods.After removing the element at the current position you need to move to the next element to remove it i.e. per one call of the next() method you can invoke this remove() method only once.Since the initial position of the list (pointer) will be before the first element, you cannot invoke this method without calling the next method.If you invoke the remove() method otherwise it throws an java.lang.IllegalStateException.Example: ... Read More

431 Views
An exception is an issue (run time error) occurred during the execution of a program. When an exception occurs the program gets terminated abruptly and, the code past the line that generated the exception never gets executed. Each exception is represented by its respective class.NosuchElement ExceptionThis is a Runtime exception i.e. it occurs at the execution time.While accessing the contents of a collection, array or other objects using the accessor methods of an Enumeration, Iterator or, tokenizer, such as next() or nextElement(), if you try to get the elements from an empty object, or if you try to get the ... Read More

2K+ Views
An exception is an issue (run time error) occurred during the execution of a program. For understanding purpose let us look at it in a different manner.Generally, when you compile a program, if it gets compiled without a .class file will be created, this is the executable file in Java, and every time you execute this .class file it is supposed to run successfully executing each line in the program without any issues. But, in some exceptional cases, while executing the program, JVM encounters some ambiguous scenarios where it doesn’t know what to do.Here are some example scenarios −If you ... Read More

1K+ Views
Whenever you need to create an object which cannot be changed after initialization you can define an immutable object. There are no specific rules to create immutable objects, the idea is to restrict the access of the fields of a class after initialization.A Set is an interface in collection framework, which does not allow duplicate values.You need to keep following points in mind while creating an immutable set −We should not be able to add or delete elements from it.we should not be able to add null values to an immutable set.Once you create an immutable set you cannot add ... Read More

785 Views
In most scenarios if you try to write contents to a file, using the classes of the java.io package, the file will be overwritten i.e. data existing in the file is erased and the new data is added to it.But, in certain scenarios like logging exceptions into a file (without using logger frame works) you need to append data (message) in the next line of the file.You can do this using the Files class of the java.nio package. This class provides a method named write() which acceptsAn object of the class Path, representing a file.A byte array holding the data ... Read More

2K+ Views
The public static void main(String args[]) is the entry point of a Java program Whenever you execute a program the JVM searches for the main method and starts executing the contents of it. If such method is not found the program gets executed successfully, but when you execute the program it generates an error.As the matter of fact you should declare the main method with public static as modifiers, void return type and String arguments if you change anything, JVM doesn’t considers as the entry point method and prompts an error at run time.Therefore, you cannot change the return type ... Read More

444 Views
Whenever you make a method final, you cannot override it. i.e. you cannot provide implementation to the superclass’s final method from the subclass.i.e. The purpose of making a method final is to prevent modification of a method from outside (child class).Still, if you try to override a final method a compile time error is generated.Exampleinterface Person{ void dsplay(); } class Employee implements Person{ public final void dsplay() { System.out.println("This is display method of the Employee class"); } } class Lecturer extends Employee{ public void dsplay() { System.out.println("This is display method of ... Read More