OOPs concept in java

 What is OOPs?

  • OOPS, the standard form is Object Oriented Programming Structure.
  • It is one of the ways of solving complex problem into the smaller problem by using objects.
  • Before using OOPS, programs were written in a procedural language i.e. C language, they were nothing but a long list of instructions.

Problems in C and overcome by OOPS:

  • If declare global variable then all function known that value because of the global variable is public so anyone can access i.e. here not possible the particular function only knowns the global value and data are not secure.
  • But, in the oops concept of having and managing objects and classes in java, the program key building block is Data. Therefore, secure data is tightly using access specifiers, classes, encapsulation, and so on.

Uses of oops or why it used?

  • Reducing program lines.
  • Data secure.
  • Easy way to find errors.
  • Execution speed is fast.

Features of oops in Java:

  • Class and object
  • Methods
  • Constructor and Destructor
  • Arrays
  • Encapsulation
  • Abstraction
  • Polymorphism
  • Inheritance
  • Interfaces
  • Exception handling
  • Threads
  • Method overloading and overriding

Share:

LISTAGG function in SQL

LISTAGG function:

   Ø LISTAGG function used to concatenate multiple row of a string into a single row.

Syntax:

  1. LISTAGG(clm_name, ‘Separator’) within group (order by clm_name) from table_name;

Example:

  1. Select ename from emp;

Output:


Example: 1  LISTAGG function

  1. Select LISTAGG(ename,',') WITHIN GROUP (order by ename) from emp;

Output:

Example: 2

  1. Select LISTAGG(ename,';') WITHIN GROUP (order by empno) from emp;

Output:

Explanation:

   v LISTAGG is the keyword

   v Ename column name of the emp table

   v ; is the separator (User can change the separator whatever developer needs)

   v WITHIN GROUP (order by clm_name) default through the syntax

   v Emp table_name.

Disadvantages:

   Ø The problem of using LISTAGG function is, if we trying to concatenate          more than 4000 characters it’s thrown the exception.

Example:

  1. SELECT LISTAGG(party_name,',') WITHIN GROUP (order by party_id) FROM hz_parties;

Note: HZ_Parties table have above 4000 characters string in the table so oracle will throw the error.

The output report will be,

Solution:

  1. SELECT LISTAGG(party_name, '; ' ON OVERFLOW TRUNCATE '...') WITHIN GROUP (order by party_name)

    FROM HZ_PARTIES;

Explanation:

   Ø ON OVERFLOW TRUNCATE or ON OVERFLOW ERROR is used to truncate the values.



Share:

Unconditional control statement

 Jump statements or unconditional control statement:

  • Unconditional control statement is also called a jump statement.
  • There are three kinds of jumping statements,

*Break

*Continue

Break statement:

  • The break statement is used to execute particular blocks only.
  • For example, the switch case.

Syntax:

  1. Loop or if conditions

    break;

    or

    lable_name: Loop or if conditions

    break lable_name;

Example program:

  1. package exampleprogram;

    import java.util.Scanner;

    public class Break_Example {

        public static void main(String[] args) {

            int[] num = {1000, 2000, 3000, 4000};

            boolean found = false;

            Scanner input = new Scanner(System.in);

            go:

            for (int i = 1; i <= 3; i++) {

                System.out.println("Enter your PIN number : ");

                int pin = input.nextInt();

                for (int n : num) {

                    if (n == pin) {

                        found = true;

                        break;

                    } 

                }

                if (found) {

                    System.out.println("Entered PIN number is correct.");

                    System.out.println("You can choose the below options \n1.Cash withdrawal \n2.Cash deposit \n3.Mini Statement");

                    break;

                } else {

                    System.out.println("Sorry try again!!!");

                    System.out.println("You let with " + (3 - i) + " more options...");

                    System.out.println("Entered PIN number " + pin + " is incorrect.\nPlease re-enter the pin number");

                }

            }

        }

    }

Output:

Continue statement:

  • Continue statement is used inside loops.
  • Whenever a continue statement is encountered inside a loop, control directly jumps to the beginning of the loop for the next iteration, skipping the execution of statements inside the loop’s body for the current iteration.

Syntax:

  1. Loop or if conditions

    continue;

    or

    lable_name: Loop or if conditions

    continue lable_name;

Example program:

  1. package exampleprogram;

    import java.util.Scanner;

    public class Continue_Example {

        public static void main(String args[]) {

            Scanner read = new Scanner(System.in);

            reading:

            for (int i = 1; i <= 3; i++) {

                System.out.print("Enter a even number: ");

                int value = read.nextInt();

                verify:

                if (value % 2 == 0) {

                    System.out.println("You are enterd even number : "+value);

                    break reading;

                } else {

                    System.out.println("Please enter even number only.");

                    System.out.println("You can enter " + (3 - i) + " times only...");

                    continue reading;

                }

            }

        }

    }

Output:

Share:

Decision making in java

 Control statements:

The control statement is nothing but, It is used to control your program.

That means you are having the control by how it executes based on logic and based on your requirements.

It is one of the decision makings logic in the programming language.

Types of control statement:

There are two types of control statements,

1. Conditionalcontrol statement

1.1. Branching statements

*If statement

*If – else statement

*Nested if....else statement

*If ....else ladder

*Switch case

1.2. Looping statements

*While

*Do-While

*Loop

2. Unconditional control statement

*Break

*Continue

*Goto

Note:

Each type have links, so please press the link to learn deeply.

Share:

variables in PL/SQL

 What are variables?

   v Variables are place holder in computer memory that holds some data. We can call them variables because which can be changed any point in your program.

   v Every variable must have a valid name, a data type and a data width.

   v In PL/SQL every variable must be declared prior to its use and the declaration of the variables or even other objects can only be done in the declaration section of the PL/SQL block.

There are two ways assigning the value in PL/SQL:

Example: 1

  1. DECLARE

       v_var   VARCHAR2 (50) := 'Welcome to PL/SQL';

    BEGIN

       DBMS_OUTPUT.put_line (v_var);

    END;

Explanation:

   §  V_var is the variable name, the datatype of the variable VARCHAR and the width is 50.

   §  := is the assignment operator for assigning value into the variable.

   §  'Welcome to PL/SQL' is the value must be enclosed with single quotes (‘’)

   §  In this example we DECLARING and INITIALIZING the variable in DECLARE section.

Output:

Example: 2

  1. DECLARE

       v_var   VARCHAR2 (50);

    BEGIN

       v_var := 'Welcome';

       DBMS_OUTPUT.put_line (v_var);

    END;

Explanation:

 v We were initializing the variable in the BEGIN Section.

 Output:



 

Share:

Conditional control statement type two in java

Looping statements:

  • It is used to execute continually until the condition becomes false.
Types:
  • While
  • Do while
  • For
1. While:
  • It first checks the condition then executes the result until becomes false.
Syntax:

 while (condition)
{
          Statements;
}

Example program for while condition:

package exampleprogram;

public class Looping_program {

    public static void main(String[] args) {

        int i = 1, sum = 0;

        while (i <= 5) {

            sum = sum + i;

            i++;

        }

        System.out.println("\n The sum of numbers upto 5 is : " + sum);

    }

}

Output:
2. do while:
  • It is first to perform some operation after that check the conditions.
  • It's opposite to the while condition.
Syntax:

do
{
          Statements;
}
while (condition);

Example program for do while condition:

package exampleprogram;
public class Looping_program {
    public static void main(String[] args) {
        int i = 1, sum = 0;

        do {
            sum = sum + i;
            i++;
        } while (i <= 5);
        System.out.println("\n The sum of numbers upto 5 is : " + sum);
    }
}

Output:
3. for loop:
  • It is used to execute a set of instructions repeatedly until the condition becomes false.
Syntax:

 for(initialization ;condition ;increment or decrement)
{
          Statement;
}

Example program for for loop:

package exampleprogram;

public class Looping_program {

    public static void main(String[] args) {

        int i;

        for (i = 1; i <= 10; i++) {

            System.out.println(i);

        }

    }

}

Output:
Share:

Recent Posts

Service Support

Need our help to Learn or Post New Concepts Contact me