Java Programming

Advanced Java Programming

Deep dive into Java fundamentals, data types, variable naming rules, and all four types of operators with practical examples

Lesson Overview

Today we'll explore advanced Java programming concepts including Java features, detailed data types, variable naming rules, and all four operator types. This comprehensive foundation is essential for Selenium automation development.

Java Features

7 key characteristics

Data Types

Primitive vs Non-primitive

Variable Rules

Naming conventions

Operators

4 operator types

Java Programming Language

About Java

  • • Java Programming language was developed by Sun Microsystems in 1995, now part of Oracle company
  • • Java is an Object Oriented Programming Language - everything is objects
  • • Java is platform independent (execute on any machine or OS: Windows, Mac, Linux, Unix)
  • • Java is simple and easy to use
  • • Java is secure - develop virus-free applications

Java Applications

Desktop Applications

GUI applications

Web Applications

Server-side development

Mobile Applications

Android development

Games

Game development

Smart Cards

Embedded systems

Test Automation

Selenium testing

Java Syntax Rules

  • • Case Sensitive: Java is case sensitive language
  • • Class Name: First character should be upper case
  • • Method Name: Should start with lower case (camelCase)
  • • File Name: Must exactly match with class name
  • • Main Method: Mandatory for each Java class execution
  • • Semicolon: Every statement must end with semicolon (;)
  • • Braces: Every code block must be enclosed with

Java Data Types

Data Type Categories

Data types are used to store different values as per the datatype. There are 2 different categories:

1. Primitive Data Types

8 built-in data types

2. Non-Primitive Data Types

String, Arrays, Classes

Primitive Data Types (8 Types)

Integer Types

byte

Range: -128 to 127

byte a = 100;
short

Range: -32,768 to 32,767

short b = 1000;
int

Range: -2,147,483,648 to 2,147,483,647

int c = 100000;
long

Very large numbers (add 'l' or 'L')

long d = 12449494884l;

Decimal Types

float

Precision: 6 to 7 digits (add 'f' or 'F')

float m = 21434.45f;
double

Precision: Up to 15 digits

double n = 38377474.445555;

Other Types

boolean

Values: true or false

boolean k = true;
char

Single character (use single quotes)

char p = 'a';

Non-Primitive Data Types

String

Text and words

Arrays

Collection of elements

Classes

User-defined types

Variable Naming Rules

Valid vs Invalid Variable Names

✅ Valid Variable Names

abcABC_abc_ABC_abCDE$abc$ABCabc1233ABC1234

❌ Invalid Variable Names

1262abc

Cannot start with number

#abc

Cannot start with special characters (except _ and $)

Rules:
  • • Must start with letter, underscore (_), or dollar ($)
  • • Cannot start with numbers
  • • Cannot use Java keywords
  • • Case sensitive
  • • No spaces allowed

Java Operators

4 Types of Operators

1. Arithmetic

Math operations

2. Relational

Comparison

3. Logical

Boolean logic

4. Assignment

Value assignment

1. Arithmetic Operators

+Addition
-Subtraction
*Multiplication
/Division
%Modulo (Remainder)
++Increment
--Decrement
Arithmetic Example
int a = 10, b = 7;
System.out.println(a + b);  // 17
System.out.println(a - b);  // 3
System.out.println(a * b);  // 70
System.out.println(a / b);  // 1
System.out.println(a % b);  // 3
a++; System.out.println(a); // 11
b--; System.out.println(b); // 6

2. Relational Operators

Result criteria: Always returns boolean (true/false)

==Equal to
!=Not equal to
>Greater than
>=Greater than or equal to
<Less than
<=Less than or equal to
Relational Example
int a = 800, b = 1200;
System.out.println(a == b);  // false
System.out.println(a != b);  // true
System.out.println(a > b);   // false
System.out.println(a >= b);  // false
System.out.println(a < b);   // true
System.out.println(a <= b);  // true

4. Assignment Operators

=Assignment
+=Add and assign
-=Subtract and assign
*=Multiply and assign
Assignment Example
int a = 5;
System.out.println(a);    // 5
a = 40;                   // Re-assign
System.out.println(a);    // 40
a += 10;                  // a = a + 10
System.out.println(a);    // 50
a -= 15;                  // a = a - 15
System.out.println(a);    // 35
a /= 3;                   // a = a / 3
System.out.println(a);    // 11

Day 7 Knowledge Check

Question 1 of 5

Which company originally developed Java and in what year?

Key Takeaways

Java Features

  • Platform Independent: Run on any OS (Windows, Mac, Linux)
  • Object Oriented: Everything is objects
  • Secure: Virus-free application development
  • Applications: Desktop, Web, Mobile, Games, Test Automation

Data Types

  • Primitive (8): byte, short, int, long, float, double, boolean, char
  • Non-Primitive: String, Arrays, Classes
  • Suffixes: long (l/L), float (f/F)

Variable Naming Rules

  • Valid Start: Letter, underscore (_), dollar ($)
  • Invalid Start: Numbers, special chars (except _ $)
  • Case Sensitive: abc ≠ ABC
  • No Keywords: Cannot use Java reserved words

4 Operator Types

  • Arithmetic: +, -, *, /, %, ++, --
  • Relational: ==, !=, >, >=, <, <= (returns boolean)
  • Assignment: =, +=, -=, *=, /=
  • Logical: &&, ||, ! (covered in next class)

💡 These Java fundamentals form the core foundation for Selenium automation. Master these concepts as they're essential for writing effective test automation scripts.

SDET Mastery

Master Test Automation

Home
CurriculumPracticeQ&ACheatsheet
🍵Buy me a Chai

Automation Testing Course

Comprehensive course covering Manual Testing, Java Programming, and Selenium WebDriver

🍵Buy me a Chai
Privacy Policy•GitHub
© 2024 Automation Testing Course. All rights reserved.