HomeSelenium

Understanding Java programs, Variables, Data Types, Literals and Operators (Selenium 4 – Session 5)

Understanding Java Programs, Variables, Data Types, Literals and Operators

Understanding Java Programs


  • In Java programs, we have to enclose everything inside a Class.Syntax: public class ClassName {          }
  • In Java programs, execution starts from the main method
  • Syntax of main() method – public static void main(String args[]){   }
  • All the Java statements in Java should end with ‘;‘ symbol
  • Example for a Java Statement is nothing but print statement – System.out.println(“Hello World”);
  • All the Java statements should be written inside the methods
  • We generally write code which is nothing but a set of statements inside the methods
  • Keywords like public, static, void and String args[] will be explained later

Compiler Errors

Java Complier Errors will be displayed when we make syntax mistakes in the Java Code:
  • Example: All the Java statements in Java should end with ‘;’ symbol
  • Remove the ; from the end of Java Statement
  • Example: Java is case sensitive
  • Replace ‘S’ with ‘s’ in the statement
  • Example: Remove any of the closing brace

Print Statements

Print statements in Java are used to print the program output to the console.
  • The below are the two types of print statements in Java:
  • Demonstrate print statements
  • Demonstrate println statements
  • Demonstrate printing a number and text
  • IntelliJ Idea shortcuts for writing print statements
  • Type sout and press Tab key

Comments

Comments provided in a Java program won’t be executed and are generally used to explain the underlined code.
  • The below are the two types of comments in Java:
  • Demonstrate single line comments
  • Syntax: // Sample Comment Text
  • Demonstrate multi line comments
  • Syntax: /* Sample Comment Text */

Variables, Data Types, Operators and Literals


In order to store the data in Java programs, we need to use Variables, Data Types, operators and Literals.
  • Example: int a = 5; 
  • Refer more details here
  • Demonstrate a program which stores the data into a variable and prints it

Variables

Variable is a name provided to a reserved memory location.
  • Refer more details here

Data Types

We can define the variables with different Data types, based on the type of data to be stored.

The below are the different data types in Java:

  • byte
  • short
  • int
    • Assigning another value to the same variable
    • Creating multiple variables of the same data type
  • long
  • double
  • float
  • char
  • boolean

String is not a data type in Java

  • String is a predefined class in Java

Operators

Operators are just symbols used to perform operations on the provided data.
  • The below are the different types of Operators in Java:
  • Demonstrate all Operators here

Literals

Literals in Java are the representation of numeric, boolean, string and character data
  • Integer Literals – Numerical values in the range of -2147483648 to 2147483647
  • Long Literals – Numerical values in the range of -9223372036854775808 to 9223372036854775807L
  • Floating Point Literals – Example: 123.456F
  • Double Literals – Example: 123.456
  • Boolean Literals – true or false
  • Character Literals – Example: ‘S’
  • String Literals – Example:  “Hello World”

By,
Arun Motoori

Comments (0)

Leave a Reply

Your email address will not be published. Required fields are marked *

For FREE Testing Tutorials & Videos

X
Open chat
Contact Us on Whatsapp