Java Unit 3 Notes New Fetures Part 2 Sakshiji
Java Unit 3 Notes New Fetures Part 2 Sakshiji
import java.util.*;
/*
interface Test
System.out.println("inside main");
{
UnitThree obj = new UnitThree();
obj.first();
obj.MyDefaultMethod();
Test.myStaticMethod();
//obj.myStaticMethod();
*/
/*
//@FunctionalInterface
interface Message
@Override
};
m1.msgA();
//m2.msgA();
m3.Sum(2,3);
*/
*/
/*
* The mapping of Function Interface method to the specified method by using “::” (double colon)
should have same argument types, except this the remaining things like return type,
*/
/*
interface Sayable{
void say();
System.out.println("Thread is running...");
sayable.say();
t2.start();
} */
/*
import java.util.function.BiFunction;
class Arithmetic{
return a+b;
System.out.println(result);
*/
/*
*/
/*
import java.util.stream.Collectors;
li.add(10);
li.add(20);
li.add(30);
li.add(40);
List<Integer> ll =li.stream().map((x)->x*x).collect(Collectors.toList());
*/
/*
* sList.add("Archana"); sList.add("Ananya");
*
*}}
*/
/*
* finally block for just passing the closing statements of the resources.
*/
/*
import java.io.FileOutputStream;
// Using try-with-resources
fileOutputStream.write(byteArray);
System.out.println("You are doing good its done writing the file !");
catch(Exception exception){
System.out.println(exception);
} */
* Java 8 has included two new features repeating and type annotations
* in its prior annotations topic. In early Java versions,
@NonNull List<String>
*/
/*
import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@Repeatable(Games.class)
@interfaceGame{
String name();
String day();
@interfaceGames{
Game[] value();
//Repeating annotation
System.out.println(game2.name()+" on "+game2.day());
*/
/*
* normal classes.
* /
*/
/*
};
} */
/*
import java.util.ArrayList;
class UnitThree {
*/
/* use of yield
*/
/*
public class UnitThree
int number=2;
case 2 -> {
default -> {
};
*/
//text blocks
/*
{
public static void main(String a[])
"Sector-136, Noida,\n" +
Sector-136, Noida,
*/
/*
* record
*/
/*
// toString()
System.out.println(empRecord1);
// accessing fields
System.out.println("Name: "+empRecord1.name());
System.out.println("ID: "+empRecord1.id());
// equals()
System.out.println(empRecord1.equals(empRecord2));
// hashCode()
System.out.println(empRecord1 == empRecord2);
}*/
/*
* that can
*/
import java.lang.*;
System.out.println("Default");
}
System.out.println("Manish Sharma");
System.out.println("Vartika Dadheech");
System.out.println("Anjali Sharma");
}
public class UnitThree
h1.printName();
h2.printName();
h3.printName();
package AbhishekJava;
// Java Program to Illustrate Record's
functionalities
//Java Program Illustrating a Record class
//defining constructors, instance methods
//and static fields
//Record class
record Employee(int id, String firstName,
String lastName)
{
// Instance methods
public void getFullName()
{
if (lastName == null)
System.out.println(firstName());
else
System.out.println(firstName() + " "
+ lastName());
}
// Static methods
public static int generateEmployeeToken()
{
return ++empToken;
}
}
// Main class
public class MyEmp {