Writing an interface is similar to writing a class. But a class describes the attributes and behaviors of an object. And an interface contains behaviors that a class implements. An interface is similar to a class in the following ways: An interface is written in a file with a .java extension, with the name of […]
Java
Java Packages
A Package can be stated that a grouping of related types (classes, interfaces, enumerations, and annotations ) providing access protection and namespace management. Some of the existing packages in Java are: java.io – classes for input , output functions are bundled in this package. java.lang – bundles the fundamental classes. Creating a Package The package […]
Java Encapsulation
Encapsulation is a more useful fundamental OOP concept. The other three are inheritance, polymorphism, and abstraction. Encapsulation in Java is data variables and methods together as a single unit. In encapsulation, the variables of a class will be hidden from other classes, and can be accessed only through the methods of their current class. Therefore, […]
Java Abstraction
An abstract method is a method that is declared without an implementation (without braces, and followed by a semicolon): abstract void walk();. The user will have the information on what the object does instead of how it does it. Abstract Class Abstraction is achieved using abstract classes and interfaces. To use an abstract class, you […]
Java Polymorphism
Polymorphism, which refers to the idea of “having many forms”, occurs when there is a hierarchy of classes related to each other through inheritance. A call to a member method will cause a different implementation to be executed, depending on the type of object invoking the method. Dog and Cat are classes that inherit from […]
Java Inheritance
The class which inherits the properties of others is known as subclass (derived class, child class) and the class whose properties are inherited is known as superclass (base class, parent class). extends Keyword The extends is a Java keyword, which is used in inheritance process of Java. It is a keyword that indicates the parent […]
Java Overriding
In this post, we will learn the OOP of Java overriding means to override the functionality of an existing method. A subclass can define a behavior that’s specific to the subclass type, meaning that a subclass can implement a parent class method based on its requirement. This is called Overriding. Example: class Animal { public […]
Java – Inner classes
Java supports nesting classes; a class can be a member of another class. Creating an inner class is quite simple. Just write a class within a class. Unlike a class, an inner class can be private. Once you declare an inner class private, it cannot be accessed from an : Nested Classes In java have […]
Java File and I/O
java.io packager provides many data such as primitives, object, localized characters, etc. Stream Sequence of data is called stream. There are two types of Streams: InPutStream: The InputStream is used to read data from a source. OutPutStream: The OutputStream is used for writing data to a destination. Byte Streams It uses byte streams to perform […]
Java Methods
A method is a set of statements to perform an operation, methods are also known as procedures or functions. Creating Method following example to explain the syntax of a method: Syntax: public static int methodName(int x, int y) { // body } Here, public static − modifier int − return type methodName − name of […]