Found 9326 Articles for Object Oriented Programming

Java Program to show the Nesting of Methods

Rudradev Das
Updated on 13-Apr-2023 11:58:33

4K+ Views

Nesting of methods is a hybrid function calling method in Java, which can call another method in the same class. There are two types of nested classes are available in a Java environment. Non-static nested class (also known as , the inner class) Static nested class A non-static nested class (or, inner class) is a defined class within a particular class. It also contains some outer classes with some access authorities. In this method, we can use "." operator to create the instance of the inner class by using an outer class. On the other hand; a static ... Read More

Java Program to Segregate 0s on Left Side & 1s on Right Side of the Array

Rudradev Das
Updated on 11-Apr-2023 15:58:48

790 Views

Segregation is a process in the field of software engineering where a code forced to depend on those methods which are not in use. The segregation interface is known as ISP. It splits the interfaces those are vast in nature. In a java environment there are lots of advantage to implement the segregation principal. It increases the readability of the particular code. As well as helps to maintain that particular code in a convenient manner. Example: There is an array of 7s and 16s in a random manner. We have to segregate the 7s on the left side and 16s ... Read More

Java Program to Search User Defined Object From a List By using Binary Search Comparator

Rudradev Das
Updated on 11-Apr-2023 15:49:36

226 Views

Java comparator interface used to sort Java objects. A comparator class in Java compares the different objects (Obj 01, Obj 02) by invoking the "java. util. comparator". In this method the objects can be compared on the basis of the return value. It can be positive, equal or negative in comparison. The process provides user multiple sorting sequences. There are lots of method by which we can perform the comparison between two methods. public int compare class (obj 1, obj 2) - Perform comparison between two objects. public Boolean equals (obj) - Compare current object with specified object. ... Read More

Java Program to Represent Linear Equations in Matrix Form

Rudradev Das
Updated on 11-Apr-2023 15:45:06

330 Views

Java is an object oriented programming language which is used to solve and implement programs. In this segment of Java programming we are going to learn and discover about certain programs by which we can represent linear equations in Matrix form. To do these programs at first, we have to learn about linear equations and Matrix forms , their types and how they are solved by simple mathematical methods and then by Java programming. In this article we will learn how to integrate a scanner class to take an input from the user by a java build code. Where the ... Read More

Java Program to Illustrate a Method without Parameters but with Return Type

Sakshi Ghosh
Updated on 11-Apr-2023 14:58:20

3K+ Views

In Java, a method is a block of code that performs a specific task. Methods can take zero or more parameters and can also return a value. When a method returns a value, we call it a method with a return type. A method without parameters but with a return type is a method that does not take any parameters, but it returns a value. This type of method is useful when we need to perform a specific task that does not require any input parameters, but we need to get a result from that task. First, let us get ... Read More

Java Program to Illustrate a Method without Parameters and Return Type

Sakshi Ghosh
Updated on 11-Apr-2023 14:55:22

268 Views

First, let us get acquainted with the syntax, and examples, and then finally the implementation. The methods in Java are of great importance since it allows reusability of the same code, reducing the number of statements to be written within the code. There are three main parts of the method in order to make it executable. Declaration of the method. Definition of the method. Invoking the method. Method invoking is the last step, while the other two can be interchanged. The only thing to be kept in mind here is, the method must be declared before invoking it. ... Read More

Java Program to Illustrate a Method with 2 Parameters and without Return Type

Sakshi Ghosh
Updated on 11-Apr-2023 14:54:10

1K+ Views

A method without a return type is termed a void method since it returns nothing. This method can accept multiple parameters. In this tutorial, we will implement Java programs illustrating a method with two parameters and without return type. First of all, we are going to get acquainted with the syntax, examples, and, finally implementation. Syntax public static void method_name (int parameter1, int parameter2) Here, public − It is the access specifier specifying who can access this method. static − It is mandatory to make the method static to avoid errors. void − it denotes that this method returns ... Read More

Java Program to Handle Unchecked Exception

Sakshi Ghosh
Updated on 11-Apr-2023 14:50:10

739 Views

Exceptions are the unexpected circumstances occurring during the implementation of the program i.e., at the run time, that interrupt the usual working of the program. It can occur due to various reasons such as Illegal input given by the user, Failure of the devices, Loss of network connection, Physical limitations, Code faults, trying to open an unavailable file, etc. There are two major categories of Exceptions  − Checked Exception Unchecked Exception Here, we are going to deal with Unchecked Exception. The unchecked exception further includes the following − Error class Exception − OutOfMemoryError exception, StackOverflow exception, etc ... Read More

Java Program to Handle Divide by Zero and Multiple Exceptions

Shiva Keerthi
Updated on 31-May-2024 14:07:14

6K+ Views

Exceptions are the unusual events which disrupt the normal flow of execution of a program. When an exception occurs an object called exception object is generated, which contains details of exception like name, description, state of program. In this section, we are going to write a java program to handle divide by zero exception and how to handle multiple exceptions. Types of Exceptions− There are three types of exceptions − Checked exception − Checked exceptions are compile time exceptions i.e, they are checked during compilation of program.These cannot be ignored and must be handled by the programmer. ... Read More

Java Program to Find Sum of First N Odd numbers and Even numbers

Shiva Keerthi
Updated on 11-Apr-2023 14:17:21

2K+ Views

In this article, we are going to write a java program to find the sum of first n Odd and Even numbers. A number can be divided into two categories based on whether when it is divided by ‘2’ gives remainder ‘0’ or ‘1’. Odd numbers are the numbers which cannot be divided by ‘2’ or these numbers give remainder as 1 when they are divided by ‘2’. In other terms which can be written in the form of ‘2n+1’and Even numbers are numbers which can be divided by 2 i.e., these numbers give remainder as 0 when they are ... Read More

Advertisements