This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Employee{ | |
int id; | |
String name; | |
Address address; // <- aggregation here (Address is a class) | |
// ... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@FunctionalInterface | |
public interface MyFirstFunctionalInterface { | |
public void firstWork(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Java program to demonstrate lambda expressions | |
// to implement a user defined functional interface. | |
// A sample functional interface (An interface with single abstract method) | |
interface FuncInterface | |
{ | |
// An abstract function | |
void abstractFun(int x); | |
// A non-abstract (or default) function (Java 8 feature) | |
default void normalFun() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Moveable interface defines a method move() | |
// and provided a default implementation as well. | |
// If any class implements this interface then it | |
// need not to implement it’s own version of move() method. | |
// It can directly call instance.move(). e.g. | |
public interface Moveable { | |
default void move(){ | |
System.out.println("I am moving"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// List Interface | |
// We can store the ordered collection of objects. It can have duplicate values. | |
List <data-type> list1= new ArrayList(); | |
List <data-type> list2 = new LinkedList(); | |
List <data-type> list3 = new Vector(); | |
List <data-type> list4 = new Stack(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ArrayList | |
import java.util.*; | |
class TestJavaCollection1{ | |
public static void main(String args[]){ | |
ArrayList<String> list=new ArrayList<String>();//Creating arraylist | |
list.add("Ravi");//Adding object in arraylist | |
list.add("Vijay"); | |
list.add("Ravi"); | |
list.add("Ajay"); | |
// Traversing list through Iterator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//LinkedList | |
import java.util.*; | |
public class TestJavaCollection2{ | |
public static void main(String args[]){ | |
LinkedList<String> al=new LinkedList<String>(); | |
al.add("Ravi"); | |
al.add("Vijay"); | |
al.add("Ravi"); | |
al.add("Ajay"); | |
Iterator<String> itr=al.iterator(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Stack | |
import java.util.*; | |
public class TestJavaCollection4{ | |
public static void main(String args[]){ | |
Stack<String> stack = new Stack<String>(); | |
stack.push("Ayush"); | |
stack.push("Garvit"); | |
stack.push("Amit"); | |
stack.push("Ashish"); | |
stack.push("Garima"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// PriorityQueue | |
import java.util.*; | |
public class TestJavaCollection5{ | |
public static void main(String args[]){ | |
PriorityQueue<String> queue=new PriorityQueue<String>(); | |
queue.add("Amit Sharma"); | |
queue.add("Vijay Raj"); | |
queue.add("JaiShankar"); | |
queue.add("Raj"); | |
System.out.println("head:"+queue.element()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Array Deque | |
import java.util.*; | |
public class TestJavaCollection6{ | |
public static void main(String[] args) { | |
//Creating Deque and adding elements | |
Deque<String> deque = new ArrayDeque<String>(); | |
deque.add("Gautam"); | |
deque.add("Karan"); | |
deque.add("Ajay"); | |
//Traversing elements |