
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 7442 Articles for Java

9K+ Views
An interface in Java is similar to class but, it contains only abstract methods and fields which are final and static.Since Java8 static methods and default methods are introduced in interfaces.Default Methods - Unlike other abstract methods these are the methods can have a default implementation. If you have default method in an interface, it is not mandatory to override (provide body) it in the classes that are already implementing this interface.In short, you can access the default methods of an interface using the objects of the implementing classes.Exampleinterface MyInterface{ public static int num = 100; public default void ... Read More

2K+ Views
Inheritance is a relation between two classes where one class inherits the properties of the other class. This relation can be defined using the extends keyword as −public class A extends B{ }The class which inherits the properties is known as sub class or, child class and the class whose properties are inherited is super class or, parent class.In inheritance a copy of super class members are created in the sub class object. Therefore, using the sub class object you can access the members of the both classes.Exampleclass Super{ int a =100; int b = 200; public void ... Read More

355 Views
The process of wrapping up the data and, the code acting on the data together is known as encapsulation. This is a protective mechanism where we hide the data of one class from (an object of) another.Since, variables hold the data of a class to encapsulate a class you need to declare the required variables (that you want to hide) private and provide public methods to access (read/write) them.By doing so, you can access the variables only in the current class, they will be hidden from other classes, and can be accessed only through the provided methods. Therefore, it is ... Read More

3K+ Views
The default methods are introduced in an interface since Java8. Unlike other abstract methods these are the methods can have a default implementation. If you have default method in an interface, it is not mandatory to override (provide body) it in the classes that are already implementing this interface.In short, you can access the default methods of an interface using the objects of the implementing classes.Exampleinterface MyInterface{ public static int num = 100; public default void display() { System.out.println("display method of MyInterface"); } } public class InterfaceExample implements MyInterface{ public static void main(String ... Read More

13K+ Views
Inheritance is a relation between two classes where one class inherits the properties of the other class. This relation can be defined using the extends keyword as −public class A extends B{ }The class which inherits the properties is known as sub class or, child class and the class whose properties are inherited is super class or, parent class.In inheritance a copy of super class members is created in the sub class object. Therefore, using the sub class object you can access the members of the both classes.Multiple inheritanceThere are various types of inheritance available namely single, multilevel, hierarchical, multiple ... Read More

13K+ Views
Yes, an Enum implements an Interface in Java. It can be useful when we need to implement business logic that is tightly coupled with a specific property of a given object or class. Before implementing the interface with an enum, let's discuss enums and interfaces in Java with a code snippet for better understanding. Enum in Java In Java, an Enum (i.e., an enumeration) is a special data type added in Java version 1.5. Enums are constants by default; the names of an enum type's fields are in uppercase letters. In the Java programming language, you can define an Enum ... Read More

2K+ Views
A JLabel is a subclass of JComponent class and an object of JLabel provides text instructions or information on a GUI. A JLabel can display a single line of read-only text, an image or both text and an image. A JLabel can explicitly generate a PropertyChangeListener interface. We can also implement a moving text in a JLabel by using a Timer class, it can set a timer with speed(in milliseconds) and this as an argument.Exampleimport java.awt.*; import java.awt.event.*; import java.util.*; import javax.swing.*; import javax.swing.Timer; public class MovingTextLabel extends JFrame implements ActionListener { private JLabel label; public MovingTextLabel() { setTitle("MovingTextLabel"); label= new JLabel(" ... Read More

12K+ Views
In Java, the cannot find symbol error occurs when we try to reference a variable that is not declared in the program or when we try to access a class that is not declared or imported. Possible Causes of 'Cannot Find Symbol' Error Below is a list of some possible causes of the 'cannot find symbol' error in Java - Using a variable that is not declared or outside the code. Using wrong cases ("tutorials" and "Tutorials" are different) or making spelling mistakes. The packaged class has ... Read More

637 Views
This article will discuss the wait() and wait(long timeout) methods, along with a suitable example that explains when to call these methods in a thread in Java. The wait() Method In Java, the wait() method is used in multithreading and causes the current thread to "wait" until another thread calls notify() or notifyAll() on the same object. When the wait() method is called, the thread moves from the running to the waiting state and resumes only when notified, if not a deadlock will be formed. Note: Call the wait() method only when the thread should wait without any time limit. Following ... Read More

1K+ Views
The java.lang.Runtime class is a subclass of Object class, can provide access to various information about the environment in which a program is running. The Java run-time environment creates a single instance of this class that is associated with a program. The Runtime class does not have any public constructors, so a program cannot create its own instances of the class. A program must call the getRuntime() method to get a reference to the current Runtime object. The important methods of Runtime class are addShutdownHook(), exec(), exit(), freeMemory(), gc(), halt() and load(). Syntax public class Runtime extends Object Example public class RuntimeTest { ... Read More