Java Data Types

Java Data Types 


1. Primitive Data Types (8 Types)

These store simple values, not objects.


a. byte – ๐Ÿงฎ Small whole number

  • Size: 1 byte
  • Range: -128 to 127
  • Declaration:
    byte retryCount = 3;
    

b. short – ๐Ÿ“ฆ Medium-range whole number

  • Size: 2 bytes
  • Range: -32,768 to 32,767
  • Declaration:
    short sessionTime = 1200;
    

c. int – ๐Ÿ”ข Common whole number type

  • Size: 4 bytes
  • Range: Large range
  • Declaration:
    int totalTests = 500;
    

d. long – ๐Ÿ—ƒ️ Very large whole numbers

  • Size: 8 bytes
  • Must end with L
  • Declaration:
    long executionId = 12345678900L;
    

e. float – ๐ŸŒŠ Decimal number (less precise)

  • Size: 4 bytes
  • Must end with f
  • Declaration:
    float loadTime = 3.45f;
    

f. double – ๐ŸŒ Decimal number (more precise)

  • Size: 8 bytes
  • Declaration:
    double responseTime = 125.789;
    

g. char – ๐Ÿ”ค Single character

  • Size: 2 bytes
  • Declaration:
    char status = 'P';  // 'P' for Pass
    

h. boolean – ⚙️ True or False

  • Size: 1 bit
  • Declaration:
    boolean isTestPassed = true;
    

2. Non-Primitive (Reference) Data Types

These refer to objects and more complex structures.


a. String – ✉️ Sequence of characters

  • Declaration:
    String browser = "Chrome";
    

b. Array – ๐Ÿ“š Collection of values

  • Declaration:
    int[] testCaseIds = {101, 102, 103};
    String[] browsers = {"Chrome", "Firefox", "Edge"};
    

c. Class & Object – ๐Ÿงฑ Custom types

  • Declaration:
    class TestCase {
        String name;
        boolean isPassed;
    }
    
    TestCase tc1 = new TestCase();
    tc1.name = "Login Test";
    tc1.isPassed = true;
    

Bonus Tip for QA Automation

Use:

  • boolean for assertion flags
  • int for counts like number of tests
  • String for test data and messages
  • double for performance metrics
  • Arrays or Lists for data-driven testing

Would you like this as a cheat sheet PDF or infographic?

Comments

Popular posts from this blog

10 automation test cases for https://www.saucedemo.com/ (Sauce Demo)

Java Roadmap for SDET Superstars!

Mastering XPath in Selenium 4 ๐Ÿš€ – Supported Functions & Axes Explained