Saturday, 5 March 2016

Lambda Expressions



Lambda Expression:

Java 8 introduced many features in its new version, amongst them stands lambda expressions. The way of writing the methods have been changed. Especially for loop is more generalized.

Advantages of lambda:

1.      They add new syntax elements.
2.      Parallel processing can be done (more detail in the parallelism section).
3.      It supports pipeline operations on data.
4.      Appending default functionality to the method that is defined in interface, default functionality executes on the reference of the interface method, surprisingly the method is not executed.

Implementation:

    Implementation of java includes two constructors:

1.      Lambda expression
2.      Functional interface.

Key points to remember:

1.      Lambda expression is anonymous method.
2.      This method don’t execute o its own, rather used to execute a function or method that is defined in the functional interface.
3.      They are called as ‘closures’.
4.      Lambda expression is redefined in the form of anonymous classes.
5.      We can only use lambda expression if and only if target type is known or specified.

Functional interface (Single Abstract Method Type):

1.      By name it’s an interface that contains only one method, which is abstract.
2.      It defines the target type of the lambda expression.

Lambda expression:

1.      A new operator is introduced, operator is called as ‘lambda operator’ or ‘arrow operator’. It is represented by ‘->’. This sign is verbally called as ‘goes to’ or ‘becomes’.
2.      The left side of the LE is used to specify parameters and the right side is for lambda body.
3.      Lambda body is of two types:
1.      Consisting single expression.
2.      Consisting a block.



marker interfaces

                                                            Marker Interfaces in Java


"An interface is called a marker interface when it is provided as a handle by Java interpreter to mark a class so that it can provide special behaviour to it at 
runtime and they do not have any method declarations". 

In the above definition "and they do not have any method declarations" is added because, till now all the marker interfaces provided by Java do not have method 
declarations. 

We cannot create marker interfaces, as you cannot instruct JVM to add special behaviour to all classes implementing (directly) that special interface. 



We don't need to create your own marker interface since it is not recommended by java. For your knowledge I want to make you clear that their 
is no any definition for marker interface in Java specification/api. Whatever we study on web/books is cooked by web developers. 

Now since jdk 1.5 we dont need to use marker interface, in place of this we can use annotations which have their own many advantages.

Sunday, 24 January 2016

simple login web service

package dat;

import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;

@Path("/login")
public class LoginService {

@POST
    @Path("/add")
@Produces("application/json")
    public Response getDate(
            @FormParam("email") String email,
            @FormParam("pwd") String pwd  )
             {
 
       String actualdetails = email + " " + pwd ;
 
       return Response.status(200)
        .entity("your details : " + actualdetails)
        .build();
    }
}


===============================

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="first/login/add" method="post">  
Enter Email:<input type="text" name="email"/><br/><br/>  
Enter Password:<input type="text" name="pwd"/><br/><br/>  
  
<input type="submit" value="Login"/>  
</form>  
</body>
</html>

Friday, 22 January 2016

Collections -- ArrayList

public class ArrayLists {

    public static void main(String[] args) {
        ArrayList<String> als = new ArrayList<String>();
       
       
        als.add("Name1");
        als.add("Name2");
        als.add("Name3");
        als.add("Name4");
        als.add("Name5");
        als.add("Name5");
       
        Iterator itr = als.iterator();
        while(itr == itr.next())
        {
            System.out.println(itr.next());
        }
       
        }
       
       

    }


in place of iterator we can use for loop also.... it is up to you how you use the traditional for loop or new for loop syntax.

for example:

public class ArrayLists {

    public static void main(String[] args) {
        ArrayList<String> als = new ArrayList<String>();
       
       
        als.add("Name1");
        als.add("Name2");
        als.add("Name3");
        als.add("Name4");
        als.add("Name5");
        als.add("Name5");
       
       for(String alsObject : ls)
        {
         System.out.println(alsObject);
         }
        }
       
       

    }

here the array list is the in memory data structure.
it can contain duplicate values.
its an dynamic array(same as arrays concept).
the add() method adds the values to the array list, later they can be retrieved by using iterator.
random access of the values or the objects is possible.
it is slow compared to other collection data structures
note: Collection framework is a generic one.......

Wednesday, 6 January 2016

JavaForYouGuys

Hi this JavaForYouGuys!!!!

Lets not go the history of java, from where it came, who was the author and all. we discuss about java in market, How new technologies are using java and stuff.

Present the era is for BigData. And Hadoop is the solution for it. Do you know on which platform it is made. its JAVA. the MapReduce algorithms are of java made. What not with java. there is a huge demand of java. lets have a great time working with Java. We talk about JavaEE and Core Java.But to say its entirely java thing.

Before Starting we should have main to important things:
1. Laptop/Desktop with internet.(though its silly to mention)
2. Eclipse or NetBeans IDE to work around with Java (See it also have JavaEE support)