
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 9105 Articles for Object Oriented Programming

2K+ Views
Java is a statically typed, object-oriented programming language that needs a main method as an entry point for running. But it is possible to develop Java programs without a main method under certain conditions. Different Approaches The following are the different approaches for creating a program without a main method in Java − Using Static Blocks Using a Servlet Using a JavaFX Application Using Static Blocks (Before Java 7) In previous implementations of Java (prior to Java 7), a program was possible to run with a ... Read More

1K+ Views
For two given matrix each of size m×n, write a Java program to subtract them. The matrix has a row and column arrangement of its elements. A matrix with m rows and n columns can be called as m×n matrix. Individual entries in the matrix are called element and can be represented by a[i][j] which means that the element a is present at the ith row and jth column. Note that two matrix can be subtracted if and only if the number of rows and columns of each matrix are equal. Now, let's understand the problem statement with an example ... Read More

5K+ Views
ExampleFollowing is the required program.Live Demopublic class Tester { public static int getThirdSmallest(int[] a) { int temp; //sort the array for (int i = 0; i < a.length; i++) { for (int j = i + 1; j < a.length; j++) { if (a[i] > a[j]) { temp = a[i]; a[i] = a[j]; a[j] = temp; } } } //return third smallest element return a[2]; } public static void main(String args[]) { int a[] = { 11,10,4, 15, 16, 13, 2 }; System.out.println("Third Smallest: " +getThirdSmallest(a)); } }OutputThird smallest: 10

2K+ Views
Following is the required program.ExampleLive Demopublic class Tester { static int factorial(int n) { if (n == 0) return 1; else return (n * factorial(n - 1)); } public static void main(String args[]) { int i, fact = 1; int number = 5; fact = factorial(number); System.out.println(number + "! = " + fact); } }Output5! = 120

2K+ Views
Following is the required program.ExampleLive Demopublic class Tester { public static void main(String args[]) { int i, m = 0, flag = 0; int n = 41;// it is the number to be checked m = n / 2; if (n == 0 || n == 1) { System.out.println(n + " not a prime number"); } else { for (i = 2; i

2K+ Views
Following is the required program.ExampleLive Demopublic class Tester { static int n1 = 0, n2 = 1, n3 = 0; static void fibbonacci(int count) { if (count > 0) { n3 = n1 + n2; n1 = n2; n2 = n3; System.out.print(" " + n3); fibbonacci(count - 1); } } public static void main(String args[]) { int count = 5; System.out.print(n1 + " " + n2); fibbonacci(count - 2); } }Output0 1 1 2 3

3K+ Views
Following is the required program.ExampleLive Demopublic class Tester { public static void main(String args[]) { int n1 = 0, n2 = 1, n3, i, max = 5; System.out.print(n1 + " " + n2); for (i = 2; i < max; ++i) { n3 = n1 + n2; System.out.print(" " + n3); n1 = n2; n2 = n3; } } }Output0 1 1 2 3

4K+ Views
In this article. we will learn about break, continue, and label in Java loop. There are cases when you would want to manage the flow of your loop, that is, skip some iterations or terminate the loop altogether. This is where break, continue, and label statements are used. Break Statement A break statement interrupts the normal execution of a loop and causes it to exit before being completed. The loop will terminate and the flow of control will transfer to the next statement immediately following the loop, when the break function is called. It can be used in any loop statement, ... Read More

704 Views
Java programming language provides following types of decision making or branching statements.Java programming language provides following types of decision making statements.Sr.No.Statement & Description1if statementAn if statement consists of a boolean expression followed by one or more statements.2if...else statementAn if statement can be followed by an optional else statement, which executes when the boolean expression is false.3nested if statementYou can use one if or else if statement inside another if or else if statement(s).4switch statementA switch statement allows a variable to be tested for equality against a list of values.