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 .
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.
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 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.
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.
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.
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.
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.
A 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.
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).
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.