Java 8
Java 8
Video 1:
@FunctionalInterface
interface I
{
public abstract void m1();
acc.m1();
acc.m2();
acc.m3();
I.m5();
I.m4();
}
}
Video 2:
annonymous class is a class which present inside the another class without having
any identity or a name. is called annonymous inner class
package com;
interface Test
{
public abstract void m1();
}
a.m1();
}
}
Video No. 3
Video No. 4
package com;
interface i
{
public abstract void m1();
class A implements i
{
@Override
public void m1() {
System.out.println("we are A-m1");
}
}
class B implements i
{
@Override
public void m1()
{
System.out.println("we are B-m2");
}
}
i g = new i() {
@Override
public void m1()
{
System.out.println(" we are annonymouns inner class");
}
};
g.m2();
e.m2();
f.m2();
g.m1();
e.m1();
f.m1();
}
}
Video No. 5
Video No. 6
package com;
interface A
{
public default void call()
{
System.out.println("we are A default class");
}
}
interface B
{
public default void call()
{
System.out.println("we are A default class");
}
}
@Override
public void call() {
A.super.call();
B.super.call();
System.out.println("we are Onee.");
}
}
s.call();
}
Video No. 7
Interface
Abstract class
1. Variables are public static final
1. Variables are private public, static, final, protected
2. We can't write the constructors 2. We
can write the constructors
3. Interface doesn't talk about the state of the object
3. Abstract talks about the state of the object
4. We can't write blocks/initializers[instance/static]
4. abstract class can allows both static and instance initializers/blocks.
5. It can allows abstract methods but not the allows the
5. it can allows both concrete and abstract method
concerte methods
6. We can logic in interface by using default method
6. We can't write default methods in interface
7. It will supports multiple inheritance 7. It
will not support multiple inheritance.
8. We can't write object class method in interface
8. We can write the object class method in abstract class.
Final Variables:
Variables declared in a Java interface are by default final. An abstract class may
contain non-final variables.
Type of variables:
Abstract class can have final, non-final, static and non-static variables. The
interface has only static and final variables.
Implementation: ************
Abstract class can provide the implementation of the interface. Interface can’t
provide the implementation of an abstract class.
Inheritance vs Abstraction:
A Java interface can be implemented using the keyword “implements” and an abstract
class can be extended using the keyword “extends”.
Multiple implementations:
An interface can extend another Java interface only, an abstract class can extend
another Java class and implement multiple Java interfaces.
Video No. 8
/*
No need to take the suppoort of class for static method to execute the logic, we
can do it in interface, abstract class, enum also.
//Static method in interface.
*/
/*if you want to execute any logic without any implementation or annonymous class
that should must be write in the
static method.*//*
package com;
interface i2
{
public default void m2()
{
System.out.println("we are m2 of the default i2 interface");
}
public void m1();
public static void m3()
{
System.out.println("we are a static method");
}
}
class O implements i2
{
@Override
public void m1() {
System.out.println("we re O implemtned class");
}
}
i2 a = new i2() {
@Override
public void m1() {
m2();
}
} ;
a.m2();
a.m1();
i2.m3();
O e = new O();
e.m2();
}
}
*/
interface i
{
public static void main(String[] args) {
System.out.println("we are ok");
}
}
interface i
{
public static void main(String[] args) {
System.out.println("we are ok");
}
}
abstract class i
{
public static void main(String[] args) {
System.out.println("we are ok");
}
}
enum i
{
public static void main(String[] args) {
System.out.println("we are ok");
}
}
class i
{
public static void main(String[] args) {
System.out.println("we are ok");
}
}
Video NO. 9
package com;
interface j
{
public abstract void m4();
public abstract String toString();// method of java.lang.object
public abstract int hashCode();// method of java.lang.object
}
@Override
public String toString() {
return "we are toString";
}
@Override
public int hashCode() {
return 21468;
}
}
Video No. 10
Q. How many ways can we able to provide implementation for interface from JDK 1.8
package com;
interface Ie
{
public abstract void learn();
}
Ie a = () -> {
};
a.learn();
}
}
Video No. 12
package com;
interface a1
{
public abstract void r1();
}
interface b1 extends a1
{
}
}
}
}
Video No. 13
why: providing implementation for only Functional Interface writing less and
perform more operations suitable for Collections Frameworks objects.
syntax:
(datatypes parameter, datatypes parameter) --> {statement};
Video No. 15
package com;
interface A1 <T>
{
public abstract T m2( T x);
}
com.m2(121);
Video No. 20
package com;
interface A1 <T>
{
public abstract T m2( T x);
}
com.m2(121);
package com;
interface i
{
public abstract void a();
}
class ax
{
public void c()
{
System.out.println(" we are c");
}
}
o.a();