Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Java Notes

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

Day-2

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;

public class MyfirstProgram {

public static void main(String[] args) {

/*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

//Primitive Data Types


//int(
//char
//double
//boolean

/* int x = 10; // Datatype Variablename = value


System.out.println("ANe123es");
System.out.println(x); */

/*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

/*String Firstname = "Anees";


String Lastname="Sk";
System.out.println(Firstname+" "+ Lastname);*/

/*String Automation = "Welcome to Automation session for Java";


System.out.println(Automation);
System.out.println(Automation.toUpperCase());
System.out.println(Automation.toLowerCase());
System.out.println(Automation.length());
System.out.println(Automation.indexOf("session"));

System.out.println(Automation.contains("Java")); */

//Arthematic Operators or comparision operators


// + - = < > <= >= !=

/*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]);*/

//String[] name= {"Jaffar","Divya","Padma","Prathiba","Moosa","Shakeer"};

//System.out.println(name[7]);

//String text = "Automation testing for java session";


/*String[] xyz=text.split(" ");
System.out.println(xyz[3]);*/

/*[] xyz = text.split("for");


System.out.println(xyz[0].trim());
System.out.println(xyz[1].trim());*/

/*String name =" Anees Sk ";


System.out.println(name);
System.out.println(name.trim());*/

//String Registrationmessage = "completed susscsfully Reg12345";

}
day_3
ackage Package1;

public class ForLoop {

public static void main(String[] args) {

//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]);
}

for(String val : Splitvalue )


{
System.out.println(val);
}*/

//This is script to print single word by word from a string in Reverse


/*String text= "Automation testing session for java";
System.out.println(text.length());
for ( int i=text.length()-1;i>=0;i--)
{
System.out.print(text.charAt(i));
}*/

/* int[] numbers = {1,2,3,4,5,6,7,8,9,0,1,3,3,34,54,754,56,78,5,8554,53,4,346,52,5};


for ( int a:numbers) {
System.out.println(a);
if(a==54) {
System.out.println("I did got 54");
break;
}
else
{
System.out.println("I did not get 54");
}
} */

//If elseif condition;

/* String Names = "Prathiba";


*
if (Names.equals("Shakeer")) {
System.out.println("Calling Shakeer");
}

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;

public class MethodORFunction {

// How to create a Method / Function


//Login Method
public void Login() {
System.out.println("Login as UN");
System.out.println("Login as pwd");
System.out.println("Login as Sign in");
}

//Logout Method
public void logout() {
System.out.println("Logout");
}

public static void main(String[] args) {

//Methods in the class can be access by creation object of that class


//how to create object
MethodORFunction x = new MethodORFunction();
ForLoop y = new ForLoop();
y.getData();

x.Login();
x.logout();

x.Login();
x.logout();

x.Login();
x.logout();

}
}

NESTED FOR LOOP


public class NestedForLoop {

public static void main(String[] args) {


//Nested Forloop

//1 2 3 4 - 1 row ; 4 colums


//5 6 7 - 2 row ; 3 colums
//8 9 - 3 Row ; 2 colums
//10 - 4 Row ; 1 colums

// totally 3 Rows and 4 Columns with -1 for each iteration.


//So outer loop should 4 times and inner loop should run for 4 times but each time -1
/*int k=1;
for(int i=0;i<4;i++)
{
for (int j=1;j<=4-i;j++)
{
System.out.print(k);
k++;
System.out.print("\t");

}
System.out.println("");
} */

//Outer loop = Rows


//inner loops = COlumns

//1 - 1 row ; 1 colums


//2 3 - 2 row ; 2 colums
//4 5 6 - 3 Row ; 3 colums
//7 8 9 10 - 4 Row ; 4 colums

/*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("");
} */

//1 - 1 row ; 1 columns


//1 2 - 2 row ; 2 columns
//1 2 3 - 3 row ; 3 columns
//1 2 3 4 - 4 row ; 4 columns

}
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.

Method should be created only outside a Main lock.

Methods can be called by Objects which are created with its class reference.

class A has 2 method


if i need to use Class A methods in Class B, then I need to create an object with
Class A reference in Class B

Method can be a normal method or method with parameters.

Exercise:

package Package1;

public class MethodORFunction {

// How to create a Method / Function


//Login Method
public void Login(String Username, String Password)
{
System.out.println("Login with username " + Username);
System.out.println("Login with Password " + Password);
System.out.println("Login as Sign in");
}

//Logout Method
public void logout() {
System.out.println("Logout");
}

public static void main(String[] args) {

//Methods in the class can be access by creation object of that class


//how to create object
MethodORFunction x = new MethodORFunction();
ForLoop y = new ForLoop();
y.getData();

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:

Interface will have only unimplemented Methods(Abstract Methods) it is nothing but


Method without body, whereas class will have only Implemented methods.

TROI INTERFACE:

package Package1;

public interface TROIInterface {

public void Calling();


public void CallEnd();
public void CallDivert();
public void Messages();
public void Maps();

IPHONE 14 CLASS:
package Package1;

public class iPhone14 implements TROIInterface{

public static void main(String[] args) {


iPhone14 IP14 = new iPhone14();
IP14.AppStore();
IP14.CallDivert();
IP14.CallEnd();
IP14.Calling();
IP14.iFrontcam();
IP14.iMusic();
IP14.iWatch();
IP14.Maps();
IP14.Messages();
IP14.RareCam();

public void iWatch() {


System.out.println("iWatch");
}

public void AppStore() {


System.out.println("Appstore");
}

public void iMusic() {


System.out.println("iMusic");
}

public void iFrontcam() {


System.out.println("32MP");
}

public void RareCam() {


System.out.println("64MP");
}

@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;

public class iPhone15 implements TROIInterface{

public static void main(String[] args) {


iPhone15 IP15 = new iPhone15();
IP15.AppStore();
IP15.CallDivert();
IP15.CallEnd();
IP15.Calling();
IP15.iFrontcam();
IP15.iMusic();
IP15.iWatch();
IP15.Maps();
IP15.Messages();
IP15.RareCam();

public void iWatch() {


System.out.println("iWatch");
}

public void AppStore() {


System.out.println("Appstore");
}

public void iMusic() {


System.out.println("iMusic");
}

public void iFrontcam() {


System.out.println("48MP");
}

public void RareCam() {


System.out.println("72MP");
}

@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;

public class iPhone16 implements TROIInterface , iPhoneInterface{

public static void main(String[] args) {


iPhone16 IP16 = new iPhone16();
IP16.AppStore();

@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;

public class SamsungA71 implements TROIInterface {

public static void main(String[] args) {


// TODO Auto-generated method stub

public void Playstore() {


System.out.println("playstore");
}

public void Samsungstore() {


System.out.println("Samsungstore");
}

public void SamsungMackup() {


System.out.println("SamsungMackup");
}

@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:

What is meant by Abstract class?


We can create the Abstract class by using the “Abstract” keyword before the class name. An abstract class can have both “Abstract” methods
and “Non-abstract” methods that are a concrete class.

Abstract method:
The method which has no implementation is called the abstract method and it has the keyword called “abstract”.

 An abstract class may have a non- abstract method also.


 The concrete Subclass which extends the Abstract class should provide the implementation for abstract methods.

NHAABSTRCTCLASS:

package Package1;

public abstract class NHAAbstractClass {

public void Greenlight() {


System.out.println("GO");
}

public void Orangelight() {


System.out.println("Slow down");
}

public void Redlight() {


System.out.println("STOP");
}

public abstract void GreenlightWaittime();


public abstract void RedlightWaittime();
public abstract void OrangelightWaittime();

//Abstract class will have both implemented and unimplemented methods


//Unimplemented methods are also called as Abstract Method
//Interface will have 100% Abstract Methods
//When a Normal class becomes Abstract Class - When there is alteast one Abstract
method
//then that class will become Abstract Class

BelgiumSIgnalSystem :

package Package1;

public class BelgiumSIgnalSystem extends NHAAbstractClass{

public static void main(String[] args) {

BelgiumSIgnalSystem Belgium = new BelgiumSIgnalSystem();


Belgium.Greenlight();
Belgium.GreenlightWaittime();
Belgium.Redlight();
Belgium.RedlightWaittime();
Belgium.Orangelight();
Belgium.OrangelightWaittime();
}

@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;

public class CanadaSignalSyatem extends NHAAbstractClass{

public static void main(String[] args) {

CanadaSignalSyatem Canada = new CanadaSignalSyatem();


Canada.Greenlight();
Canada.GreenlightWaittime();
Canada.Orangelight();
Canada.OrangelightWaittime();
Canada.Redlight();
Canada.RedlightWaittime();
}

@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?

Inheritance means one class can extend to another


class. So that the codes can be reused from one
class to another class. The existing class is known as
the Super class whereas the derived class is known
as a sub class. Child can extend to Parent, Where
Parent also can extend to is Parent(Grand Parent)
Parent1Class :

package Package1;

import Package2.Parent3;

public class Parent1Class extends


Parent3 {

public void mobile() {


System.out.println("Samsung");
}

public void Job() {


System.out.println("Job");
}

public static void Bike() {


//super.Bike();
System.out.println("HERO");
}

public void Money() {


System.out.println("Money");
}

public static void main(String[]


args) {
// TODO Auto-generated method
stub

//Inheritance allows new classes


to extend other classes.
//Keyword for inheritance is
extends
//child class - it is called as
subclass
//Parent class - it is called as
SUper class
//sub class can inherit variables
and Methods of the super class
//Sub class cannot extend to
multiple super class
//Sub class can override the super
class if both classes have same
Methodnames with same or
different implimentation.
Parent1Class parent = new
Parent1Class();
parent.mobile();
parent.Job();
parent.Money();
parent.Bike();
//parent.Bike();

Parent2Class :

package Package1;

public class Parent2Class {

public void Bike()


{
System.out.println("BAJAJ");
}

public void Travel()


{
System.out.println("Travel");
}
public static void main(String[]
args) {

PACKAGE2 --> Parent3

package Package2;

public class Parent3 {

public void Bike() {


System.out.println("superBike");
}
public static void main(String[]
args) {
}

Child1Class :

package Package1;

import Package2.Parent3;

public class Child1Class extends


Parent1Class{

public void Freetime() {


System.out.println("Freetime");
}

public void Student() {


System.out.println("Student");
}

public void Bike() {


//super.Bike();
System.out.println("BWM");
}

public void Mobile() {


System.out.println("iPhone");
}

public static void main(String[]


args) {

Child1Class child1=new
Child1Class();
child1.Bike();
child1.Freetime();
child1.Mobile();
child1.Student();
child1.Money();
//child1.SUperbike();
//child.Travel();

}
Child2Class:

package Package1;

public class Child2Class extends


Parent1Class {

public void Freetime() {


System.out.println("Freetime");
}

public void Student() {


System.out.println("Student");
}

public void Bike() {


System.out.println("DUKE");
}

public void Mobile() {


System.out.println("Redmi");
}

public static void main(String[]


args) {

Child2Class child2=new
Child2Class();
child2.Bike();
child2.Freetime();
child2.Mobile();
child2.Student();
child2.Money();
//child.Travel();
}

Child3 :

package Package1;

import Package2.Parent3;

public class Child3 extends


Parent3 {

public static void main(String[]


args) {

---------------------
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;

public class StaticMethod {

public static void login()


{
System.out.println("Login");
}
public static void main(String[]
args) {
login();

-------------------------------
What is Polymorphism?

Polymorphism is a concept by which we can


perform a single action in different ways, So
polymorphism means many forms. We can
perform polymorphism in java by method
overloading and method overriding.

What is meant by Method Overriding?

When a method of sub class (derived, child class)


has the same name, parameters (signature), and
same return type as the method in its super class
(base, parent class) then the method in the subclass
is said to be overridden the method in the
superclass. This feature is also known as runtime
polymorphism.
Method overriding happens if the sub-class method
satisfies the below conditions with the Super-class
method:
 Method name should be the same
 The argument should be the same
 Return type should also be the same

The key benefit of overriding is that the Sub-class


can provide some specific implementation than the
super-class implementation

What is meant by
Overloading?

When two or more methods with the same name


have either a different number of parameters or
different types of parameters, these methods may
have or may not have different return types, then
they are overloaded methods, and the feature is
method overloading. Method overloading is also
called compile-time polymorphism.

For method overloading, sub-class method should


satisfy the below conditions with the Super-class
method (or) methods in the same class itself:
 Same method name
 Different argument types
 There may be different return types

OverloadingClass :

package Package1;

public class OverloadingClass {

public void getData(int a)


{
System.out.println("Anees");
}

public void getData(String b)


{
System.out.println("Anees1");
}

public void getData(int a,int b)


{
System.out.println("Anees2");
}

public void getData(int a,String b)


{
System.out.println("Anees3");
}

public void getData(String


b,String c)
{
System.out.println("Anees4");
}

public static void main(String[]


args) {
// TODO Auto-generated method
stub
OverloadingClass object = new
OverloadingClass();

object.getData(5,"Selenium");
object.getData("Selenium");
object.getData("test","Selenium")
;
object.getData(5);
}

DAY_8

ClassAccessModifier1:

package Package1;

public class ClassAccessModifier1 {

public int x =10;


int y =20;
private int z = 30;
protected String name = "testing";

public void publicmethod() {


System.out.println("I am publicmethod");
}

void defaultmethod() {
System.out.println("I am defaultmethod");
}

private void privatemethod() {


System.out.println("I am privatemethod");
}

protected void protectedmethod() {


System.out.println("I am protectedmethod");
}
public static void main(String[] args) {
// Access MOdifier - 4 types
//public, default, protected, private

//public - Variable and Methods which are declared as public


//can accessed by any class from any package. It can be accessed outside the package

//Default - Variable and Methods which are declared as default


//can be accessed by any class in the same package. It can't be accessed outside the package

//Private - Variable and Methods which are declared as private


//can be accessed only with in the class. It can't be accessed outside the class even in the same
package

//Protected - Variable and Methods which are declared as Protected


//can be accessed by any class in the same package and child classes of other package.

ClassAccessModifier1 obj = new ClassAccessModifier1();

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;

public class ClassAccessModifier2 {

public static void main(String[] args) {


ClassAccessModifier1 obj1=new ClassAccessModifier1();

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;

public class ClassAccessModifier3 {

public static void main(String[] args) {


ClassAccessModifier1 obj2 = new ClassAccessModifier1();
ClassAccessModifier3 obj6 = new ClassAccessModifier3();
System.out.println(obj2.x);
System.out.println(obj2.y);
System.out.println(obj2.z);
System.out.println(obj6.name);
obj2.publicmethod();
obj2.defaultmethod();
obj2.privatemethod();
obj6.protectedmethod();

ClassAccessModifier4 :
package Package2;

import Package1.ClassAccessModifier1;

public class ClassAccessModifier4 extends ClassAccessModifier1 {

public static void main(String[] args) {


ClassAccessModifier1 obj4 = new ClassAccessModifier1();
ClassAccessModifier4 obj5 = new ClassAccessModifier4();
System.out.println(obj4.x);
System.out.println(obj4.y);
System.out.println(obj4.z);
System.out.println(obj5.name);
obj4.publicmethod();
obj4.defaultmethod();
obj4.privatemethod();
obj5.protectedmethod();
}

=======================================
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

You want the debugger to resume "normal" execution instead of step-by-step

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;

public class DebugClass {


public void method1() {
System.out.println("Hello1");
System.out.println("Hi1");
System.out.println("How are you");
System.out.println("Gud night");
System.out.println("Bye");
System.out.println("Good morning");
System.out.println("have a nice day");
}

public void method2() {


System.out.println("Hello2");
System.out.println("Hi2");
System.out.println("How are you2");
System.out.println("Bye2");
System.out.println("Good morning2");
System.out.println("have a nice day2");
}

public void method3() {


System.out.println("Hello3");
System.out.println("Hi3");
System.out.println("How are you3");
System.out.println("Gud night3");
System.out.println("Bye3");
System.out.println("Good morning3");
System.out.println("have a nice day3");
}

public static void main(String[] args) {


DebugClass obj = new DebugClass();

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");
}

You might also like