The worm

This Article was very interesting and thought of sharing!!

" The Most complicated code ever written!! 

The most sophisticated software in history was written by a team of people, whose names we do not know.
It’s a computer worm. The worm was written, probably, between 2005 and 2010.
Because the worm is so complex and sophisticated, I can only give the most superficial outline of what it does.
This worm exists first on a USB drive. Someone could just find that USB drive lying around, or get it in the mail, and wonder what was on it. When that USB drive is inserted into a Windows PC, without the user knowing it, that worm will quietly run itself, and copy itself to that PC. It has at least three ways of trying to get itself to run. If one way doesn’t work, it tries another. At least two of these methods to launch itself were completely new then, and both of them used two independent, secret bugs in Windows that no one else knew about, until this worm came along.

Java/Rest/Spring

Theory Interview Question Java/J2EE

1. In Spring MVC how to handle exceptions?
  • Controller Based: We annotate our controller with @ExceptionHandlerThis takes exception class as argument.
  • Global Exception Handler: Here we use @ControllerAdvice annotation that we can use with any class to define our global exception handler.
  • HandlerExceptionResolver: Interface that we can implement to create global exception handler

2. What are the annotations would you use?
 @ControllerAdvice,@ExceptionHandler

3. For Global exception handler? What would you use?
@ControllerAdvice

4. For Controller Based?
@ExceptionHandler

5. Get and Load Method?

Find Intersection Between 2 Arrays

Find Intersection Between 2 Arrays

Example:1
Array-1 -- {1,2,3,10,20,5,8}
Array-1 --{20,1,90,30}

Output: 1,20

Example:2
Array-1 -- {10,20,10,10,50,80}
Array-1 --{10,10,10,10}

Output: 10

Steps & Complexity
Step:1 Sort any array[eg:Array-2]
Step:2 Take each element from an array:1, do a binary search for each element in array-1 with Array2
Step:3 If found- add into the set
Step:4 Else increment

Complexity : O(nlogn)

Interface In Java 8

Interface :

It is similar to a class in java, instead, with a keyword as interface. 
Interface used as method declaration, not for implementation untill jdk7

Eg:

1
 2
 3
 4
 5
 6
 7
 8
 9
10
Public interface MyInteface {
 Void m1(String str);
 Void m2(int i);

 // But you cannot write as follows in interface
 /*Void m3(String s){
 System.out.println("You cannot write this way. "); 
     }*/

}




Interface in Java-8 :

Java-8 interface can have STATIC DEFAULT methods, we can also have method implementation from jdk 8 but has to be default

Eg: Before JAVA-8 

1
2
3
4
5
6
7
Public interface MyInterface{
     Void m1(String str);
     /* Default void m2(String str){
          System.out.println(“Gives an error in prior jav-8 versions. ”);
    } //Gives you an error
  
  */
}



Code In Java-8

Java-8 Functional Interface

Java Functional Interface



If look into some other programming languages like c++, Javascript they are called functional programming languages bcoz, we can write functional and use whenever required.

An interface with only 1 abstract method is called Functional interface.
A new annotation @FunctionalInteface provides us to avoid accidental addition od abstract methods.
Functional interface is long waited and much sought out feature of Java-8 as it enables us to use Lambda expressions to instantiate them.

Being object-oriented is not bad, but when we wanted to implement Runnable we do it as follows

Eg: 


1
2
3
4
5
Runnable r = new Runnable(){
   @Override
   public void run() {
    System.out.println("My Runnable");
   }};

If you notice it, the important logic in under run() method right?

Java-8 lambda expressions allow to help us in writing smaller and cleaner code.


Lambda Expressions:

Lambda expression is way through we can visualize functional programming in java object world.
Objects are base of java prog. Lang. and we can never have a function without an Object


Syntax:  (argument) -> (body)


1
Runnable r1 = () -> System.out.println("My Runnable");


In the above code, Runnable is a functional interface so we can use Lambda.
Since run() has no arguments,  we have no arguments passed.

Advantages of Lambda expressions:
  1. Reduced lines of code.
  2. Pass method into behaviours
  3. High efficiency