Articles on Trending Technologies

Technical articles with clear explanations and examples

What is the syntax for passing Scanner object as a parameter in a method using java?

Maruthi Krishna
Maruthi Krishna
Updated on 02-Jul-2020 5K+ Views

Until Java 1.5 to read data from the user programmers used to depend on the character stream classes and byte stream classes.From Java 1.5 Scanner class was introduced. This class accepts a File, InputStream, Path and, String objects, reads all the primitive data types and Strings (from the given source) token by token using regular expressions.By default, whitespace is considered as the delimiter (to break the data into tokens).To read various datatypes from the source using the nextXXX() methods provided by this class namely, nextInt(), nextShort(), nextFloat(), nextLong(), nextBigDecimal(), nextBigInteger(), nextLong(), nextShort(), nextDouble(), nextByte(), nextFloat(), next().Passing Scanner object as a ...

Read More

How to fix "Exception in thread main" in java?

Maruthi Krishna
Maruthi Krishna
Updated on 02-Jul-2020 21K+ Views

An exception is an issue (run time error) occurred during the execution of a program. When an exception occurred the program gets terminated abruptly and, the code past the line that generated the exception never gets executed.Exampleimport java.util.Scanner; public class ExceptionExample {    public static void main(String args[]) {       Scanner sc = new Scanner(System.in);       System.out.println("Enter first number: ");       int a = sc.nextInt();       System.out.println("Enter second number: ");       int b = sc.nextInt();       int c = a/b;       System.out.println("The result is: "+c);   ...

Read More

Can we declare a static variable within a method in java?

Maruthi Krishna
Maruthi Krishna
Updated on 02-Jul-2020 7K+ Views

A static filed/variable belongs to the class and it will be loaded into the memory along with the class. You can invoke them without creating an object. (using the class name as reference). There is only one copy of the static field available throughout the class i.e. the value of the static field will be same in all objects. You can define a static field using the static keyword.Examplepublic class Sample{    static int num = 50;    public void demo(){       System.out.println("Value of num in the demo method "+ Sample.num);    }    public static void main(String ...

Read More

How and where does String literals in Java stored in the memory?

Maruthi Krishna
Maruthi Krishna
Updated on 02-Jul-2020 8K+ Views

Strings are used to store a sequence of characters in Java, they are treated as objects. The String class of the java.lang package represents a String.You can create a String either by using the new keyword (like any other object) or, by assigning value to the literal (like any other primitive datatype).Examplepublic class StringDemo {    public static void main(String args[]) {       String stringObject = new String("Hello how are you");       System.out.println(stringObject);       String stringLiteral = "Welcome to Tutorialspoint";       System.out.println(stringLiteral);    } }OutputHello how are you Welcome to TutorialspointStorage of ...

Read More

Why should you be careful about String concatenation (+) operator in loops using Java?

Maruthi Krishna
Maruthi Krishna
Updated on 02-Jul-2020 4K+ Views

Strings are used to store a sequence of characters in Java, they are treated as objects. The String class of the java.lang package represents a String.You can create a String either by using the new keyword (like any other object) or, by assigning value to the literal (like any other primitive datatype).Public class Sample{    Public static void main(String args[]){       String str1 = "Hello";       String str2 = "how are you";    } }Strings are immutable in Java i.e. once you create a String literal it cannot be modified.StorageSince all the String values we define ...

Read More

In how many ways we can concatenate Strings in Java?

Maruthi Krishna
Maruthi Krishna
Updated on 02-Jul-2020 416 Views

Strings are used to store a sequence of characters in Java, they are treated as objects. The String class of the java.lang package represents a String.You can create a String either by using the new keyword (like any other object) or, by assigning value to the literal (like any other primitive datatype).String stringObject = new String("Hello how are you"); String stringLiteral = "Welcome to Tutorialspoint";Concatenating StringsYou can concatenate Strings in Java in the following ways −Using the "+" operator: Java Provides a concatenation operator using this, you can directly add two String literalsExampleimport java.util.Scanner; public class StringExample {    public ...

Read More

How do we set the Java environment variable in cmd.exe?

Maruthi Krishna
Maruthi Krishna
Updated on 02-Jul-2020 1K+ Views

When you install Java in your system first of all you need to set the environment variables which are path and class path.PATH− The path environment variable is used to specify the set of directories which contains executional programs.When you try to execute a program from command line, the operating system searches for the specified program in the current directly, if available, executes it.In case the programs are not available in the current directory, operating system verifies in the set of directories specified in the ‘PATH’ environment variable.You need to set path for compiler (javac.exe) and JVM(java.exe), which exists in ...

Read More

Can we make Array volatile using volatile keyword in Java?

Maruthi Krishna
Maruthi Krishna
Updated on 02-Jul-2020 2K+ Views

The volatile modifier indicates the JVM that the thread accessing a volatile variable should get data always from the memory. i.e. a thread should not cache the volatile variable.Accessing a volatile variable synchronizes all the cached copied of the variables in the main memory. Volatile can only be applied to instance variables, which are of type object or private. A volatile object reference can be null.Examplepublic class MyRunnable implements Runnable {    private volatile boolean active;    public void run() {       active = true;       while (active) { // line 1         ...

Read More

What is the difference between selenium and automation?

Adiya Dua
Adiya Dua
Updated on 02-Jul-2020 2K+ Views

Automation − It is the technique to run the test cases without human intervention. If we are sticking to the IT industry, Automation is not just confined to Automation of test scripts. Automation is the basic control system in which human intervention is expected the least. Various many tasks such as Data Migration, Decision making for AI, deploying the code automatically in the latest builds for testing etc.Goals −The ultimate goal of Automation is to re-run the regression flows without intervention of manual tester. Initializing some amount of human effort is required to design the scripts. But the end result ...

Read More

What is Maven in selenium?

Adiya Dua
Adiya Dua
Updated on 02-Jul-2020 3K+ Views

Maven is Yiddish Word which means Accumulator of Knowledge. Maven is a tool which is used for building and managing Java Based Projects. Basically to put it in simple words is a way to manage dependency for Java Based Project. Maven can be used when building project with POM (Page Object Model) when working on big projects.Below are the objectives which can be achieved with maven −Easier and Uniform build process.Providing quality project informationEasy DocmentationBest practices developmentManage the dependenciesLets understand them one by oneEasier and Unfirom Build Process −Maven provides pom.xml configuration files where all information such as construction directory, ...

Read More
Showing 52441–52450 of 61,297 articles
Advertisements