Found 7442 Articles for Java

Java Program to Check whether the input number is a Neon Number

Shriansh Kumar
Updated on 01-Aug-2024 11:54:45

1K+ Views

In this article, we will understand how to check whether the given input number is a neon number. A neon number is such a number whose sum of digits of square of the number is equal to the number itself. Example Scenario: Input: num = 9; Output: The given input is a neon number How to Check Neon Number in Java? To check a given input is a neon number in Java, use the below approaches − Using for loop Using while loop Using recursion Using ... Read More

Java Program to Display All Prime Numbers from 1 to N

Manisha Chand
Updated on 05-Jun-2025 09:55:00

37K+ Views

In this article, we will understand how to display all the prime numbers from 1 to N in Java. All possible positive numbers from 1 to infinity are called natural numbers. A number is a prime number if its only factors are 1 and itself and cannot be divided by any other number. 11 is a prime number. Its factors are 1 and 11 itself. Some examples of prime numbers are 2, 3, 5, 7, 11, 13, and so on. 2 is the only even prime number. All other prime numbers are odd numbers. Below is a demonstration of the ... Read More

Java Program to Add Two Complex numbers

Shriansh Kumar
Updated on 27-May-2025 10:22:40

2K+ Views

Complex numbers are expressed in the form of p + iq, where p and q indicate real numbers and i represents imaginary numbers. For instance, 8.2 + 5.6i is a complex number, where 8.2 is the real part and 5.6i is the imaginary part. As you can see, the real number part contains an integer value (mathematical, not Java integer), and the imaginary part has an additional symbol i. In this article, we will understand how to add two complex numbers in Java. Adding Complex Numbers Since complex numbers are divided into two parts (real and imaginary), the real numbers ... Read More

Java program to get input from the user

Manisha Chand
Updated on 18-Jun-2025 17:03:39

2K+ Views

In this article, we will understand how to get input from the user in Java. Java provides a built-in Scanner Class that belongs to the java.util package. The Scanner class is used to get user input. In this article, we will learn how to take different types of input, like integers, floating numbers, strings, etc., from the user in Java. Algorithm Following are the steps to get input from the user - Step 1- START Step-2- Import the Scanner class Step 3- Create a Scanner object Step 4- Prompt the user to enter ... Read More

Java program to read the number from standard input

Manisha Chand
Updated on 18-Jun-2025 18:17:59

2K+ Views

In Java, to read input from standard input(via keyboard), Java provides a built-in Scanner Class. In this article, we will understand how to read a number from standard input(via keyboard) in Java. The Scanner.nextInt() method of the Scanner class belongs to java.util package is used to read the number. The java.util.Scanner.nextInt() method scans the next token of the input as an int. The nextInt() method reads numbers in base-10 (decimal numbers) by default. To read numbers in other bases, like binary or hexadecimal, you can use nextInt(radix). Problem Statement Write a Java program to read a number from standard input. ... Read More

Using XPATH to search text containing  

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

16K+ 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

11K+ 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

4K+ 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

5K+ 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

Advertisements