Java is an object-oriented programming language. Everything in Java is an object. Object-oriented means we organize our software as a combination of different types of objects that incorporate both data and behavior. Object-oriented programming (OOPs) is a methodology that simplifies software development and maintenance by providing some rules. Basic concepts of OOPs are: Object Class Inheritance Polymorphism… Continue reading Object-oriented
Month: March 2022
Simple
Java is very easy to learn, and its syntax is simple, clean and easy to understand. According to Sun Microsystem, Java language is a simple programming language because: Java syntax is based on C++ (so easier for programmers to learn it after C++). Java has removed many complicated and rarely-used features, for example, explicit pointers,… Continue reading Simple
Futures Overview
Features of Java The primary objective of Java programming language creation was to make it portable, simple and secure programming language. Apart from this, there are also some excellent features which play an important role in the popularity of this language. The features of Java are also known as Java buzzwords. A list of the most important… Continue reading Futures Overview
Overridden Methods of the superclass
If methods with the same name are defined in both superclass and subclass, the method in the subclass overrides the method in the superclass. This is called method overriding. Example 1: Method overriding Output In this example, by making an object dog1 of Dog class, we can call its method printMessage() which then executes the display() statement. Since display() is defined in both the classes, the… Continue reading Overridden Methods of the superclass
Create an enum class
Java program to create an enum class Output In the above example, we have created an enum class named Size. The class contains four constants SMALL, MEDIUM, LARGE, and EXTRALARGE. Here, the compiler automatically converts all the constants of the enum into its instances. Hence, we can call the method using the constant as objects. In this call, the this keyword is… Continue reading Create an enum class
Print object of a class
Java program to print the object Output In the above example, we have created an object of the class Test. When we print the object, we can see that the output looks different. This is because while printing the object, the toString() method of the object class is called. It formats the object in the default format. That… Continue reading Print object of a class
Implement private constructors
Java program to create a private constructor Output In the above example, we have created a private constructor of the Test class. Hence, we cannot create an object of the Test class outside of the class. This is why we have created a public static method named instanceMethod() inside the class that is used to create an object of the Test class. And from the Main class,… Continue reading Implement private constructors
Determine the class of an object
Check the class of an object using getClass() Output In the above example, we have used the getClass() method of the Object class to get the class name of the objects obj1 and obj2.
Program to perform binary search
Example Program to perform binary search on a list of integer numbers This program uses binary search algorithm to search an element in given list of elements. Output 1: Output 2:
Program for linear search – Example
Example Program: This program uses linear search algorithm to find out a number among all other numbers entered by user. Output 1: Output 2: