Search
  • +44-7459919437 (UK- WhatsApp & Direct Call) | +91-6383544892 (India - WhatsApp Only) | Email Id : vinothrwins@gmail.com
Vinoth Q.A Academy
  • Home
  • Selenium Java Online Training
  • Self Paced Video Course
    • Selenium Course Curriculum
    • Cypress Course Curriculum
    • Playwright Course Curriculum
  • Tutorials
  • Demo Sites
    • Practice Automation
      • Demo Page Healthcare
      • Registration Form
      • Transaction Details
      • DropDown
      • Mouse Event
      • Keyboard Events
      • Alert and Popup
      • Multiple Windows
      • iFrames
      • Wait WebElement
      • WebTable
  • FAQS
  • About Me & Feedback
    • Placed Students Feedback
    • Online Training Feedback
    • LinkedIn Profile
    • TechTalk
  • Free YouTube Courses
    • Python for Automation
    • Free QA Video Courses
      • Manual Testing
      • Java For Automation
      • Selenium Webdriver
      • TestNG
      • Cucumber BDD
      • UFT(QTP) Automation
    • Free Data Science Courses
      • Artificial Intelligence for Beginners
      • Python For A.I
      • Python Pandas
      • Python NumPy
      • Mathematics for A.I
  • Home
  • Selenium Java Online Training
  • Self Paced Video Course
    • Selenium Course Curriculum
    • Cypress Course Curriculum
    • Playwright Course Curriculum
  • Tutorials
  • Demo Sites
    • Practice Automation
      • Demo Page Healthcare
      • Registration Form
      • Transaction Details
      • DropDown
      • Mouse Event
      • Keyboard Events
      • Alert and Popup
      • Multiple Windows
      • iFrames
      • Wait WebElement
      • WebTable
  • FAQS
  • About Me & Feedback
    • Placed Students Feedback
    • Online Training Feedback
    • LinkedIn Profile
    • TechTalk
  • Free YouTube Courses
    • Python for Automation
    • Free QA Video Courses
      • Manual Testing
      • Java For Automation
      • Selenium Webdriver
      • TestNG
      • Cucumber BDD
      • UFT(QTP) Automation
    • Free Data Science Courses
      • Artificial Intelligence for Beginners
      • Python For A.I
      • Python Pandas
      • Python NumPy
      • Mathematics for A.I

Java

  • What is Java?
  • Why to Learn Java?
  • History of Java
  • Types of Java Applications
  • Naming Conventions
  • Hello World Program
  • Internal Details of Java program
  • What is Java JDK, JRE and JVM ?
  • What is Java Comments ?
  • What is Java Variable?
  • Variable Naming convention
  • Primitive Data Types
  • Non Primitive Data Types
  • Type Casting
  • Java Arithmetic Operators
  • Relational Operators
  • What is logical operators in Java? 
  • What is Assignment Operators in Java? 
  • What is Unary Operators in Java? 
  • What is Ternary Operators in Java?
  • What is Java Control Statements?
  • What are Decision Making statements?
  • What are looping statements?
  • What are Jump statements?
  • What is OOPS concept in Java?
  • Advantages of Java OOPs
  • What is Java Inheritance?
  • What is Java Constructor?
  • What is this keyword?
  • What is Polymorphism?
  • What is super keyword ?
  • What is final keyword? 
  • What are access modifiers?
  • What is Encapsulation? 
  • What is Abstraction? 
View Categories
  • Home
  • Tutorials
  • Java
  • Java
  • Non Primitive Data Types

Non Primitive Data Types

Non Primitive Data Types

Non-primitive data types in Java are more complex than primitive data types. They include classes, interfaces, arrays, and enums. Non-primitive data types are also known as reference types because they refer to objects.

1. String #

A String is an object that represents a sequence of characters. It is part of the java.lang package.

Example:

public class Main {

    public static void main(String[] args) {

        String greeting = "Hello, World!";

        System.out.println(greeting);  // Output: Hello, World!

    }

}

2. Arrays #

An array is a container object that holds a fixed number of values of a single type. The length of an array is established when the array is created.

Example:

public class Main {

    public static void main(String[] args) {

        int[] numbers = {1, 2, 3, 4, 5};

        for (int num : numbers) {

            System.out.print(num + " ");  // Output: 1 2 3 4 5

        }

    }

}

3. Classes #

A class is a blueprint for creating objects. It can contain fields (variables) and methods to define its behavior.

Example:

public class Main {

    public static void main(String[] args) {

        Person person = new Person("Alice", 30);

        person.displayInfo();  // Output: Name: Alice, Age: 30

    }

}

class Person {

    String name;

    int age;

    Person(String name, int age) {

        this.name = name;

        this.age = age;

    }

    void displayInfo() {

        System.out.println("Name: " + name + ", Age: " + age);

    }

}

4. Interfaces #

An interface is a reference type, similar to a class, that can contain only constants, method signatures, default methods, static methods, and nested types. Interfaces cannot contain instance fields or constructors.

public class Main {

    public static void main(String[] args) {

        Dog dog = new Dog();

        dog.makeSound();  // Output: Bark

    }

}

interface Animal {

    void makeSound();

}

class Dog implements Animal {

    public void makeSound() {

        System.out.println("Bark");

    }

}

5. Enums #

An enum (short for enumeration) is a special data type that enables a variable to be a set of predefined constants. The variable must be equal to one of the values that have been predefined for it.

public class Main {

    public static void main(String[] args) {

        Day day = Day.MONDAY;

        System.out.println(day);  // Output: MONDAY

    }

}

enum Day {

    SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY

}

Summary

  • String: Represents a sequence of characters.
  • Arrays: Container objects that hold a fixed number of values of a single type.
  • Classes: Blueprints for creating objects, containing fields and methods.
  • Interfaces: Define methods that must be implemented by classes.
  • Enums: Special data types that enable variables to be a set of predefined constants.

Each of these non-primitive data types provides a way to create complex data structures and objects that can be manipulated within your Java programs.

Java
What are your Feelings
Share This Article :
  • Facebook
  • X
  • LinkedIn
Primitive Data TypesType Casting
Table of Contents
  • 1. String
  • 2. Arrays
  • 3. Classes
  • 4. Interfaces
  • 5. Enums
© Copyright [2018-2025]. All Rights Reserved.