Category: JAVA
-
Package
Java Packages & API: A package in Java is used to group related classes. Think of it as a folder in a file directory. We use packages to avoid name conflicts, and to write a better maintainable code. Packages are divided into two categories: Built-in Packages: The Java API is a library of prewritten classes, that…
-
Encapsulation : Private,final,get and set
Encapsulation: The meaning of Encapsulation, is to make sure that “sensitive” data is hidden from users. To achieve this, you must: Private: final variable: The final keyword is a non-access modifier used for classes, attributes and methods, which makes them non-changeable (impossible to inherit or override). The final keyword is useful when you want a variable to always store the…
-
Polymorphism and method overloading
What is polymorphism? Polymorphism allows us to perform a single action in different ways. In other words, polymorphism allows you to define one interface and have multiple implementations. The word “poly” means many and “morphs” means forms, So it means many forms. Types of polymorphism: In Java polymorphism is mainly divided into two types: Compile-time…
-
Constructor and constructor overloading
What is constructor? A Java constructor is special method that is called when an object is instantiated. In other words, when you use the new keyword. The purpose of a Java constructor is to initializes the newly created object before it is used.At the time of calling constructor, memory for the object is allocated in the memory.(we use new keyword to…
-
this keyword
this keyword: In Java, this is a keyword which is used to refer current object of a class. we can it to refer any member of the class. It means we can access any instance variable and method by using this keyword(it can be used to differentiate local and instance variables in the class). The main purpose of using this keyword…
-
Return type and void purpose
Return type: It is used to perform certain tasks or processing of data in the program to yield the expected results. A method can accept data from outside and can also return the results. To return the result, a return statement is used inside a method to come out of it to the calling method.…
-
Void keyword and void method
void keyword: Void keyword is used with the method declaration to specify that this particular method is not going to return any value after completing its execution. We can’t assign the return type of a void method to any variable because void is not a data type. void method: Look at the following program that demonstrate how a method is…
-
static and non-static variable
static variable: If you declare any variable as static, it is known as a static variable. Advantages of static variable: It makes your program memory efficient (i.e., it saves memory). Non -static variable: A non-static variable is initialized every time a new instance of its class is created, and as such there can be multiple copies of…
-
Object oriented programming
What is OOPS? Object-Oriented Programming System (OOPs) is a programming concept that works on the principles of abstraction, encapsulation, inheritance, and polymorphism. It allows users to create objects they want and create methods to handle those objects. The basic concept of OOPs is to create objects, re-use them throughout the program, and manipulate these objects to…
-
Object creation and call a method
Overview: In this blog about creating and object, call a method and Method Parameters. Creating an Object: An object is created from a class. In Java, the new keyword is used to create new objects. There are three steps when creating an object from a class − Call a Method: To call a method in…