Professional Documents
Culture Documents
Diagram:
==========================================================
faq:
Method Signature:
public java.lang.String getMessage();
syntax:
faq:
Method Signature:
syntax:
obj.printStackTrace();
======================================================
*imp
Ex:
java.lang.InterruptedException
java.lang.ClassNotFoundException
java.io.IOException
...
faq:
Method Signature:
throws java.lang.InterruptedException;
syntax:
Thread.sleep(time);
Note:
Ex : DemoException4.java
package maccess;
for(int i=1;i<=10;i++) {
System.out.println("Value:"+i);
try {
Thread.sleep(5000);//method_call
}//end of loop
o/p:
Value:1
Value:2
Value:3
Value:4
Value:5
Value:6
Value:7
Value:8
Value:9
Value:10
=====================================================
Dt : 21/7/2022
*imp
Checked Exceptions.
=>we use the following steps to define and raise the Checked
Exceptions:
re-throwing process.
StudentDetails.java
package test;
public class StudentDetails {
public String rollNo,name,branch,result;
public int totMarks;
public float per;
public String toString() {
return rollNo+"\t"+name+"\t"+
branch+"\t"+totMarks+"\t"
+"\t"+per+"\t"+result;
}
}
CheckBranch.java
package test;
@SuppressWarnings("serial")
public class CheckBranch extends Exception
{
public CheckBranch() {}
public CheckBranch(String msg)
{
super(msg);
}
public void verify(String br) throws CheckBranch
{
try
{
switch(br) {
case "CSE":
break;
case "ECE":
break;
case "EEE":
break;
default: //raise the exception
CheckBranch cb =
new CheckBranch("Invalid branch...");
throw cb;
}//end of switch
}//end of try
catch(CheckBranch cb)
{
throw cb;//re-throwing process
}
}//end of method
}
GenerateBranch.java
package test;
public class GenerateBranch{
public String generate(String brCode) {
return switch(brCode) {
case "05":
yield "CSE";
case "04":
yield "ECE";
case "02":
yield "EEE";
default:
yield "null";
};
}
}
StudentResult.java
package test;
public class StudentResult {
public String generateResult(float per,boolean p)
{
if(p)
{
return "Fail";
}
else if(per>=70 && per<=100)
{
return "Destinction";
}
else if(per>=60 && per<70)
{
return "FirstClass";
}
else if(per>=50 && per<60)
{
return "SecondClass";
}
else if(per>=35 && per<50)
{
return "ThirdClass";
}
else
{
return "Fail";
}
}
}
DemoException5.java(MainClass)
package maccess;
import test.*;
import java.util.*;
@SuppressWarnings("serial")
super(msg);
try(s;)//Java
ArrayList<StudentDetails> al =
new ArrayList<StudentDetails>();
try
int n = Integer.parseInt(s.nextLine());
for(int i=1;i<=n;i++)
try
sd.rollNo=s.nextLine();
if(sd.rollNo.length()!=10)//Exception
("Invalid rollNo..");
throw de;
}//end of if
sd.name=s.nextLine();
sd.branch=s.nextLine().toUpperCase();
cb.verify(sd.branch);
String br =
gb.generate(sd.rollNo.substring(6,8));
if(br==null)
{
DemoException5 ob = new DemoException5
throw ob;
if(!br.equals(sd.branch))
throw ob;
int j=1,totM=0;
boolean p=false;
while(j<=6)
try
System.out.println("Marks of Sub-"+j);
if(sub<0 || sub>100)
("Invalid marks...");
throw ob;
}
p=true;
totM=totM+sub;
j++;
}//end of switch
catch(NumberFormatException nfe)
catch(DemoException5 ob)
System.out.println(ob.getMessage());
}//end of while
sd.totMarks=totM;
sd.per=(float)sd.totMarks/6;
sd.result =
new StudentResult().generateResult(sd.per,p);
}//end of try
System.out.println(ob.getMessage());
i--;
}//end of loop
System.out.println("====StudentDetails===");
al.forEach((k)->
System.out.println(k.toString());
});
}//end of try
catch(NumberFormatException ob)
}
===========================================================
faq:
Note:
declared.
faq:
define Exception propagation?
faq:
(i)throw
(ii)throws
==========================================================
faq:
define Annotation?
Annotation.
(i) @Override
(ii) @SuppressWarnings
(i) @Override:
(ii) @SuppressWarnings:
============================================================
Dt : 22/7/2022
faq:
define try-with-resource?
syntax:
try(resource1;resource2;...)
//statements
Ex:
//statements
}
==========================================================
faq:
syntax:
resource1;resource2;...
try(res1_var;res2_var;...)
//statements
Ex:
try(s;)
//statements
}
================================================
faq:
define java.lang.NullPointerException?
'NullPointerException'.
======================================================
*imp
MultiThreading process:
define application?
define process?
(According to JavaLang)
define Task?
define Mult-Tasking?
Multi-Tasking.
define Thread?
Note:
===================================================
*imp
interface:
name
ProjectName : Interface_App5
packages,
test : Display1,Display2
maccess : DemoInterface5(MainClass)
ProjectName : Anonymous_InnerClass_App4_Thread
packages,
maccess : DemoAnonymous4.java(MainClass)
ProjectName : App3_LambdaExpression_Thread
packages,
maccess : DemoLambdaExpression3.java(MainClass)
ProjectName : App_MethodReferences_Thread
packages,
test : Display1,Display2
maccess : DemoMethodReference2.java(MainClass)
============================================================
*imp