#1 India's Top IT Training Institute
×

About Uncodemy

Know more about who we are and what we stand for.

About Us

About Us

Discover our mission to equip individuals with essential IT skills and industry expertise.

Read More →
UnCodeMy Gallery

UnCodeMy Gallery

Explore highlights from our IT training sessions and success stories.

Read More →
Mentors

Mentors

Meet the industry experts who train and guide you through your course.

Read More →
Free Resources

Free Resources

Free tutorials, interview questions, tools and calculators to help you learn.

Explore →
×

Free Resources

Learn, practice and plan your career — bilkul free.

Tutorials

Tutorials

Step-by-step written tutorials to learn any technology at your own pace.

Read More →
Free Counselling

Free Counselling

Book a free video counselling session and pick the right course for you.

Read More →
Online Compiler

Online Compiler

Write, run and test your code online — no setup required.

Read More →
Core Java

Java Data Types

Primitive Data Types

  • int: whole numbers (e.g., 42)
  • double / float: decimal numbers
  • boolean: true or false
  • char: a single character
  • long, short, byte: other integer sizes for specific memory needs

Reference (Non-Primitive) Data Types

Includes String, Arrays, and Objects — these store references to data rather than the raw value itself, and can be null.

Why Testers Should Know This

Understanding data types is essential when writing Rest Assured assertions, since a response field's actual data type (e.g., a number vs a string) must match what the assertion expects.

Sizes, Ranges and Default Values

Every primitive type in Java has a fixed size on every platform, which keeps behaviour predictable.

TypeSizeRange or valuesDefault (as a field)
byte8 bits-128 to 1270
short16 bits-32,768 to 32,7670
int32 bitsabout -2.1 billion to 2.1 billion0
long64 bitsvery large whole numbers0L
float32 bitsabout 6 to 7 significant digits0.0f
double64 bitsabout 15 to 16 significant digits0.0
char16 bitsa single UTF-16 code unit'\u0000'
booleanJVM-dependenttrue or falsefalse

Defaults apply only to class fields. Local variables inside a method have no default and must be assigned before use, or the code will not compile.

Wrapper Classes and the == Trap

Collections and many libraries work with objects, so Java wraps primitives in classes like Integer, Double and Boolean. Conversion happens automatically, called autoboxing. The danger is comparing wrapper objects with ==, which checks whether two references point to the same object, not whether the values match.

Integer a = 100, b = 100;
Integer c = 1000, d = 1000;
System.out.println(a == b);        // true  (small values are cached)
System.out.println(c == d);        // false (different objects)
System.out.println(c.equals(d));   // true  (compares values)

String s1 = "pass";
String s2 = new String("pass");
System.out.println(s1 == s2);      // false
System.out.println(s1.equals(s2)); // true

In test code, always use equals() or your assertion library for objects and strings. A check that passes for small numbers and fails for large ones is very confusing to debug.

Matching Types in Rest Assured Assertions

Suppose an API returns {"id": 101, "name": "Asha", "active": true, "balance": 2500.75}. Each matcher must use the type Rest Assured produces when it parses the JSON.

given()
    .baseUri("https://api.example.com")
.when()
    .get("/users/101")
.then()
    .statusCode(200)
    .body("id", equalTo(101))           // int, not "101"
    .body("name", equalTo("Asha"))      // String
    .body("active", equalTo(true))      // boolean, not "true"
    .body("balance", equalTo(2500.75f)); // float by default!

By default, Rest Assured's JsonPath reads decimal numbers as float, so equalTo(2500.75), which is a double, fails even though the numbers look the same. Either add the f suffix or configure JsonPath to return double or BigDecimal. Whole numbers too large for int come back as long, so a matcher like equalTo(9876543210L) is needed for big IDs.

Checklist for Testers

  • Use long for timestamps in milliseconds and large IDs.
  • Avoid float and double for money; prefer BigDecimal for exact comparisons.
  • Compare strings and wrappers with equals(), never ==.
  • Check that a null field is really null and not the string "null".
  • When an assertion fails with matching-looking values, suspect a type mismatch first.

Ready to master real-world software testing?

Learn manual and automation testing hands-on with mentor-led sessions.

Explore Course