Curriculum
Course: Java Basic
Login

Curriculum

Java Basic

Java Home

0/1

Java Introduction

0/1

Java Get Started

0/1

Java Syntax

0/1

Java Comments

0/1

Java Type Casting

0/1

Java Operators

0/1

Java Booleans

0/1

Java Switch

0/1

Java Break / Continue

0/1

Java Errors and Exception

0/1
Text lesson

Print Variables

Display Variables

Using the println() method is a common practice for showing variables.

To blend text with a variable, employ the + character:

Example

String name = "John";
System.out.println("Hello " + name);

Additionally, you can utilize the + character to concatenate one variable with another variable:

Example

String firstName = "John ";
String lastName = "Doe";
String fullName = firstName + lastName;
System.out.println(fullName);

When dealing with numeric values, the + character functions as a mathematical operator. (Note the usage of int variables for integers here):

Example

int x = 5;
int y = 6;
System.out.println(x + y); // Print the value of x + y

Based on the example provided, you can anticipate

  • x holds the value 5
  • y holds the value 6
  • Subsequently, we employ the println() method to exhibit the value obtained by adding x and y, resulting in 11.