Selenium Java Interview Questions

Embed Size (px)

DESCRIPTION

selenium interview questions

Citation preview

  • www.thetestingworld.com Call/Whatsapp - 874391 3121

    www.thetestingworld.com

    TESTINGWORLD

  • www.thetestingworld.com Call/Whatsapp - 874391 3121

    www.thetestingworld.com

    TESTINGWORLD

    Advantage of Selenium over QTP

    1 Free (No license fees is required)2 Support large number of browser(QTP support only 3)3 Support large number of programming language(C#, Java, Python, Perl etc), QTP support only VB script4 With the help of grid we can execute multiple test cases in parallel, ultimately we are saving lot of executiontime, this kind of feature not available in QTP

    Advantage of QTP over Selenium

    1 User Friendly, Easy to work on2 Can develop test cases in much faster way as compared to Selenium3 Support all type of application(client-server, window , web)4 Limited programming skills are required

    Difference between Selenium IDE, RC and WebDriver

    Selenium IDE Selenium RC SeleniumWebDriver

    It only works in Mozillabrowser.

    It supports with all browserslike Firefox, IE, Chrome, Safari,

    Opera etc.

    It supports with all browserslike Firefox, IE, Chrome, Safari,

    Opera etc.It supports Record and

    playbackIt doesnt supports Record and

    playbackIt doesnt supports Record and

    playbackDoesnt required to start serverbefore executing the test script.

    Required to start server beforeexecuting the test script.

    Doesnt required to start serverbefore executing the test script.

    It is a GUI Plug-in It is standalone java programwhich allow you to run Html

    test suites.

    It actual core API which hasbinding in a range of languages.

    Core engine is Javascript based Core engine is Javascript based Interacts natively with browserapplication

    Very simple to use as it isrecord & playback.

    It is easy and small API As compared to RC, it is bitcomplex and large API.

    It is not object oriented APIs are less Object oriented APIs are entirely Objectoriented

    It doesnt supports of movingmouse cursors.

    It doesnt supports of movingmouse cursors.

    It supports of moving mousecursors.

    Need to append full xpath withxpath=\\ syntax

    Need to append full xpath withxpath=\\ syntax

    No need to append full xpathwith xpath=\\ syntax

    It does not support to testiphone/Android applications

    It does not support to testiphone/Android applications

    It support to testiphone/Android applications

    Commands to Create Webdriver object for different browsers

  • www.thetestingworld.com Call/Whatsapp - 874391 3121

    www.thetestingworld.com

    TESTINGWORLD

    FirefoxFirefoxDriver driver = new FirefoxDriver();

    Chrome DriverSystem.setProperty("webdriver.chrome.driver", "path of chrome driver executable");ChromeDriver driver = new ChromeDriver();

    IE DriverSystem.setProperty("webdriver.ie.driver", "path of ie driver executable");InternetExplorerDriver driver = new InternetExplorerDriver();

    All Supported Element Locators in Selenium

    Supported in RCSupported in WebdriverElement Locator

    id=findElementByIdId

    name=findElementByNameName

    identifier=Not AvailableIdentifier

    link=findElementByLinkTextfindElementByPartialLinkText

    Link

    css=findElementByCssSelectorCSS

    dom=Not AvailableDOM

    xpath=//findElementByXpathXPATH

    class=findElementByClassNameClass Name

    Not availablefindElementByTagNameTag Name

    What is Annotation

    Annotation can be defined as metatag, which holds information about methods which are placed next to it.Unit Testing tool like Junit and TestNg support Annotations

    Annotations in Junit

    @Test@Test (timeout=500)@Test(expected=IllegalArgumentException.class)

  • www.thetestingworld.com Call/Whatsapp - 874391 3121

    www.thetestingworld.com

    TESTINGWORLD

    @Before : Will execute before every @Test Annotation@After : Will execute after every @Test Annotation@BeforeClass : Will execute before executing any other annotation, execute only once at the start@AfterClass : Will execute after executing all other annotation, execute only once at the end@Ignore : Used with @Test annotation, will skip execution of particular test method@Parameterized : Used for running my test case with multiple data

    Order of Execution@BeforeClass @Before @Test @After @AfterClass

    Annotations Supported in TestNg

    @Test : Marks a class or a method as part of the test.@BeforeSuite : The annotated method will be run before all tests in this suite have run.@AfterSuite : The annotated method will be run after all tests in this suite have run.@BeforeTest : The annotated method will be run before any test method belonging to the classes insidethe tag is run.@AfterTest : The annotated method will be run after all the test methods belonging to the classesinside the tag have run.@BeforeGroups : The list of groups that this configuration method will run before. This method isguaranteed to run before the first test method that belongs to any of these groups is invoked.@AfterGroups : The list of groups that this configuration method will run after. This method is guaranteedto run shortly after the last test method that belongs to any of these groups is invoked.@BeforeClass : The annotated method will be run before the first test method in the current class isinvoked.@AfterClass : The annotated method will be run after all the test methods in the current class havebeen run.@BeforeMethod : The annotated method will be run before each test method.@AfterMethod : The annotated method will be run after each test method.

    Order of Execution@BeforeSuite @BeforeTest @BeforeGroup @BeforeClass --> @BeforeMethod @Test @AfterMethod @AfterClass @AfterGroup @AfterTest @AfterSuite

    Difference between Junit & TestNg

    JunitTestNg

    For reports, we need to use ANTGenerate html reports automatically

    We cant create report of 1 test case, only reportsfor test suites can be generated

    Can generate report for test case as well as testsuite

    Support annotationSupport more annotations than Junit, make it moreflexible

    Cant set order of execution of multiple testannotation in single class file

    Can set order of execution of multiple testannotation in single class file using priority

  • www.thetestingworld.com Call/Whatsapp - 874391 3121

    www.thetestingworld.com

    TESTINGWORLD

    No concept of group executionCan execute particular group of test cases

    Build.xml is complex and difficult to understandTestNg.xml is very simple and easy to understand

    Cant set multiple threads(parallel execution)We have option to set threads for parallelexecution(used in Grid)

    Different ways to open URL in Webdriver

    get() and navigate() both are used to open URL/application in webdriverDifference is that in case of get() method, we can just open a URL while in case of navigate() method, we canuse forward and back button of browser

    Navigate() methodGet() method

    driver.navigate().to("http://rediff.com");driver.navigate().back();driver.navigate().forward();

    driver.get("http://rediff.com");

    Wait in Webdriver Or Ajax handling in Selenium Webdriver

    1 Thread.sleep(10)Thread is a java class, we are calling sleep method of that classIt will add a forcefully wait at particular pointThis is used when we want to always pause our execution at specific point

    2 ImplicitWaitImplicitly wait are mainly used when our element on page are taking some time to loadIt we dont add any wait in our script, then our driver will search for element and if not found immediatelyfailed that stepIn case of implicitly wait, our driver will wait for specified time(time mentioned in implicitly wait) for thatelement to be presentThis wait will be applicable for findElements commands onlyThis need to placed at the start of test case, will be applied on all findElements commands

    FirefoxDriver driver = new FirefoxDriver();driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

    3 Explicit Wait (WebdriverWait class)Explicitly wait (WebdriverWait class), is mainly used when we want to wait in script until a specified conditionis satisfied or max timeout we have given

    FirefoxDriver driver = new FirefoxDriver();WebDriverWait wait = newWebDriverWait(driver, 10);wait.until(ExpectedConditions.textToBePresentInElement(By.id("f_id"), "Hello"));

    4 Fluent WaitIt implements Wait interface and we create object of FluentWait classHere we can set maximum time we should wait for element to be present(withTimeout method)Here we can set after how much time, it will check for element to be present (pollingEvery method)Here we can ignore any exception if it comes at runtime while waiting (ignoring method)

  • www.thetestingworld.com Call/Whatsapp - 874391 3121

    www.thetestingworld.com

    TESTINGWORLD

    Wait wait = new FluentWait(driver).withTimeout(30, SECONDS).pollingEvery(5, SECONDS).ignoring(NoSuchElementException.class);

    Working with LIST AND DROPDOWN in selenium

    Selenium RCSelenium WEBDRIVER

    // Working with Listselenium.addSelection("ElementLocator", "Value");

    // Working with Dropdownselenium.select("ElementLocator", "Value");

    // To Work on dropdown or List we need to create objectof Select classSelect dateselect = newSelect(driver.findElementById("f_mydata"));

    // Here we have 3 options to select an elementdateselect.selectByIndex(1);dateselect.selectByValue("15");dateselect.selectByVisibleText("MyData");

    Taking snapshot in Webdriver

    // Creating webdriver objectFirefoxDriver driver = new FirefoxDriver();driver.get("http://rediff.com");

    // Taking screenshot in WebdriverFile outSnapshot =driver.getScreenshotAs(OutputType.FILE);

    // Use FileUtils class to copy snapshot taken in//previous step to my diskFileUtils.copyFile(outSnapshot, newFile("C:\\snaps.png"));

    Difference between Assert and Verify

    Verify: If verify got failed, it will fail that particular stepand execution will move to next step, remaining stepswill execute of that test case

    Assert : If assert got failed, execution of that test casewill halt on that step, no more steps of that test case willexecute

    Multiple Windows handling in Webdriver

    // Creating webdriver objectFirefoxDriver driver = new FirefoxDriver();driver.get("http://rediff.com");

    // getWindowHandles method of driver class return //astring// this string is a unique key referencing all//browsers/opend by our webdriver,//we save all values in a SetSet hs = driver.getWindowHandles();

    // Iterating to the set and picking all available valuesIterator iter = hs.iterator();

    // Setting iterator to work until value exist therewhile(iter.hasNext()){// Here we can perform different actions on window'// here in code we are just moving to the windows// and closing all windows opened by webdriverdriver.switchTo().window((String) iter.next()).close();}

    How to implement object repository in Selenium OR How to manage elements in Selenium?

  • www.thetestingworld.com Call/Whatsapp - 874391 3121

    www.thetestingworld.com

    TESTINGWORLD

    In selenium, first we pick element locator of all elements on which we are supposed to perform our action andplace in a property file(Here property file behave as Object Repository for Selenium)Now wherever in our test case, element locator value is required. We fetch element locator value fromproperties file (this is called properties file because extension of this file is .properties)To fetch value of element locator from property file, we need to create object of ResourceBundle class andby that object we can use getStringmethod.

    What are Desired Capabilities?

    Desired Capabilities help to set properties for the Web Driver. A typical use case would be toset the path for the Firefox Driver if your local installation doesn't correspond to the defaultsettings.DesiredCapabilities capabilities = DesiredCapabilities.firefox();capabilities.setCapability(CapabilityType.PROXY, proxy);How to perform Keyboard and Mouse Operations in SeleniumOrHow to Handle Page onLoad Authentication

    For attachment and downloading we need to perform some keyboard or mouse operations, for that we havefew options in Selenium

    2 Through Actions class of Selenium Webdriver To perform keyboard operation To perform mouse operation Perform Right Click Perform double click Drag and Drop Scroll Up and down the window

    Actions action = new Actions(driver);action.click();action.doubleClick();action.dragAndDrop(By.id("sourceelementlocator"),By.id("destinationelementlocator"));action.contextClick(); // Right Clickaction.keyDown(Keys.CONTROL);

    // Move cursor to the Other ElementWebElement mnEle =dr.findElement(By.id("shop"));action.moveToElement(mnEle).perform();

    1. Through ROBOT Class of JAVA To perform keyboard operation To perform mouse operation

    Robot action = new Robot();action.keyPress(KeyEvent.VK_0);action.keyRelease(KeyEvent.VK_0);action.mousePress(MouseEvent.MOUSE_CLICKED);action.mouseMove(10, 20);

    3 AutoIT (Page Onload authentication and Keyboard andMouse Operations)Sometimes when you are Automating Web pages, youmay come across Page onload Authentication window.This window is not java popup/div. It is windows popup.Selenium directly cannot handle this windows popup.

    This tool can also be used to handle windows thats comeswhile attaching and downloading attachment with email.

    What is POM in Selenium ? What is its advantage ?

    POM refers to Page Object Model which encapsulate the internal state of a page into a single pageobject. UI changes only affect to a single Page Object, not to the actual test codes.Advantages :Code re-use: Able to use the same page object in a variety of tests cases.

  • www.thetestingworld.com Call/Whatsapp - 874391 3121

    www.thetestingworld.com

    TESTINGWORLD

    Reduces the amount of duplicated code.

    How can we get the font size, font color, font type used for a particular text on a webpage usingSelenium web driver?driver.findelement(By.Xpath("Xpath ").getcssvalue("font-size or font-colour or font-type);

    How to overcome same origin policy through web driver?DesiredCapabilities capability=new DesiredCapabilities();capability.setCapability(CapabilityType.PROXY,"http://wpadnod.microsft.com/wpad.dat");FirefoxDriver f = new FirefoxDriver(capability);How to Get page title in selenium webdriver ?driver.getTitle();

    How to Get Current Page URL In SeleniumWebDriverdriver.getCurrentUrl();

    Check Whether Element is Enabled Or Disabled In SeleniumWeb driver.boolean fname = driver.findElement(By.xpath("//input[@name='fname']")).isEnabled();System.out.print(fname);Above syntax will verify that element (text box) fname is enabled or not. You can use it for any inputelement.

    Does WebDriver support file uploads?Yes, You can't interact with the native OS file browser dialog directly, but we do some magic so thatif you call WebElement#sendKeys("/path/to/file") on a file upload element, it does the right thing.Make sure you don't WebElement#click() the file upload element, or the browser will probably hang.

    Difference between Absolute path & Relative path.Absolute path will start with root path (/) and Relative path will from current path (//)

    How do you verify if the checkbox/radio is checked or not ?driver.findElement(By.xpath("xpath of the checkbox/radio button")).isSelected();

    How do you handle alert pop-up ?To handle alert pop-ups, we need to 1st switch control to alert pop-ups then click on ok or canclethen move control back to main page.Syntax-String mainPage = driver.getWindowHandle();Alert alt = driver.switchTo().alert(); // to move control to alert popupalt.accept(); // to click on ok.alt.dismiss(); // to click on cancel.//Then move the control back to main web page-driver.switchTo().window(mainPage); to switch back to main page.

    How to get typed text from a textbox ?String typedText = driver.findElement(By.xpath("xpath of box")).getAttribute("value"));

  • www.thetestingworld.com Call/Whatsapp - 874391 3121

    www.thetestingworld.com

    TESTINGWORLD

    What is WebDriverBackedSelenium ?WebDriverBackedSelenium is a kind of class name where we can create an object for it as below:Selenium wbdriver= newWebDriverBackedSelenium(WebDriver object name, "URL ")The main use of this is when we want to write code using both WebDriver and Selenium RC, wemust use above created object to use selenium commands.

    How to get the number of frames on a page ?List framesList = driver.findElements(By.xpath("//iframe"));int numOfFrames = frameList.size();

  • www.thetestingworld.com Call/Whatsapp - 874391 3121

    www.thetestingworld.com

    TESTINGWORLD

  • www.thetestingworld.com Call/Whatsapp - 874391 3121

    www.thetestingworld.com

    TESTINGWORLD

    Why JAVA code is machine and platform independent?

    When we compile java code, it convert java file to byte code (class file) rather than machine code,byte code is machine and platform independent (.class file). We can interpret these class file to anymachine having JVM, JVM is used to interpret class file and convert it to machine dependent codeand then execute it.

    What are different types of access modifiers?-

    Access modifiers are used while creating class, method or variable.public: Any thing declared as public can be accessed from anywhere.private: Any thing declared as private can be accessed inside class only cant be seen outside of its class.protected: Any thing declared as protected can be accessed by classes in the same package andsubclasses in the other packages.Default : Can be accessed only to classes in the same package.

    What is Garbage Collection and how to call it explicitly?-

    When an object is no longer referred to by any variable, java/JVM automatically reclaims memory used by thatobject. This is known as garbage collection.System. gc() method may be used to call it explicitly.

    What do you understand by keywords String , StringBuffer and StringBuilder ?

    Strings can be handled by 3 classes in Java: String, StringBuffer, StringBuilder

    String StringBuffer StringBuilderString Class is immutable StringBuffer is mutable StringBuilder is mutable

    object cannot be modified (allchanges that we are

    doing(uppercase, lowercase,substring etc) on string object,is creating a new string objectand old data still persist and

    become garbage(lot of garbageis generating, impact on

    performance)

    objects can be modified objects can be modified

    StringBuffer is threadsafe(synchronized) but slow

    StringBuilder is not threadsafe(not synchronized) and fast

    This keyword in java

    This keyword can be used with variable, with the help of this keyword we can set which one is class variableand which one is local variable(this.variable name shows , this is a class variable)

    This keyword can also be used to call current class overloaded constructor.This keyword can be used to call current class methods

  • www.thetestingworld.com Call/Whatsapp - 874391 3121

    www.thetestingworld.com

    TESTINGWORLD

    Static keyword in Java

    Static keyword in Java can be used with variable, method and nested class(class inside another class)static variable: static variable holds single memory location independent to number of objects we have created,all objects will access data from same memory location.static methods: static methods are like static variable holds single memory location for all objects.

    STATIC methods/variable can be called by the class name itself without creating object of the classStatic nested class object created without creating object of its outer classMethods, variables which are not static is called instance variable/methods

    Super keyword in Java

    Super keyword in java is used to call parent class override method or parent class constructorSuper Class Method Calling1--> In case child class override, parent class method. When we create child class object and call overridemethod it will access child class method but if we want to access parent class method, we are going to usesuper keywordSuper Class Constructor Calling2--> super keyword is used to call parent class constructor as well

    Difference between :-`

    Abstract Method Concrete Method

    Methods which are just declared not defined ormethod without body.

    Methods which are declared and defined as well ormethod with body.

    Abstract Class Concrete Class

    Class with abstract & concrete methods. Havingat least 1 abstract method

    Class with concrete methods only

    Cannot create object of abstract class Can create object of concrete class

    Abstract Class Interface

    Class with Abstract + Concrete methods Interface can have only abstract methods

    Can have constants as well as variable Variable declared are by default final(meansconstants)

    We can inherit only 1 class We can inherit multiple interface(by this way java issupporting multiple inheritance)

    Use extends keyword for inheritance Use implements keyword for inheritance

  • www.thetestingworld.com Call/Whatsapp - 874391 3121

    www.thetestingworld.com

    TESTINGWORLD

    JAVA OOPS Concepts

    Polymorphism:means same name multiple use.Overloading and Overriding concept in java implements polymorphism

    2 type polymorphism: Compile Time and RunTimeOverriding is a runtime polymorphism as 2 methods are having same name and signature so at the run time itis decided which method to callOverloading is a compile time polymorphism, as while compiling JVM knows which method is to call bynumber and type of arguments

    Inheritance:With the help of inheritance, we can transfer the properties of a class to child class

    Data Encapsulation:Wrapping up of data and function in a single unit is called encapsulation.In java class implements the concept of encapsulation

    Data Abstraction:Make class/ methods abstractAbstract class and Interface implements the concept of Data Abstraction

    What is method overloading and method overriding?-

    Method Overloading:When more than 1 method in a class having the same method name but different signature(Different signature means different number and type of arguments) is said to be method overloading.

    Method Overriding:When patent and child class have same name and same signature (signature means number and type ofarguments) method, this is called method overriding.(Method overriding exist in case of inheritance only, when we are making parent-child relationship betweenclasses)

    Inheritance

    With the help of inheritance we can transfer the properties of a class to another classClass which is inherited is called Parent Class or Super ClassClass which inherit other class is called Child Class or Sub ClassAfter inheritance, child class objects can access parent class method and variables .

    extends is the keyword which is used to inherit classimplements is the keyword which is used to inherit interface

    Type of InheritanceSingle/SimpleInheritance

    Multilevel Inheritance Multiple Inheritance Hybrid Inheritance

    Supported in Java Supported in Java Not directly supported(supported throughinterface)

    Not directly supported(supported throughinterface)

  • www.thetestingworld.com Call/Whatsapp - 874391 3121

    www.thetestingworld.com

    TESTINGWORLD

    Constructors

    Constructor can be defined as a group of code (same like method) which is used for initializationInitializationmeans anything that we want to perform at startPoints to remember:-

    Constructor name is always same as class name Constructor does not return any value so we dont write void while creating constructor Constructors are automatically called when object is created we need not to call them explicitly as we

    do in methods( as constructor is automatically called when object is created so all code pasted insideconstructed is executed before we use class object to call any other methods, thats why it is calledinitialization)

    We can have more than 1 constructor in a class with different signature, this is called constructoroverloading

    Exception handling in Java

    1>> throws keyword : we can place throws keyword in front of our method definition and we can mentionclasses of all exception which we want to handle or we can mention parent class Exception

    2>> Try catch -- finally blockCode that can throw exception, need to be placed in try blockAfter getting exception, whenever the action we want to perform will be placed in catch blockIf we want to perform some task at the end does not matter exception came or not we will paste that code infinally blockWe can use try block then catch block

    try block then finally block(we can skip catch block)try block then catch block then finally block

    Difference between Throw and Throws in Exception handling

    1--> Throws is used in Method Signature while Throw is used in Java Code (send the instance of Exception class)2--> Throws, we can mention multiple type of exception, separated by comma while in throw we can set only 1exception class instance3-->Throws keyword just throws exception need not to handle it, throw pass exception instance to callerprogram

    What do you understand by keywords final, finalize and finally?-

    final :final keyword can be used for class, method and variables.A final class cannot be inherited, a final method cant be override.A final variable becomes constant, we cant change its value

    finally :finally, keyword used in exception handling.It is used with a block of code that will be executed after a try/catch block has completedThe finally block will execute whether or not an exception is thrown.Means if exception is not throws then Try execute then Finally will execute, in case when exception is thrownfinally will execute after catch e

    Example : Like we have written DB connection code in try block but exception comesIn that case connection persist with DB and no other user are allowed to create connection, So in that kind ofscenario we want whatever the condition comes, may be exception or not, my DB connection should break,for that Ill paste connection breaking code in finally() block

  • www.thetestingworld.com Call/Whatsapp - 874391 3121

    www.thetestingworld.com

    TESTINGWORLD

    finalize() : finalize() method is used to code something that we want to execute just before garbage collectionis performed by JVM

    Generic Method/ Classes in Java

    In java Generic can be used with Methods and Classes

    Generic means we create generic method which serves our multiple purposes like we can use same methodfor multiple tasks like, sorting an integer array, String array etc.

    Generic Methods : We can create generic methods which can be called by different type ofarguments, methods will server request on the behalf of type of argument coming with request

    Collection in Java OR List in Java OR Set in Java or MAP in Java

    Collection is a interface, which gives architecture to hold multiple data by same nameIn JAVA, Collection interface is implemented by Set, List and Map

    SET LIST MAP-It is used to hold multiple data(same or different data type)

    -Cannot hold duplicate values

    -Can have maximum 1 null value

    -It is used to hold multiple data(same or different data type)

    - Can hold duplicate values

    -Values can be accessed by indexsame like Array

    Map holds data in the form of keyvalue pair

    Difference between Array and ArrayList

    Array ArrayList

    Use to hold multiple data of single data type Use to hold multiple data of single/diff data type

    Need to define size of array Need not to define size, size automatically increase/decrease as we add/remove element

    Can access data through index Can access data through Iterator

  • www.thetestingworld.com Call/Whatsapp - 874391 3121

    www.thetestingworld.com

    TESTINGWORLD

    How to Iterate on HashMap?

    Answer: Iterating to List and Set is very simple but in case of HashMap we have to use an extra method"keySet" which pass hashmap object to Iterator

    package mypack;import java.util.HashMap;import java.util.Iterator;import org.junit.Test;import org.openqa.selenium.ie.InternetExplorerDriver;public class MyClas {public static void main(String aa[]){

    HashMap hp = new HashMap();hp.put("K1", "Val1");hp.put("K2", "Val2");Iterator itr= hp.keySet().iterator();while(itr.hasNext()){

    String k = itr.next().toString();System.out.println(hp.get(k));

    }}}

  • www.thetestingworld.com Call/Whatsapp - 874391 3121

    www.thetestingworld.com

    TESTINGWORLD

    Java Programs for Selenium Interview

    Interchanging Values of 2 variable without using 3rd Variable

    package org.abcpublic class Tst1 {

    public static void main(String aa[]){

    int i,ji=100j=300i=i+j // 400j=ij//400300=100 Now j=100i=ij//400100=300 Now i=300// Here we can see values exchanged successfully without using 3rd variableSystem.out.println(i)System.out.println(j)

    }}

    Printing * Triangle** ** * *

    package mypackpublic class MyClas {public static void main(String aa[]){

    int Num=3int i,j,kSystem.out.println("Star Triangle up to "+Num+" line is below" )// Here First loop is created for switching linefor(i=0iij){

    System.out.print(" ")}

    // Here this loop is created for printing * in every linefor(k=0k

  • www.thetestingworld.com Call/Whatsapp - 874391 3121

    www.thetestingworld.com

    TESTINGWORLD

    }}}Print * Triangle* * * ** * ** **

    package mypackpublic class MyClas {public static void main(String aa[]){

    int i,j,k// Here First loop is created for switchinglinefor(i=0i

  • www.thetestingworld.com Call/Whatsapp - 874391 3121

    www.thetestingworld.com

    TESTINGWORLD

    found")}}

    System.out.print(i[j] + " ")}}

    Fabonacci Series upto 100

    package mypackpublic class MyClas {public static void main(String aa[]){

    // Fabonnaci series upto 100// Fabonacci Series 0,1,1,2,3,5(next number = add of last 2 numbers)int a=0,b=1,z=0System.out.print(a + " , " + b )while (z

  • www.thetestingworld.com Call/Whatsapp - 874391 3121

    www.thetestingworld.com

    TESTINGWORLD

    }// class close

    Find SubString using logic

    package mypackpublic class MyClas {public static void main(String aa[]){

    String a="Hello World"String b ="llo W"int flag=0, lenb= b.length()try{for(int j=0j

  • www.thetestingworld.com Call/Whatsapp - 874391 3121

    www.thetestingworld.com

    TESTINGWORLD

    System.out.println("Element is notfound")

    }}

    System.out.println(arrString[i])

    }}

  • www.thetestingworld.com Call/Whatsapp - 874391 3121

    www.thetestingworld.com

    TESTINGWORLD