Learning Java!

 Todays im going to learn 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.

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


There are mainly three reasons to use interface. They are given below.

  • It is used to achieve abstraction.
  • By interface, we can support the functionality of multiple inheritance.
  • It can be used to achieve loose coupling.

Collections in Java

https://www.javatpoint.com/collections-in-java

Java Collections can achieve all the operations that you perform on a data such as searching, sorting, insertion, manipulation, and deletion.

Java Collection means a single unit of objects. Java Collection framework provides many interfaces (Set, List, Queue, Deque) and classes (ArrayList, Vector, LinkedListPriorityQueue, HashSet, LinkedHashSet, TreeSet).


List Interface

List interface is the child interface of Collection interface. It inhibits a list type data structure in which we can store the ordered collection of objects. It can have duplicate values.

List interface is implemented by the classes ArrayList, LinkedList, Vector, and Stack.

To instantiate the List interface, we must use :

  1. List <data-type> list1= new ArrayList();  
  2. List <data-type> list2 = new LinkedList();  
  3. List <data-type> list3 = new Vector();  
  4. List <data-type> list4 = new Stack();  

There are various methods in List interface that can be used to insert, delete, and access the elements from the list.

The classes that implement the List interface are given below.


My java Versions:

C:\Users\Venkatesh>java -version

java version "13.0.1" 2019-10-15

Java(TM) SE Runtime Environment (build 13.0.1+9)

Java HotSpot(TM) 64-Bit Server VM (build 13.0.1+9, mixed mode, sharing)


HOW TO TAKE INPUT FROM USER IN JAVA:

Scanner sc = new Scanner(System.in)

int a = sc.nextInt();


CODE:

  1. import java.util.*;  
  2. class UserInputDemo   
  3. {  
  4. public static void main(String[] args)  
  5. {  
  6. Scanner sc= new Scanner(System.in);    //System.in is a standard input stream  
  7. System.out.print("Enter first number- ");  
  8. int a= sc.nextInt();  
  9. System.out.print("Enter second number- ");  
  10. int b= sc.nextInt();  
  11. System.out.print("Enter third number- ");  
  12. int c= sc.nextInt();  
  13. int d=a+b+c;  
  14. System.out.println("Total= " +d);  
  15. }  

Java Infinitive For Loop

If you use two semicolons ;; in the for loop, it will be infinitive for loop.

Syntax:

  1. for(;;){  
  2. //code to be executed  
  3. }

What is the difference between Overloading and Overriding?

  • Overloading is about same function have different signatures. Overriding is about same function, same signature but different classes connected through inheritance.
    OverridingVsOverloading
  • Overloading is an example of compiler time polymorphism and overriding is an example of run time polymorphism.
Character input():
next().charAt(0)

Comments