Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 3

Lecture 03-Dec-2020 Thursday

Topics To Cover:
Core Java:
1. Concept of Lambda Operator - Java 8 onwards.
Swing/Project:
2. Improving StudentFrame.java code. So that, it will show information of the
Candidate who have logged in.
3. Introduction to HTML.
4. Error Solution - By Screen Sharing.
5. Recap of Tuesday
-----------------------------------------------------------------------------------
------------------------
Core Java:
1. Concept of Lambda Operator - Java 8 onwards.
Definition: It is shortcut way of defining functions in mathematical manner, which
takes one or more parameters and returns some value.

Earlier we write [Without Lambda]


int operation(int a, int b){ return a+b; }

Now, we write [Using Lambda ] as


(a,b) -> a+b

OCJP1. Operator -> is known as __(a)____ in Java and __(b)_____ in C++?


Ans: (a) Lambda (b) Pointer Indirection

Example Program I: Performing Arithmetic Operations using old approach [Without


Lambda]
interface Arithmetic{
public abstract int operation(int a, int b); //abstract method - declaration
only
}
class Addition implements Arithmetic{
@Override
public int operation(int a, int b){ return a+b; }
}
class Subtraction implements Arithmetic{
@Override
public int operation(int a, int b){ return a-b; }
}
//Similarly we can code Multiplication and Division Class. Drawback: Lot of Code
public class WithoutLambda{
public static void main(String args[ ]){
//Creating instance of classes
Addition obj1=new Addition();
Subtraction obj2=new Subtraction();
//Message Passing
System.out.println("Addition=" + obj1.operation(9,4)); //Output 13
System.out.println("Subtraction=" + obj2.operation(9,4)); //Output 5
} //main
} //class

Example Program II: Same program but using Lambda Operator


//Step I: Define a Functional Interface [OCJP2] - means contains only single fn
interface Arithmetic{
public abstract int operation(int a, int b); //abstract method - declaration
only
}
//Step II: Create public class and main fn (no need to implement interface)
public class WithLambda{
public static void main(String args[ ]){
//Step III: Define lambda operation to perform by using interface variables
Arithmetic obj1=(a,b)->a+b;
Arithmetic obj2=(int a, int b)->a-b; //OCJP3. datatype is optional
//python lambda(a,b):a+b
//Step IV: Perform Message Passing
System.out.println("Addition=" + obj1.operation(9,4)); //Output 13
System.out.println("Subtraction=" + obj2.operation(9,4)); //Output 5
} //main
} //class

Swing/Project:
2. Improving StudentFrame.java code. So that, it will show information of the
Candidate who have logged in.

Step I: StudentFrame=>Goto initialize() fn and just add if condition to decide


whether all rows should appear (Admin)
Or only single row appear (candidate) Login
private void initialize() throws Exception //OCJP2
{
String sql = "";
//Check for the usertype - 03-Dec-2020
if (usertype.equals("A")) {
sql = String.format("Select * from Student"); //Select all rows
} else {
sql = String.format("Select * from Student where enrollment='%s' ",
userid);
}
rs1 = DatabaseBean.executeQuery(sql); //Code Reusability [Static Fn]
if (rs1.last()) //Means row found
{
rsToText(rs1);
} else {
emptyText();
}
}

Step II: In Oracle/MySQL Database now we have to keep enrollment as userid for
usertype='C' (Candidate)
SQL> insert into users values('0101CS181001' ,'ajay','C','Favorite Dish','dosa');
SQL> insert into users values('0101CS181002' ,'vijay','C','Favorite Dish','dosa');
SQL> insert into users values('0101CS181003' ,'sanjay','C','Favorite Dish','dosa');
SQL>commit;

Step III: Now, Run Login Two times, one with admin user and then with candidate
user.

-----------------------------------------------------------------------------------
-----------------------
Introduction to HTML:
=>Stands for "Hyper Text Markup Language", used to design web pages that can be
accessed from any platform such as Windows, Mac, Linux, etc, just we need a web
browser such as Firefor, Chrome, Edge, Opera, etc.

=>It consist of set of <tags> to format the document, like


<b>Bold Text</b> <i>Italic Text</i>
<tag> => Start of a tag
</tag> => End of a tag [Forward slash]
-----------------------------------------------------------------------------------
------------------------
A Simple Html Page by using Notepad - Hello World
-----------------------------------------------------------------------------------
-------------------------
Step I: Type below code using Notepad
<html>
<head>Hello World</head>
<body>Html is Fun</body>
</html>

Step II: File=>Save As=>d:\helloworld.html


Save As Type=>All Files
Step III: Open any browser like firefox/chrome and type in address bar
file:///d:/helloworld.html [Interview Question]
OR
Open My Computer=>d:\ => Double Click on helloworld.html

You might also like