Java Notes
Java Notes
Java Notes
important point:
1. Any value written inside the double code will be strictly treated as String
2. // In arrays we can store multiple values in a single variable
Int [] xyz à By defining in this form we can know that thevariable is not storing
only integer value but it storing multiple integer values. New will create a
memory for those many values we are going to save
package Package1;
/*System.out.println("Java training");
System.out.println("Hello");
System.out.print("testing");
System.out.println("Happy Weekend");
System.out.println("Bye");
System.out.println("out sidemain training"); */
// SYSO ctrl+spacebar
/*double x = 10;
System.out.println(x); */
/*char x = '8';
System.out.println(x); */
/*boolean x = true;
System.out.println(x);*/
/*int a,b;
a =10;
b=35;
double c = a+b;
System.out.println("This is total"+" "+c); // concatination
//This is total : 45.0*/
//Non-Primitive Datatypes
//String
//Arrays
//Classes
//Interfaces
System.out.println(Automation.contains("Java")); */
/*int x,y;
x=100;
y=100;
System.out.println(x==y); //False
System.out.println(x!=y); //true
System.out.println(x<y); //true
System.out.println(x>y); //false
System.out.println(x>=y); //false
System.out.println(x<=y); //true */
/*String expectedvalue="automation";
String actualvalue="automation123";
if (expectedvalue.equals(actualvalue))
{
System.out.println("Pass");
}
else
{
System.out.println("fail");
}*/
//int[] x= {10,20,30,40,50};
/*String[] names=new String[5];
names[0]="Prathiba";
names[2]="Moosa";
System.out.println(names[2]);
names[3]="Teja";
names[4]="jaffar";
names[2]="Padma";
System.out.println(names[2]);*/
//System.out.println(name[7]);
}
day_3
ackage Package1;
//For looping
/*for(int i=1;i<=10;i++)
{
System.out.println(i);
}*/
//For Debug --> place a breakpoint and then when teh script stop at
//test line press F6
//This is script to print single word by word from a string
/*String text= "Automation testing session for Selenium";
System.out.println(text);
for (int i=0;i<text.length();i++)
{
//System.out.println(text.charAt(i));
System.out.print(text.charAt(i));
}*/
//Enhanced Forloop
/*String text= "Automation testing session for Selenium";
String [] Splitvalue = text.split(" ");
for(int i=0;i<Splitvalue.length;i++)
{
System.out.println(Splitvalue[i]);
}
else if(Names.equals("Moosa") )
{
System.out.println("calling Moosa");
}
else if(Names.equals("Jaffar"))
{
System.out.println("Calling Jaffar");
}
else if(Names.equals("Prathiba"))
{
System.out.println("Calling Prathiba");
}
else
{
System.out.println("Calling no one");
}
*/
//SWITCH
/* String Names = "Anees";
switch(Names) {
case "Shakeer":
System.out.println("Calling Shakeer");
break;
case "Moosa":
System.out.println("Calling Moosa");
break;
case "Jaffar":
System.out.println("Calling Jaffar");
break;
case "Prathiba":
System.out.println("Calling Prathiba");
break;
default:
System.out.println("Calling no one");
}*/
1234
567
89
10
}
DAY-4
package Package1;
//Logout Method
public void logout() {
System.out.println("Logout");
}
x.Login();
x.logout();
x.Login();
x.logout();
x.Login();
x.logout();
}
}
}
System.out.println("");
} */
/*int k=1;
for (int rows=1; rows<5; rows++)
{
for (int column=1; column<=rows;column++)
{
System.out.print(k);
k++;
System.out.print("\t");
}
System.out.println("");
} */
}
DAY_5
Methods/Functions:
Whenever we feel some set of lines of code can be reused multiple times, then we
will place that code in a Method and reuse it whenever it is required.
Methods can be called by Objects which are created with its class reference.
Exercise:
package Package1;
//Logout Method
public void logout() {
System.out.println("Logout");
}
x.Login("shakeer", "test@1234");
x.logout();
x.Login("Jaffar", "Password@123");
x.logout();
x.Login("Divya", "Pass@999");
x.logout();
x.Login("Padma", "Pass456@999");
x.logout();
x.Login("Moosa", "Testing");
x.logout();
--------------------------------
INTERFACE:
TROI INTERFACE:
package Package1;
IPHONE 14 CLASS:
package Package1;
@Override
public void Calling() {
System.out.println("Scroll up");
@Override
public void CallEnd() {
System.out.println("Scroll down");
}
@Override
public void CallDivert() {
System.out.println("Diverting");
@Override
public void Messages() {
System.out.println("Message");
@Override
public void Maps() {
System.out.println("Maps");
IPHONE15 CLass:
package Package1;
@Override
public void Calling() {
System.out.println("Scroll up");
@Override
public void CallEnd() {
System.out.println("Scroll down");
@Override
public void CallDivert() {
System.out.println("Diverting");
@Override
public void Messages() {
System.out.println("Message");
@Override
public void Maps() {
System.out.println("Maps");
IPHONE 16 CLASS
package Package1;
@Override
public void iWatch() {
System.out.println("New Iwatch App");
@Override
public void AppStore() {
System.out.println("New AppStore App");
@Override
public void iMusic() {
System.out.println("New iMusci App");
@Override
public void Calling() {
System.out.println("Calling");
@Override
public void CallEnd() {
System.out.println("CallEnd");
@Override
public void CallDivert() {
System.out.println("CallDivert");
@Override
public void Messages() {
System.out.println("Messages");
}
@Override
public void Maps() {
System.out.println("Maps");
SAMSUNG CLASS:
package Package1;
@Override
public void Calling() {
System.out.println("Scroll left");
@Override
public void CallEnd() {
System.out.println("Scroll Right");
@Override
public void CallDivert() {
System.out.println("Divert");
}
@Override
public void Messages() {
System.out.println("Messages");
@Override
public void Maps() {
System.out.println("Maps");
-----------------------------------------------------
ABSTRACT CLASS:
Abstract method:
The method which has no implementation is called the abstract method and it has the keyword called “abstract”.
NHAABSTRCTCLASS:
package Package1;
BelgiumSIgnalSystem :
package Package1;
@Override
public void GreenlightWaittime() {
System.out.println("Greenlight wait for 45 sec");
@Override
public void RedlightWaittime() {
System.out.println("Greenlight wait for 30 sec");
@Override
public void OrangelightWaittime() {
System.out.println("Greenlight wait for 5 sec");
}
}
CanadaSignalSyatem
package Package1;
@Override
public void GreenlightWaittime() {
System.out.println("Greenlight wait for 90Sec");
@Override
public void RedlightWaittime() {
System.out.println("Redlight wait for 75Sec");
@Override
public void OrangelightWaittime() {
System.out.println("Orangelight wait for 10Sec");
DAY_6
What is Inheritance?
package Package1;
import Package2.Parent3;
Parent2Class :
package Package1;
package Package2;
Child1Class :
package Package1;
import Package2.Parent3;
Child1Class child1=new
Child1Class();
child1.Bike();
child1.Freetime();
child1.Mobile();
child1.Student();
child1.Money();
//child1.SUperbike();
//child.Travel();
}
Child2Class:
package Package1;
Child2Class child2=new
Child2Class();
child2.Bike();
child2.Freetime();
child2.Mobile();
child2.Student();
child2.Money();
//child.Travel();
}
Child3 :
package Package1;
import Package2.Parent3;
---------------------
When do you use the super keyword?
Super is a Java keyword used to identify or refer
parent (base) class.
We can use super to access super class
methods
When method names are the same in
super class and sub class, to refer super
class, the super keyword is used.
Parent class method access can be done
using super, when child class has method
overridden
---------------------------------
StaticMethod :
package Package1;
-------------------------------
What is Polymorphism?
What is meant by
Overloading?
OverloadingClass :
package Package1;
object.getData(5,"Selenium");
object.getData("Selenium");
object.getData("test","Selenium")
;
object.getData(5);
}
DAY_8
ClassAccessModifier1:
package Package1;
void defaultmethod() {
System.out.println("I am defaultmethod");
}
System.out.println(obj.x);
System.out.println(obj.y);
System.out.println(obj.z);
System.out.println(obj.name);
obj.publicmethod();
obj.defaultmethod();
obj.privatemethod();
obj.protectedmethod();
ClassAccessModifier2:
package Package1;
System.out.println(obj1.x);
System.out.println(obj1.y);
//System.out.println(obj1.z);
System.out.println(obj1.name);
obj1.publicmethod();
obj1.defaultmethod();
//obj1.privatemethod();
obj1.protectedmethod();
ClassAccessModifier3 :
package Package2;
import Package1.ClassAccessModifier1;
ClassAccessModifier4 :
package Package2;
import Package1.ClassAccessModifier1;
=======================================
DEBUG:
Step Into
When a method is about to be called, and you want to debug into the code of that
method, the next step is to go into that method and continue debugging step-by-step.
Step Over
A method is about to be called, but you're not interested in debugging this particular
code inside the method, so you want the debugger to execute that method completely
as one entire step.
Step Return
You're done debugging this method step-by-step, and you just want the debugger to
run the entire method until it returns as one entire step.
Resume
Line Breakpoint
if you want the debugger to temporarily pause execution there so you can decide what
to do. Then place a breakpoint at that line
Exercise:
package Package1;
System.out.println("testing");
System.out.println("training");
System.out.println("java");
obj.method1();
System.out.println("selenium");
System.out.println("API");
obj.method2();
obj.method3();
System.out.println("Jenkins");
System.out.println("GITHUB");
}