AgerNic.com
WEB DEVELOPER SITE, HTML, CSS, PHP, SQL

Java Variable


Java Tutorial » Java Variable


Variables are containers for storing data values.

In Java, we have different types of variables, example:

String - stores text, as "JavaTutorial" with double quotes
int - stores integers as 457 or -457 (whole numbers), without decimals,
float - stores floating point numbers, with decimals, as 27.98 or -27.98
char - stores single characters, as 'e' or 'E' with single quotes
boolean - stores values as: true or false

Ccreating a variable, must specify the type and assign it a value:

Syntax:
Example:
type variable = value;


Create a variable type string


Create a variable type string and assign it the value "Langford":

Example:
String my_name = "Langford";
System.out.println(my_name);

All java program:
public class Main {
  public static void main(String[] args) {
    String my_name = "Langford";
    System.out.println(my_name);
  }
}

Output: Langford




Variable what store a number

Create a variable what store a number, example:

Example: Create a variable named my_Number of type int assign value 52:
int my_Number = 52;
System.out.println(my_Number);

Entire Java program:
public class Main {
  public static void main(String[] args) {
    int my_Number = 52;
    System.out.println(my_Number);
  }
}


Other Types of Variables


How to declare variables of other types, example:

Example: Create other variables type:
int my_Number = 27;
float my_Float_Number = 34.98f;
char my_Letter = 'E';
boolean my_Bool = false;
String my_Text = "Tutorial";





java variable type, variables, might not have been initialized, variables de entorno, globales, final, string, static, de clase, estatica
Java Variable - java

Online Editor
ONLINE EDITOR

news templates


COLOR PICKER

news templates
This tool makes it easy to create, adjust, and experiment with custom colors for the web.


HTML Templates
news templates
Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.


CSS HTML Layout
news templates
Find here examples of creative and unique website layouts.


Free CSS HTML Menu
news templates
Find here examples of creative and unique website CSS HTML menu.


0
Online Editor
ONLINE EDITOR

news templates


COLOR PICKER

news templates
This tool makes it easy to create, adjust, and experiment with custom colors for the web.


HTML Templates
news templates
Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.


CSS HTML Layout
news templates
Find here examples of creative and unique website layouts.


Free CSS HTML Menu
news templates
Find here examples of creative and unique website CSS HTML menu.


CSS background color - opacity, gradient...
CSS flex - display: flex - CSS Flexbox L...
CSS border padding...
HTML text center horizontally and vertic...
HTML text input <input type="text"&g...
HTML link color...
How to Link CSS to HTML, external file n...
HTML link - hyperlink...
jQuery replace...
jQuery replaceClass...
jQuery click ()...
jQuery switchClass()...
jQuery draggable()...
jQuery HTML...
jQuery scroll smooth...
jQuery scroll()...
jQuery stop()...
jQuery animate()...
jQuery SlideToggle()...
jQuery slideDown()...