Thursday, November 4, 2021

# 16. control statements

 Control statements:

In java, by using control statements we can tell the flow of execution. in which order the statements should execute.

different types of control statements:

1. selection statements

    1.1. if

    1.2. if else

    1.3. nested if if else

    1.4. switch

2. looping/repetitive/iterative statements

    2.1 while

    2.2 do while

    2.3 for

    2.4 nested loops

    2.5 for each

3. transfer statements

    3.1 break

    3.2 continue

    3.3 throw

    3.4 throws

    3.5 finally

;;;;;;;;;etc


if (condition)

{

;;;;;

}

;;;;;;;;

if the condition is true it will execute the statements under the condition

if the condition is false it will execute the statements outside this 

for if the condition should be always boolean


if (condition)

{

;;;;;  //many statements with open braces

// without open braces we can take only one statement

// curly braces are optional

}

else

{

;;;;;;;;

}


package com.rameshsoft.automation.corejava;

public class SelectionStmtsDemo{

public static void main(String [] args){

int a1=45,a2=45;

if(a1<a2){

 System.out.println("Equl");

}

else{

System.out.println("noteql");

}

System.out.println(




Relational operatiors:

>

<

>=

<=

==

!=

nested if:

If inside another if called nested if

if (condition)

{

;;;;;;;;;;;;;;;

if (condition)

{

;;;;;;;;;;;;;;;;;;;;;;

}

else

{

;;;;;;;;;

}

}

else

{

;;;;;;;;;;;;;;;;;;;;;;;;;;

}


Switch:

to specify multiple conditions and to execute them based on choice-based or option based then we can go for the switch statement.

Syntax:

switch is a predefined keyword to convey it as a switch, as a part of switch condition we can specify byte, short, int, long, enums ,Strings otherwise we will get compile time error

every switch must and should open and close

case is a fixec keyword inorder to convey it as a keyword

case name is always should be of condition type

each case contain some statements

break 

All cases are going to be executed based on condition value

if no case is matched the default case is going to be executed


switch(condition)

{

case casename: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

              break;

case casename: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

              break;

case casename: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

              break;

;;;;;;;;;;;;;;;;;;;;;;;

default: ;;;;;;;;;;;;;;;;

                       break;

}


String browser="chrome";


switch(browser)

{

case "ie": System.out.println("IE browser");

        break;

case "chrome":System.out.println("chrome browser");

        break';

case "edge": System.out.println(edge browser");

        break;

case "firefox":System.out.println("firefox browser");

        break';

default: System.out.println("no case matched");

        break;

}

}

}


duplicate case names are not allowed


Saturday, September 4, 2021

# 17. loops

whenever we want to execute the same statements continuously or repeatedly we will go for looping statements

3 types of looping statements

1. while

2. do-while

3. for loop


while:

when do we go for while?

whenever we want to execute the statements continuously or repeatedly whenever we don't know the no of iterations in advance then go for while loop

if we don't know how many times we need to execute

How to define the while

standard syntax:

initialization section;        //starting point

while (condition)        // while is a keyword to convey it as while, the condition should always be boolean(true/false) otherwise we will get a compile-time error

{        //beginnig of loop

;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;

inc/dec section;

}

;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;


case 1: in while once the condition is true the loop body is executed till the condition become false.

case 2: if the condition is false 


int i=1;

while (i<=5)

{

System.out.println("Hello:"+i);

i++;  // i=i+1

}

System.out.println("oow");


do while:

if we want to execute the statement atleast once irrespective of the condition then go for do while

Standard syntax:

initialization section;        //starting point

do     

{        //beginnig of loop

;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;

inc/dec section;

}while (condition)

;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;


Friday, September 3, 2021

# 19. oops concepts

 OOPS, Concepts:

---------------------

1. Data hiding

2. Data abstraction

3. Polymorphism

    3.1. Overloading

    3.2. Overriding

4. Encapsulation

    4.1 Tightly Encapsulation

5. IS-A Relationship

6. HAS-A Relationship (Composition/ aggregation)

7. Coupling

8. Cohesion


1. Data hiding:

 Our internal data should no go out directly

after validation only, If the user is valid/ authorized then only they can access the data is a mechanism called data hiding

data hiding means we are providing some security to the data

In java how we can implement data hiding?

By using a concept called private modifier


2. data abstraction:

By hiding internal implementations, just highlight a set of business methods/ services called data abstraction.

realtime example:

ATM

a lot of services ---> 

case1: we are seeing only services(highlight)

case2: we don't see business implementations(hiding)

Any application only services are showing

We can implement data abstraction using abstracts and interfaces.


4. Encapsulation:

Encapsulation is the process of wrapping the data into a container

Ex: Water bottle is a container we are wrapping water

In java where we are going to wrap our data inside a container is called class

Every java class is the best example of encapsulation

Tightly encapsulation:

A class is said to be a tightly encapsulation class if and only if all the variables in that class should be of type private and it doesn't care about methods.

the methods can be anything


# 18. nested loops

 whenever we know the number of iterations in advance means we know how many times we need to execute the program then we go for loop

 whenever we don't know the number of iterations in advance, we don't know how many times we need to execute the program then we go for while loop 

I want to execute my loop body at least once irrespective of the condition then we can go for do-while

do and then check the condition

what is nested for loop?

A for loop inside a for loop is called nested for loop

what is nested while loop?

A while loop inside a while loop is called nested while loop

A loop inside another loop is called nested loop


for (init section; condition; inc/dec section)

{

;;;;;;;;;;;

    for (init section; condition; inc/dec section)

     {

        ;;;;;;;;;;;

       }

}


Example:

public class LoopsDemo{

public static void main(String[] args)  {

        for (int i=0; i<3; i++)        // outer loop

        {

            System.out.println("OL: " + i);

            for(int j=0; j<=3; j++)        // inner loop

            {

                System.out.println("IL: "+j);

            }

        }

   }

}

// once the control is coming to the inner loop, this inner loop is executed till the condition is false

OUTPUT:

OL: 0

IL: 0

IL: 1

IL: 2

IL: 3

OL: 1

IL: 0

IL: 1

IL: 2

IL: 3

OL: 2

IL: 0

IL: 1

IL: 2

IL: 3

OL: 3

IL: 0

IL: 1

IL: 2

IL: 3


we saw break and continue in switch case.

break:

a break is a keyword or a statement which we can use inside the switch cases and which we can use inside the looping mechanism that can be while, do-while, nested, and for loop

continue:

based on some condition if we want to skip the current iteration then we go for continue 


public class LoopsDemo{

public static void main(String[] args)  {

        for (int i=0; i<=5; i++)        // outer loop

        {

             System.out.println(i);

              if (i==2) {

              break;        // directly it comes out of for loop

               }

          }

           System.out.println("OOFL");

    }

}

OUTPUT:

0

1

2

OOFL


continue:

public class LoopsDemo{

public static void main(String[] args)  {

        for (int i=0; i<=5; i++)        

        {

            

              if (i==2) {

              continue;        // skips current iteration    

               }

             System.out.println(i);

    }

        System.out.println("OOFL");

  }

}

OUTPUT:

0

1

3

4

5

OOFL


break:

public class LoopsDemo{

public static void main(String[] args)  {

        for (int i=0; i<=5; i++)        

        {

            

              if (i==2) {

                break ;  

               }

             System.out.println(i);

    }

        System.out.println("OOFL");

  }

}

OUTPUT:

0

1

2

OOFL


PART 1 completed


part1  java basics

part2  oops

part3  selenium

part4

frameworks






















Tuesday, August 31, 2021

# 15. Local Variables

 In order to access or test non-static variables and non-static methods, there is only one approach called 1. through the object

In order to access or test static variables and static methods we have 3 approaches

1. directly by calling their names

2. through the class name

3. through object


We have total 4 types of variables

1. static

2. non-static

3. local variables

4. object/reference type variables


3. local variables(method level):


public com.rameshsoft.automation.corejava;

public class ExamDemo{

        int id=456;        // within the class we can access anywhere

public static void main(String[] args) {

        ExamDemo examDemo= new ExamDemo();

        System.out.println(examDemo.id);

}

}


public class ExamDemo{

        int id=456;        // within the class we can access anywhere

        private int practiceHrs=9;        // within the class we can access anywhere

// we cannot access outside the class 

//why because it is private


public static void main(String[] args) {

        ExamDemo examDemo= new ExamDemo();

        System.out.println(examDemo.id);

}

}


public class ExamDemo{

        public int id=456;        // within the class we can access anywhere

// out side the class also we can access

        private int practiceHrs=9;        // within the class we can access anywhere

// we cannot access outside the class 

//why because it is private


public static void main(String[] args) {

        ExamDemo examDemo= new ExamDemo();

        System.out.println(examDemo.id);

}

}


>>>public class ExamDemo{

        public int id=456;        // within the class we can access anywhere, non-static variable

// out side the class also we can access

        private int practiceHrs=9;        // within the class we can access anywhere, non-static variable

// we cannot access outside the class 

//why because it is private


public void hello() {

        System.out.println(id+practiceHrs);

}


public void hello1() {

        System.out.println(id+practiceHrs);

}

// we can access this id and practicehrs within the class anywhere


public static void main(String[] args) {

        ExamDemo examDemo= new ExamDemo();

        System.out.println(examDemo.id);

}

}

If the variable is public the scope is anywhere within the class or outside the class anywhere.

If it is private also within the class


Local variables:

1. when do we go to local variables

whenever we want to restrict the data to a certain portion of the area then we will go for local variables.

that portion of the area is nothing but a method here

whenever we declare the variables inside the methods such types of methods are called local variables

2. when we can say a variable is a local variable

whenever we declare the variables inside the methods such kinds of variables are called local variables.


>>>public class ExamDemo{

        public int id=456;        // within the class we can access anywhere, non-static variable

// out side the class also we can access

        private int practiceHrs=9;        // within the class we can access anywhere, non-static variable

// we cannot access outside the class 

//why because it is private


public void hello() {

        int salary=250000;        // local variable

        System.out.println(id+practiceHrs);

}


public void hello1() {

        System.out.println(id+practiceHrs);

}

// we can access this id and practicehrs within the class anywhere


public static void main(String[] args) {

        ExamDemo examDemo= new ExamDemo();

        System.out.println(examDemo.id);

}

}


1.How many local variables do we have within the class?

one

 int salary=250000; // declaring


>>>public class ExamDemo{

        static public int id=456;        // within the class we can access anywhere, static variable

// out side the class also we can access

        private int practiceHrs=9;        // within the class we can access anywhere, non-static variable

// we cannot access outside the class 

//why because it is private


public void hello() {

        int salary=250000;        // local variable

        System.out.println(id+practiceHrs);

}


public void hello1() {

        System.out.println(id+practiceHrs);

}

// we can access this id and practicehrs within the class anywhere


public static void main(String[] args) {

        ExamDemo examDemo= new ExamDemo();

        System.out.println(examDemo.id);

}

}

 whenever we declare variables inside the methods called local variables.


>>>public class ExamDemo{

        public int id=456;        // within the class we can access anywhere, non-static variable

// out side the class also we can access

        private int practiceHrs=9;        // within the class we can access anywhere, non-static variable

// we cannot access outside the class 

//why because it is private


public void hello() {

        id=91456;        // not local variable, reassigning the value

        int salary=250000;        // local variable

        System.out.println(id+practiceHrs);

}


public void hello1() {

        System.out.println(id+practiceHrs);

}

// we can access this id and practicehrs within the class anywhere


public static void main(String[] args) {

        ExamDemo examDemo= new ExamDemo();

        System.out.println(examDemo.id);

}

}

// there is only one local variable in the above program

// id - we are using declared variable


>>>public class ExamDemo{

       static public int id=456;        // within the class we can access anywhere, non-static variable

// out side the class also we can access

        private int practiceHrs=9;        // within the class we can access anywhere, non-static variable

// we cannot access outside the class 

//why because it is private

        double id=456.456;        // invalid

// variable name should be always unique


public void hello() {

        id=91456;        // not local variable, reassigning the value

        int salary=250000;        // local variable

        System.out.println(id+practiceHrs);

}


public void hello1() {

        System.out.println(id+practiceHrs);

}

// we can access this id and practicehrs within the class anywhere


public static void main(String[] args) {

        ExamDemo examDemo= new ExamDemo();

        System.out.println(examDemo.id);

}

}


>>>public class ExamDemo{

       static public int id=456;        // within the class we can access anywhere, non-static variable

// out side the class also we can access

        private int practiceHrs=9;        // within the class we can access anywhere, non-static variable

// we cannot access outside the class 

//why because it is private

        double id=456.456;        // invalid

// variable name should be always unique


public void hello() {

        int id=91456;        //  local variable, reassigning the value

        int salary=250000;        // local variable

        System.out.println(id+practiceHrs);

}


public void hello1() {

        System.out.println(id+practiceHrs);

}

// we can access this id and practicehrs within the class anywhere


public static void main(String[] args) {

        ExamDemo examDemo= new ExamDemo();

        System.out.println(examDemo.id);

}

}

// can have class level variable names and local variable names same.

// we have two local variables


>>>public class ExamDemo{

       static public int id=456;        // within the class we can access anywhere, non-static variable

// out side the class also we can access

        private int practiceHrs=9;        // within the class we can access anywhere, non-static variable

// we cannot access outside the class 

//why because it is private

        double id=456.456;        // invalid

// variable name should be always unique


public void hello() {

        int id=91456;        //  local variable, reassigning the value

        int salary=250000;        // local variable

// priority always local

        System.out.println(id);        // 91456

        System.out.println(salary);        //250000

}


public void hello1() {

        System.out.println(id+practiceHrs);

}

// we can access this id and practicehrs within the class anywhere


public static void main(String[] args) {

        ExamDemo examDemo= new ExamDemo();

        System.out.println(examDemo.id);

}

}


>>>public class ExamDemo{

       static public int id=456;        // within the class we can access anywhere, non-static variable

// out side the class also we can access

        private int practiceHrs=9;        // within the class we can access anywhere, non-static variable

// we cannot access outside the class 

//why because it is private

        double id=456.456;        // invalid

// variable name should be always unique


public void hello() {

       // int id=91456;        //  local variable, reassigning the value

        int salary=250000;        // local variable

        System.out.println(id);

// here we dont have id then priority goes to class and execute.

}


public void hello1() {

        System.out.println(id+practiceHrs);

}

// we can access this id and practicehrs within the class anywhere


public static void main(String[] args) {

        ExamDemo examDemo= new ExamDemo();

        System.out.println(examDemo.id);

}

}

the scope of local variable is within the method only. outside the method we cannot access.

>>>public class ExamDemo{

       static public int id=456;        // within the class we can access anywhere, non-static variable

// out side the class also we can access

        private int practiceHrs=9;        // within the class we can access anywhere, non-static variable

// we cannot access outside the class 

//why because it is private

        double id=456.456;        // invalid

// variable name should be always unique


public void hello() {

        int id=91456;        //  local variable, reassigning the value

        int salary=250000;        // local variable

        System.out.println(id+practiceHrs);

}


public void hello1() {

        System.out.println(id);

        System.out.println(salary);        //no salary in class then compile time error

        System.out.println(practiceHrs);

// if variable is not there inside the method then it will directly go to class level

}

// we can access this id and practicehrs within the class anywhere


public static void main(String[] args) {

        ExamDemo examDemo= new ExamDemo();

        System.out.println(examDemo.id);

}

}

// outside the method we cannot access local variables otherwise compile time error occur.


when do we go for local variables?

whenever we want to restrict the data to certain portion of the area then go for local variables

if you want to restrict the data to certain portion of are that is within the method only then we can go for local variable.

when we can say variable is a local variable?

whenever we declare the variables inside the methods called local variables

the scope of the local variable is within the method only, outside the method we cannot access local variables.

we can have class-level variable names and local variables names as same.

if we are trying to use within the method the priority always going to local


if we don't perform initialization of static variables  and non-static variables we will get default values


initialization of local variables is compulsory otherwise compile-time error occurs

initialization of local variables is mandatory if and only if whenever we are using that variable

public void hello() {

        int id;        // no initialization

        int salary=25000;

  System.out.println(id);        // here we are using local variable so we will get compile time error

}


public void hello() {

        int id;        // no initialization

        int salary=25000;

 // System.out.println(id);        // here we are not using local variable so no error

}

for local variables default values concept is not applicable, mandatory we should perform initialization

whenever we declare the variable inside the method then those variables are called local variables


for local variables no access specifiers/ modifiers

for local variables, there is only one modifier/ keyword is applicable

1. final


final is allowed to stop reassignment of that variable

this is a keyword that never goes to a method of local directly goes to class

initialization should be inside the method only

object type or reference type variabel:

object type or reference type variable ia a variable that always contains object

In how many places we can create objects:

In general, we can create the object in two places

1. class level ---> non static OT/RT variable

2. method-level---> static OT/RT variable














Saturday, August 28, 2021

# 14. java source file structure

 If we want to execute the program in java compulsory jvm always starts the execution from the main method.

whenever the programmer asks the jvm to run the program jvm always looks for main method.

main method is the starting point for the program.

If we dont define main method immediately we will get compile time error.

If there is no main method we cannot execute the program


JAVA Source file structure:

Source file is nothing but where we are going to write our programs

1. In a single source file we can have multiple classes/ class files

>>> class A1{

------

}

class A2{

-------

}

classA3{

-------------

}

2. If no class is declare as public then we can save that file with any name

A1.java

A2.java

A3.java

A4.java

Hello.java

Anything.java

3. It is a good programming practice that declare one class as public, the class which we declared as publice the public class and filename must be same otherwise we will get compile time error.

>>> class A1{

------

}

public class A2{

-------

}

classA3{

-------------

}

Ex: A2.java ===>valid

A1.java ===>invalid

A3.java===> invalid

Hello.java ===>invalid

4. If we are trying to define more than one class as public immediately we will get compile time error

  In a single source file we should not take more than one class as a public.

>>> class A1{

------

}

public class A2{

-------

}

public classA3{

-------------

}

// we will get compile time error

5. The class which we declare as a public in that public class only we must and should take main method.

>>> class A1{

------

}

class A2{

-------

}

public classA3{

public static void main(String[] args)

{

-------------

}// end of main

}// end of class


Benifits of ide/eclipse:

We need to focus on 

1. perspective(on what perspective u want to write the programs)

2.eclipse editor (where we are going to write our programs

3. console (where we can see the output)

4. project explorer/package explorer (where we are going to manage our projects)

5. git

6. debug


Eclipse:

right side click on + symbol

select java(default)

firse we need to create a project

goto file--->new--->project--->java project--->next---> projectname and version--->next--->finish

project got created

1.jre system library

2. src (source folder where we can write our programs)

second way to create project :

goto window---> show view--->click on console---> window--->show view--->package/project explorer

Whenever we create a project two files are going to be created automatically

Assume that the Flipkart application

we have three modules

1. men-------> 25 classes

2. women----> 20 classes

3. kids-------->45 classes

under the men module, we need to write  25 classes like that

src---> class names like men1,men2,women1,women2,kids1,kids2 etc

we have taken 90 classes

if we want to execute only kids classes then we need to look for those classes in 90 classes

if we want to look only men classes then we need to look for men classes out of 90 classes

its become complex

for example under kids module if we have different types of chacolates like 100 5star,150 kitkat,200 dairymilk, etc

if all are combined together in one box.

instead of that if we put them separately in boxes its very easy to get them.

in the same way dont write all your programs under src folder.

under src folder create packages

package is a collection of classes + interfaces+enums.

Standard syntax for package:

package <packagename>

package is a fixed keyword inorder to convey it as a package

pacakagename: can be anything but it should be very meaningful.

package men;

inside this men all the program related to men

package women;

package kids;

But this above are not valid in real time we have some standard sysntax:

domain name in reverse. modulename. submodulename

www.flipkart.com

package com.flipkart.men;

src---> new--->package

give some name like 

package com.flipkart.men;

package com.flipkart.women;

package com.flipkart.kids;


now to write all men program select this package--->new-->class---> give class name

how many classes we can write all classes

men1,men2,men3,women1,women2,women3,kids1,kids2,kids3,....... etc...

to execute kids class simply look for kids package

To run: rightclick--->run as java application

package com.flipkart.kids;

public class kids3{

 public void hello() {

 System.out.println("hello");

}

public void job(){

System.out.println("job");

}

public static void main(String [] args) {

  System.out.println("hello");

}

}

















 








Friday, August 27, 2021

# 13. main method

 In order to print some information on the console, in java, we have a method called 

System.out.println() method.

Standard syntax:

System.out.println();

>>>class Demo{

int a1=456, a2= 789;

static String name="RAMESHSOFT"

public int addition()

{

int result =a1+a2;

return result;

}

}

Ex:

int a1=456, a2= 789;

static String name="RAMESHSOFT"

Syntax:

1.System.out.println(String message);

System.out.println("Please do practice and it is mandatory");

Whatever we write in double-quotes as it is it will print on the console.

2. To print variable values on the console

System.out.println(variablename);

To print more than one variable

System.out.println(varname1+varname2+varname3+.......);

>>>System.out.println(a1);

output: 456

>>>system.out.println("a1");

Output: a1

>>> System.out.println(a1+a2);

here addition is going to be happen

output: 1245

here + is acting like a addition

System.out.println(a1+name);

output: 456 RAMESHSOFT

concatenation happened.

here + is acting like a concatenation

In java the only one overloading operator is + , sometimes it acts like addition and sometimes it acts like concatenation

>>> System.out.println(a1+name+a2);

Output: 456 RAMESHSOFT 789

>>> System.out.println(a1=a2+name);

Output: 1245 RAMESHSOFT

3. To print some message along with variable value

syntax:

System.out.println(String msg+variablename);

or

System.out.println(variablename+String msg);

>>> System.out.println("The value of a is:"+a1);

>>>System.out.println(a1+" The value of a is");

Output: 

The value of a is: 456

456 The value of a is

4. To print morethan one variable with some message

System.out.println(String msg1+variablename1+ String msg2+variablename2);

or

System.out.println(variablename1+String msg1+variablename2+String msg2);

Example:

>>> public class Addition{

public int numberOne=45;

public int numbertwo=47;

public int addition()

{

int result=numberOne+numberTwo;

return result;

System.out.println("result is: "+result);    

}

}

Whenever we compile this program we will get a compile-time error because after the return statement we should not write any statements.

A method should not contain more than one return statement.

per method we should write only one statement otherwise we will get a compile-time error.

return statement should be the last statement inside a method.

>>> public class Addition{

public int numberOne=45;

public int numbertwo=47;

public int addition()

{

int result=numberOne+numberTwo;

System.out.println("result is: "+result);  

return result;  

}

}

It will compile without any errors.

In the above program inside the method, we implemented the business logic of addition between two numbers.

Whenever we call this method it is going to be performed addition between two numbers and return result.

1. We implemented one business logic then we need to testing that it is working correctly or not.

2 in order to write a program in java we need to follow 3 standard steps

2.1 write a program

 save with .java extension

2.2. validate/compile

2.3. execute

In order to execute the java program standard syntax is

<javac>    <class name>  .java

To execute standard syntax is

,java>    <classname>

>>> javac Addition_Demo.java

>>> java Addition_Demo

The moment we click on enter here JVM is going to start. once JVM is started in this desktop JVM check this .class file is there or not.

JVM loads the .class file, whenever JVM is loading the .class file automatically all the static variables and static methods are going to be created.

JVM is going to look execution 

Whenever u ask the JVM to run the program JVM is going to look for the starting point to execute the program

Ex: to start a car we need a key point

All the static blogs are going to be executed automatically.

1. check for the class file

2. JVM looks for .class file

3. loads the .class file

4. JVM looks for execution point

What is the execution point?

Jvm is always going to starts the execution from the main() method.

the main method is the starting point for the execution

If the main method is not there we will get an error.

What is the main method in java?

In java, the main method is there for two reasons

1. whenever u ask the JVM to run the program, JVM always starts execution from the main method.

why?

JVM is internally configured in such a way that whenever the programmer is asked to run the program always starts the execution from the main method.

if the main method is not there JVM doesn't know where to start the execution that's why it's throwing a compile-time error.

* In order to execute a program, we need a main method

2. Inside the main method what we will do?

We will do testing

How to define the main method:

Standard syntax:

1. public static void main(String[] args)

{

// accessing or testing the implemented services or methods

}


2. static public void main(String[] args)

{

// accessing or testing the implemented services or methods

}


3. public static void main(String... args)

{

// accessing or testing the implemented services or methods

}

In place of the args whatever we want we can write

4. public static void main(String[] RAMESHSOFT)

{

// accessing or testing the implemented services or methods

}

5. public static void main(String... RAMESHSOFT)

{

// accessing or testing the implemented services or methods

}

/* In place of [] we can write ... three dots

6. strictfp public static void main(String[] args)

{

// accessing or testing the implemented services or methods

}

All the above main methods are valid but commonly we use first method

Main method is bydefault static method.

Where we need to define the main method

1. After starting the class immediately take main method

<as>    class   <classname>  {

public static void main(String[] args)

{

// accessing or testing the implemented services or methods

}

;;;;;;;;;;;;;;;;;;;///defined or implemented part

;;;;;;;;;;;;;;;;;

}

2. Before end of a class take main method

<as>    class   <classname>  {

;;;;;;;;;;;;;;;;;;;///defined or implemented part

;;;;;;;;;;;;;;;;;

public static void main(String[] args)

{

// accessing or testing the implemented services or methods

}

}

3. In between the class take main method

<as>    class   <classname>  {

;;;;;;;;;;;;;;;;;;;///defined or implemented part

;;;;;;;;;;;;;;;;;

public static void main(String[] args)

{

// accessing or testing the implemented services or methods

}

;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;; //implemented or defined part

}

4. Take main method in seperate class

<as>    class   <classname>  {

;;;;;;;;;;;;;;;;;;;///defined or implemented part/services part

;;;;;;;;;;;;;;;;;

}

<as>    class   <classname>  {

}

<as>    class   <classname>  {

public static void main(String [] RAMESHSOFT)

{

// accessing or testing the implemented methods / services

// execution part

}

}


>>> public class Addition_Demo{

public int numberOne=45;

public int numbertwo=47;

public int addition()

{

int result=numberOne+numberTwo;

System.out.println("result is: "+result);  

return result;  

}

public static void main(String[] RAMESHSOFT)

{

System.out.println("JVM started execution")

}//end of main method

}//end of class

there is nothing to execute

.

When this above method is going to be executed?

r u calling that method?

no

so it won't respond

We implemented one business service we need to call it

>>>javac Addition_Demo.java

>>>java Addition_Demo


public static void main(String[] RAMESHSOFT)

public void main(String[] RAMESHSOFT)

if we remove static we will get a compile-time error.

public static void main(String[] ...) ===> valid



































# 16. control statements

 Control statements: In java, by using control statements we can tell the flow of execution. in which order the statements should execute. d...