Day 2 Complete
Day 2 Complete
Animal Human
jump()
Monkey stayOnTree()
bite() Kid
Monkey
jump()
Kid school()
...
Strings are immutable (once it created there state can not be change)
stack heap
How String stored in java?
String s3="lee"
method area
s3=s3+"foo"
"lee"
Bad prog practice
"leefoo"
String a="a+"b"+"c"+"d";
string pool
"a"
"ab"
"abc"
"abcd"
data2
"abcd"
method area
"abcd"
string pool
exception handing: Checked and uncheked ex? GPP(good programming practice)
Checked ex Compile time ex All Ex happend at run time?
exception
"robust"
code Compiler
System.out.println("PE 2 nos");
x=scanner.nextInt();
y=scanner.nextInt();
int z=x/y;
System.out.println("Z:"+z);
System.out.println("end");
}
catch(ArithmeticException e) {
System.out.println("dont do divide by zero");
}
catch(InputMismatchException e) {
System.out.println("input must be ints");
}
System.out.println("PE 2 nos");
x = scanner.nextInt();
y = scanner.nextInt();
int z = x / y;
System.out.println("Z:" + z);
System.out.println("end");
scanner.close();
} catch (ArithmeticException e) {
System.out.println("dont do divide by zero");
}
catch (InputMismatchException e) {
System.out.println("input must be ints");
}
User define exception: Need of user define ex?
throw vs throws bankapp
try
catch Account SA
throw
throws withdraw 1000 NotSufficientFundException
finally deposit OverFundEcxception
account creation process AccountCreationException
//NotSufficientFundException
class NotSufficientFundException extends Exception{
private static final long serialVersionUID = 1825616456008488982L;
//OverFundEcxception
class OverFundEcxception extends RuntimeException{
private static final long serialVersionUID = 1825616456008488982L;
class Account{
private int id;
private String name;
private double balance;
account.print();
} catch (AccountCreationException e) {
System.out.println(e.getMessage());
}catch(OverFundEcxception e) {
System.out.println(e.getMessage());
} catch (NotSufficientFundException e) {
System.out.println(e.getMessage());
}
System.out.println("code end");
BikeStore
BikeStoreApplication BikeStoreCreationExcption
stack heap 0 1 2 3 4
emps
method area
class Emp {
private int id;
private String name; Emp Student Account
com.session2.ob_class.Emp@50040f0c
if(e1.equals(e2)) {
System.out.println("both are same");
}else
System.out.println("not same");
public static void main(String[] args) {
List<Integer> list1=new ArrayList<>();
List<Integer> list2=new LinkedList<>(); 100000
doTiming(list1);
long end=System.currentTimeMillis();
System.out.println("time taken: "+(end-start)+" ms");
}