Java is a programming language that follows the Object-Oriented Programming paradigm. One of the pillars of OOPs is Inheritance, where you can find a relationship between two classes as Parent and Child. This relationship allows these classes to reuse each other's attributes and methods. Java classes can relate to each other in many ways such as, Is-A relationship and Has-A relationship. In this article, we are going to learn the concept of Has-A relationship in Java through examples. HAS-A Relationship in Java Has-A relationship is a type of association where two classes are linked to each other through objects. Here, ... Read More
Static Methods and Static Blocks Static methods belong to the class and they will be loaded into memory along with the class; you can invoke them without creating an object. (using the class name as reference). Whereas a static block is a block of code with a static keyword. In general, these are used to initialize the static members. JVM executes static blocks before the main method at the time of class loading. Example The following example demonstrates the usage of static blocks and static methods in Java - public class Sample { ... Read More
Java Virtual Machine is a program/software that runs Java applications. It takes Java bytecode (.class files) and converts the bytecode (line by line) into machine-understandable code, line by line so the processor can understand and execute it. JVM contains a module(components) known as a class loader. It is responsible for loading the program into memory and preparing it to run. Class Loader performs three main tasks - It Loads the class into the memory. ... Read More
While reading the contents of a file using a Java program, we may reach the end of the file abruptly; in such cases, EOFException (End Of File) is thrown. Especially, this exception occurs while reading data using the InputStream objects, such as DataInputStream. In other scenarios, a specific value will be thrown when the end of the file is reached. Why Does the EOFException Occur The EOFException occurs when a stream reaches the end of the file while reading its contents. If we consider the DataInputStream class, it provides various methods such as readBoolean(), readByte(), readChar(), etc, to read primitive ... Read More
In this article, we will learn about the differences between a JScrollBar and a JScrollPane in Java. A JScrollBar is a component, and it doesn't handle its own events whereas a JScrollPane is a Container and it handles its own events and performs its own scrolling. A JScrollBar cannot have a JScrollPane whereas a JScrollPane can have a JScrollBar. JScrollBar The object of the JScrollBar class is used to add horizontal and vertical scrollbar which allow the user to select items between a specified minimum and maximum values. A JScrollBar class is an implementation of a scrollbar and inherits the ... Read More
In this article, we will learn about the importance of the CardLayout class in Java. In Swing, we usually have to manage a set of views and panels in a single container. The CardLayout class provides you with a flexible and powerful method to complete this, allowing you to switch between various components, such as cards in a deck. What is CardLayout? CardLayout is a layout manager in the Java AWT package. It is different from the other layouts, where the other layout managers attempt to display all the components within the container at once, the CardLayout displays only one ... Read More
In this article, we will learn to disable the maximize button of a JFrame in Java. When creating Swing GUIs in Java, we might occasionally want to prevent users from maximizing certain windows. Removing the maximize button will do the trick for dialog windows, tool windows, or any window where a fixed size needs to be kept. What is a JFrame? A JFrame is a class from javax. swing package and it can extend java.awt.frame class. It is a top-level window with a border and a title bar. A JFrame class has many methods that can be used to customize ... Read More
In this article, we will learn about the implementation of a JToggleButton in Java. The JToggleButton is a basic Swing component in Java that is used to represent a two-state button, i.e., selected or unselected. It is therefore the best component to use when adding on/off or mode selection functionality to Java applications. JToggleButton A JToggleButton is an extension of AbstractButton, and it can be used to represent buttons that can be toggled ON and OFF. When JToggleButton is pressed for the first time, it remains pressed and it can be released only when it is pressed for the second ... Read More
The layout managers are used to automatically decide the position and size of the added components. In the absence of a layout manager, the position and size of the components have to be set manually. The setBounds() method in Java is used in such a situation to set the position and size. To specify the position and size of the components manually, the layout manager of the frame can be null. The setBounds() Method The setBounds() is a method inherited from Java's AWT (Abstract Window Toolkit) and Swing libraries that enables manual positioning and sizing of GUI components. The setBounds() ... Read More
In this article, we have an unsorted array. Our task is to find the kth maximum element of that array using C++. Here is an example to understand the meaning of k. If k =2, you can say the second highest value, for k =3, the third highest value. The approaches that we will be using are mentioned below: Using Sorting Using Max Heap Using Min Heap Using Quick Select Using Binary Search Tree Using ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP