Friday, September 11, 2020

Interface In JAVA

                    Interface In JAVA



Interface:

An interface in Java is a blueprint of a class. It has static constants and abstract methods.

The interface in Java is a mechanism to achieve abstraction. There can be only abstract methods in the Java interface, not method body. It is used to achieve abstraction and multiple inheritance in java

It cannot be instantiated just like the abstract class.

In other words, you can say that interfaces can have abstract methods and variables. It cannot have a method body.



interface interf{

public void m1();
public void m2();
}

class test implements interf
{
public void m1(){

}                             

public void m2(){           

}
}

**** class should give implementation for all methods in interface and they have same access specifier.

****   if you not implemented all methods declare class as abstract .                                                 




Abstract Class in Java

              Abstract Class in Java

Abstarct CLASS:

Definition: A class which is declared with the abstract keyword is known as an abstract class in Java. It can have abstract and non-abstract methods (method with the body).

i)A class with partial implementation.
ii)NO one can create a object.
iii)No one can call its methods.
iv)Event though class do not contain abstract method we can declare class as abstract
v)It can contain abstract and non abstract method also

***Every child class must provide abstract method implementation.



Example;
public abstarct class vechicle
{

public abstract int Noof whlees();

}

class bus extends vechicle{
public int noof wheels(){
return 6;
}
}

class car extends vechicle{
public int noof wheels(){
return 4;
}
}

class test{
bus b =new bus();
b.noof wheels();
car c= new car();
c.noof  wheels();
}
}

OutPut:
6
4







Why JAVA doesn't Support Multiple Inheritance with Classes

  Why JAVA doesn't Support Multiple Inheritance with Classes?

When one class extends more than one classes then this is called multiple inheritance. For example: Class C extends class A and B then this type of inheritance is known as multiple inheritance. Java doesn’t allow multiple inheritance. In this article, we will discuss why java doesn’t allow multiple inheritance and how we can use interfaces instead of classes to achieve the same purpose.




Lets Understand with an Example
// First Parent class 
class Parent1 
    void fun() 
    { 
        System.out.println("Parent1"); 
    } 
  
// Second Parent Class 
class Parent2 
    void fun() 
    { 
        System.out.println("Parent2"); 
    } 
  
// Error : Test is inheriting from multiple 
// classes 
class Test extends Parent1, Parent2 
   public static void main(String args[]) 
   { 
       Test t = new Test(); 
       t.fun(); 
   } 

t.fun()-> Compiler Do not able understand to call func() of which class. Because both Parent1,Parent2 both are having func(). Due to this ambiguity Java does not support multiple inheritance using classes.






Inheritance in Java

                                    Inheritance in Java

Inheritance is an important pillar of OOP(Object Oriented Programming).
Inheritance is the property of an object to acquire all its properties and behaviour of its parent object.

Syntax :

class derived-class extends base-class  
{  
   //methods and fields  
}  


Types:

1.single Inheritance
2.multilevel Inheritance
3.Hierarchical Inheritance

1. single Inheritance : single inheritance enables derived class to inherit properties and behaviour from a single parent class.



2.multilevel inheritance: multilevel inheritance enables derived class to inherit properties and behaviour from  parent class which is derived from another parent class.


 3.Hierarchical Inheritance: In Hierarchical Inheritance, one class serves as a superclass (base class) for more than one sub class.In below image, the class A serves as a base class for the derived class B,C and D.

4.Multiple Inheritance (Through Interfaces) : In Multiple inheritance ,one class can have more than one superclass and inherit features from all parent classes. Please note that Java does not support multiple Inheritance with classes. In java, we can achieve multiple inheritance only through Interface. In image below, Class C is derived from interface A and B.






5.Hybrid Inheritance(Through Interfaces):
It is a mix of two or more of the above types of inheritance. Since java doesn’t support multiple inheritance with classes, the hybrid inheritance is also not possible with classes. In java, we can achieve hybrid inheritance only through Interface.






Object Oriented Programming Concepts

                                    Object Oriented Programming Concepts


1. OOPS is a methodology to design a program using Class and objects.This concept is useful in representing real world entities.

2. Class(ex map) is a blueprint of object(building). class defines structure of an object.

3. object is created with new keyword(Heap memory). new keyword used to responsible for allocating memory of class.

4.A class can can have no of objects.

5.Object is Real world entity which has properties and behaviour.

Constructor:

i)constructor is member method of a class

ii)It has same name as class

iii)No return type

iv)used to initialize member

v)automatically called when you create a object





what is jdk, jre and jvm

                                  what is jdk, jre and jvm?




JDK -JAVA Development Kit:

1. It provides environment to develop and run java application(conatins JRE+ Development tools(javac, java))

2.It exists physically .

3. JDK Mostly Used By Java Developers.

JRE-Javaruntime environment:

1. It provides only runtime environment(JVM+Set of libary classes+otherfiles)

2.physically exists.

3.It is the implementation of JVM.

4.It is used by only Clients.


JVM-Java Virtual Machine:

1.It responsible to run java program line by line(Interpreter).Java bytecode can be executed. 

2.It is an abstract machine. physically not exists.

3.JVM acts like a run-time engine which calls the main method present in the Java code

For Detailed explanation watch this video.





Sunday, September 6, 2020

Joins DBMS-2

 

SQL | Join (Left, Right Joins)

LEFT JOIN: This join returns all the rows of the table on the left side of the join and matching rows for the table on the right side of join. The rows for which there is no matching row on right side, the result-set will contain null. LEFT JOIN is also known as LEFT OUTER JOIN.

Syntax:
SELECT table1.column1,table1.column2,table2.column1,....
FROM table1 
LEFT JOIN table2
ON table1.matching_column = table2.matching_column;

                                              
                                                            Left Join

RIGHT JOIN: RIGHT JOIN is similar to LEFT JOIN. This join returns all the rows of the table on the right side of the join and matching rows for the table on the left side of join. The rows for which there is no matching row on left side, the result-set will contain null. RIGHT JOIN is also known as RIGHT OUTER JOIN.

Syntax:

SELECT table1.column1,table1.column2,table2.column1,....
FROM table1 
RIGHT JOIN table2
ON table1.matching_column = table2.matching_column;


RIGHT JOIN







Joins in DBMS

 

SQL | Join (Inner and Full Joins)


A SQL Join statement is used to combine data or rows from two or more tables based on a common field between them. Different types of Joins are:

  • INNER JOIN
  • LEFT JOIN
  • RIGHT JOIN
  • FULL JOIN

INNER JOIN: The INNER JOIN keyword selects all rows from both the tables as long as the condition satisfies. This keyword will create the result-set by combining all rows from both the tables where the condition satisfies i.e value of the common field will be same.


                                                                  Inner Join

Syntax:

SELECT table1.column1,table1.column2,table2.column1,....
FROM table1 
INNER JOIN table2
ON table1.matching_column = table2.matching_column;


FULL JOIN: FULL JOIN creates the result-set by combining result of both LEFT JOIN and RIGHT JOIN. The result-set will contain all the rows from both the tables. The rows for which there is no matching, the result-set will contain NULL values.


                                                     Full Join

Syntax:
SELECT table1.column1,table1.column2,table2.column1,....
FROM table1 
FULL JOIN table2
ON table1.matching_column = table2.matching_column;



For More Details Watch this video:



Acid Properties DBMS

 

ACID Properties in DBMS


transaction is a single logical unit of work which accesses and possibly modifies the contents of a database. Transactions access data using read and write operations.
In order to maintain consistency in a database, before and after the transaction, certain properties are followed. These are called ACID properties.

Atomicity:

. It involves the following two operations.
Abort: If a transaction aborts, changes made to database are not visible.
Commit: If a transaction commits, changes made are visible.
Atomicity is also known as the ‘All or nothing rule’.


Consistency:

This means that integrity constraints must be maintained so that the database is consistent before and after the transaction.

The total amount before and after the transaction must be maintained.
Total before T occurs = 500 + 200 = 700.
Total after T occurs = 400 + 300 = 700.
Therefore, database is consistent. Inconsistency occurs in case T1 completes but T2 fails. As a result T is incomplete.

Isolation

This property ensures that multiple transactions can occur concurrently without leading to the inconsistency of database state. Transactions occur independently without interference.

Durability:

This property ensures that once the transaction has completed execution, the updates and modifications to the database are stored in and written to disk and they persist even if a system failure occurs. These updates now become permanent and are stored in non-volatile memory. The effects of the transaction, thus, are never lost.



For more Details. Watch this video.





Thursday, September 3, 2020

Call by value and call by reference in C++


Call by value in C++

In call by value, original value is not modified.

In call by value, value being passed to the function is locally stored by the function parameter in stack memory location. If you change the value of function parameter, it is changed for the current function only. It will not change the value of variable inside the caller method such as main()


#include <iostream>  

using namespace std;  

void change(int data);  

int main()  

{  

int data = 3;  

change(data);  

cout << "Value of the data is: " << data<< endl;  

return 0;  

}  

void change(int data)  

{  

data = 5;  

}  

Output:

Value of the data is: 3

Call by reference in C++

In call by reference, original value is modified because we pass reference (address).

#include<iostream>  

using namespace std;    

void swap(int *x, int *y)  

{  

 int swap;  

 swap=*x;  

 *x=*y;  

 *y=swap;  

}  

int main()   

{    

 int x=500, y=100;    

 swap(&x, &y);  // passing value to function  

 cout<<"Value of x is: "<<x<<endl;  

 cout<<"Value of y is: "<<y<<endl;  

 return 0;  

}    

Output:


Value of x is: 100

Value of y is: 500 


                                    Watch this video for better understanding:






Tuesday, September 1, 2020

React Installation Using the create-react-app command

 

Using the create-react-app command

If you do not want to install react by using webpack and babel, then you can choose create-react-app to install react. The 'create-react-app' is a tool maintained by Facebook itself. This is suitable for beginners without manually having to deal with transpiling tools like webpack and babel. In this section, I will be showing you how to install React using CRA tool.

Install NodeJS and NPM

NodeJS and NPM are the platforms need to develop any ReactJS application. You can install NodeJS and NPM package manager by the link given below.


Install React

You can install React using npm package manager by using the below command. There is no need to worry about the complexity of React installation. The create-react-app npm package will take care of it.

npm install -g create-react-app  


Create a new React project

After the installation of React, you can create a new react project using create-react-app command. Here, I choose jtp-reactapp name for my project

create-react-app jtp-reactapp  


Running the Server

After completing the installation process, you can start the server by running the following command.

  1. cd jtp-reactapp  
  2. npm start