Navigate

JavaScript Tutorial for Beginners

The Ultimate CSS Tutorial for Beginners

Data Structure Tutorial for Beginners

ReactJS Tutorial for Beginners

Node.js Tutorial for Beginners

SQL Tutorial for Beginners

Variables, Data Types, and Operators

Content

  • Variables in Java
  • Data Types
  • Operators
  • Example
  • Activity
  • Updated on 10/09/2024
  • 450 Views

Variables in Java

Variables are used to store data that can be used and manipulated throughout your program. Declaration syntax: dataType variableName = value;

Data Types

Primitive Data Types:

  • int, float, double, char, boolean, etc.

  • Non-Primitive Data Types:

  • Strings, arrays, classes, etc.

Operators

  • Arithmetic Operators:
  • +, -, *, /, %

  • Relational Operators:
  • ==, !=, >, <, >=, <=

  • Logical Operators:
  • &&, ||, !

Example

  • Example of using variables, data types, and operators in Java.

Activity

  • Create a Java program that declares variables of different types and prints their values.

Quiz

1. Which data type is used to store integer values in Java?

  • a) int
  • b) double
  • c) char
  • d) boolean

2. How do you declare a variable in Java?

  • a) variableName dataType = value;
  • b) dataType = variableName value;
  • c) dataType variableName = value;
  • d) value dataType = variableName;

3. Which operator is used for addition in Java?

  • a) -
  • b) *
  • c) /
  • d) +

4. What is the default value of a boolean variable?

  • a) 0
  • b) 1
  • c) false
  • d) true

5. What will be the output of the following code?

  • a) 5
  • b) 10
  • c) 15
  • d) 510

© 2025 LEJHRO. All Rights Reserved.