Java Package class

Package class provides information about a package like a package name, implementation title, etc. Java Package class Example package com.w3schools; public class PackageClassTest { public static void main(String args[]) { Package package1 = Package.getPackage(“java.lang”); System.out.println(“package name: ” + package1.getName()); System.out.println(“Specification Title: ” + package1.getSpecificationTitle()); System.out.println(“Specification Vendor: ” + package1.getSpecificationVendor()); System.out.println(“Specification Version: ” + package1.getSpecificationVersion()); System.out.println(“Implementaion … Read more

Java Static import

Static import is a feature that provides the facility to access static members of a class directly without using a class name. Java Static import Example package com.w3schools.display; public class Display { public static void displayText(String text){ System.out.println(text); } } package test; import static com.w3schools.display.Display.*; public class Test { public static void main(String args[]){ displayText(“Hello … Read more

Java Access Modifier

Access modifiers Access modifiers are keywords used for defining the accessibility of classes, methods, and data members. Types of access modifiers. Private. Default Protected Public Private: Data members, methods, and constructors that are declared with private access modifiers can be accessed into that class only. package com.w3schools; class Student { //private members of the class … Read more

Package in java

The package is a namespace that is used to group logically related classes and interfaces. Advantages/Benefits of the package in Java A package provides a unique namespace. A package provides access protection. A Package provides a grouping of logically related classes and interfaces that are easy to maintain. How to create a package? A package … Read more

Java Constructor

Constructor A constructor is a special member (method) of a class that is used to initialize the state of an object. It provides the values to the data members at the time of object creation which is why it is known as a constructor. Characteristics of the constructor A constructor has the same name as … Read more

Java Interface

The dictionary meaning of interface is “A point where two systems, subjects, organizations, etc., meet and interact.” Interface in the real world You can see a number of interface examples. Let us take the example of a TV. You press the change channel button of the TV remote and the channel is changed. Here remote … Read more

Java Abstract Class

Abstract class in the real world Let us take an example of graphic objects. Different graphic objects are there such as circles, rectangles, triangles, etc. They all have states defined by their positions, color, etc., and behavior defined by drawing, resizing, calculating size, etc. All these object types have common things but with different implementations. … Read more

Java Command Line Arguments

Command line arguments are the arguments that are passed at run time to the Java program. Arguments are used as input for the program. There is no limit on the number of command line arguments that can be passed to the program. Command line arguments are string by default because they are received by the … Read more

Java Inheritance

Inheritance refers to a way of implementing an IS-A relationship i.e. parent-child relationship. A subclass inherits the superclass properties like data members and methods. Inheritance is a way of code re-usability. Let us consider an example of parent and child. A child inherits the properties of its parent. Use of Inheritance Code re-usability. Run-time polymorphism. … Read more

Java Association Aggregation And Composition

Association is a mechanism to define a relationship between classes of objects. Two classes are said to be associated with each other if they are related to each other in some way. Types of Association Is-A Has-A Aggregation Composition Important definitions for association Subclass/child class/ derived class A class which is derived from another class. … Read more