Found 2616 Articles for Java

Java Program to Add the two Numbers

AmitDiwan
Updated on 21-Jun-2024 14:21:29

9K+ Views

When we enter the coding world there are various mathematical operations that we learn to do through programming languages. We are expected to begin our coding journey with basic mathematical operations like adding, subtracting, multiplying and dividing. To evaluate the sum of two numbers, we use the '+' operator. However, Java also provides other approaches for adding two numbers. This article aims to explore the possible ways to add the two numbers in Java. To add the two numbers in Java, we are going to use the following approaches − By taking input of operands from user By ... Read More

Java Program to Print a String

AmitDiwan
Updated on 14-Jun-2024 16:39:02

15K+ Views

In this article, we will understand how to print a string in Java. A string is a pattern of characters and alphanumeric values. The easiest way to create a string is to write −String str = "Welcome to the club!!!"Whenever it encounters a string literal in your code, the Java compiler creates a String object with its value in this case, " Welcome to the club!!!'.As with any other object, you can create String objects by using the new keyword and a constructor. The String class has 11 constructors that allow you to provide the initial value of the string ... Read More

Java Program to Print an Integer

AmitDiwan
Updated on 16-Feb-2022 10:51:46

6K+ Views

In this article, we will understand how to print an integer in Java. It uses the int data type. The int data type is a 32-bit signed two's complement integer. The Minimum value is 2, 147, 483, 648 (-2^31) and the Maximum 2, 147, 483, 647(inclusive) (2^31 -1). Integer is generally used as the default data type for integral values unless there is a concern about memory. The default value is 0.InputSuppose our input isEnter an integer: 45OutputThe desired output would beThe integer is: 45AlgorithmStep 1- START Step 2- Prompt the user to enter an integer value/ define the integer ... Read More

Using XPATH to search text containing  

Debomita Bhattacharjee
Updated on 08-Feb-2022 10:47:25

13K+ Views

We can use the locator xpath to identify elements having search text with   or spaces. Let us first examine the html code of a web element having trailing and leading spaces. In the below image, the text JAVA BASICS with tagname strong has spaces as reflected in the html code.If an element has spaces in its text or in the value of any attribute, then to create an xpath for such an element we have to use the normalize-space function. It removes all the trailing and leading spaces from the string. It also removes every new tab or lines ... Read More

What is Rest Assured?

Debomita Bhattacharjee
Updated on 08-Feb-2022 10:07:35

8K+ Views

Rest Assured is used to verify the REST APIs with the help of the Java library. Java library acts like a headless client to act upon the Rest web services. The libraries based on the Rest Assured library are also capable of validating the HTTP responses from the server.Response status code, body, message, headers, and so on can be tested with the Rest Assured library. It can be integrated with build tools like Maven, unit test frameworks like JUnit and TestNG. It has an efficient matching mechanism with which we can verify the expected results.Application Programming Interface or API acts ... Read More

How to create a step definition file for Cucumber in Java?

Debomita Bhattacharjee
Updated on 22-Nov-2021 10:30:42

3K+ Views

We can create a step definition file for Cucumber. This can be done using the below steps −Step1− Click on the File menu in Eclipse. Then select the option New. Next click on OtherStep2− Click on Maven Project from the Maven folder. Then click on Next.Step3− Proceed with the further steps.Step4− Select maven-achetype-quickstart template. Then click on Next.Step5− Add GroupId as Automation, Artifact Id as Cucumber, and proceed.Step6− A project should get created with a Cucumber-type project structure. The Cucumber-related scripts should be written within the src/test/java folder.Step7− Create a new package called stepDefinations inside the src/test/java folder.Step8− Create a ... Read More

How to create a Feature file for Cucumber in Java?

Debomita Bhattacharjee
Updated on 22-Nov-2021 10:17:28

4K+ Views

We can create a Feature file for Cucumber. This can be done using the below steps−Step1− Click on the File menu in Eclipse. Then select the option New. Next click on OtherStep2− Click on Maven Project from the Maven folder. Then click on Next.Step3− Proceed with the further steps.Step4− Select maven-archetype-quickstart template. Then click on Next.Step5− Add GroupId as Automation, Artifact Id as Cucumber, and proceed.Step6− A project should get created with a Cucumber-type project structure. The Cucumber-related scripts should be written within the src/test/java folder.Step6− Create a new package called features inside the src/test/java folder.Step7− Create a feature file ... Read More

How can we handle authentication popup in Selenium WebDriver using Java?

Debomita Bhattacharjee
Updated on 18-Nov-2021 11:48:54

1K+ Views

We can handle authentication popup in Selenium webdriver using Java. To do this, we have to pass the user credentials within the URL. We shall have to add the username and password to the URL.Syntax −https://username:password@URL https://admin:admin@the-internet.herokuapp.com/basic_auth Here, the admin is the username and password. URL – www.the-internet.herokuapp.com/basic_auth Let us work and accept the below authentication popup.ExampleCode Implementation.import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver;    public class AuthnPopup{       public static void main(String[] args) {       System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");       WebDriver driver = new ChromeDriver();       String u = "admin";   ... Read More

How to scroll down a webpage in selenium using Java?

Debomita Bhattacharjee
Updated on 18-Nov-2021 11:43:33

638 Views

We can scroll down a webpage in Selenium using Java. Selenium is unable to handle scrolling directly. It takes the help of the Javascript Executor to perform the scrolling action up to an element.First of all, we have to locate the element up to which we have to scroll. Next, we shall use the Javascript Executor to run the Javascript commands. The method executeScript is used to run Javascript commands in Selenium. We shall take the help of the scrollIntoView method in Javascript and pass true as an argument to the method.Syntax −WebElement elm = driver.findElement(By.name("name")); ((JavascriptExecutor) driver) .executeScript("arguments[0].scrollIntoView(true);", elm);Exampleimport ... Read More

Memorization (1D, 2D and 3D) Dynamic Programming in Java

Sunidhi Bansal
Updated on 05-Nov-2021 06:53:56

1K+ Views

Memorization is a technique based on dynamic programming which is used to improve the performance of a recursive algorithm by ensuring that the method does not run for the same set of inputs more than once by keeping a record of the results for the provided inputs(stored in an array).Memorization can be achieved by implementing top down approach of the recursive method.Let us understand this scenario with the help of basic Fibonacci example1-D MemorizationWe will be considering a recursive algorithm with only one non constant parameter (only one parameter changes its value) hence this method is called 1-D memorization. The ... Read More

Advertisements