[Introduction to Java] Variable declarations and types

I'm a fledgling programmer for the first year. This is a collection of personal notes that have been organized and published for review purposes. Please note that there is a high possibility that you are wrong.

Variable declaration

int number;     //Declare variable number of type int
String str;     //Declare a variable str of type String
int[] list;     //Declaration of array list of int type
ArrayList<String> arrList;     // ArrayList<String>Declare the variable arrList of the class

--Declare in the order of type variables

Initialization / instantiation

int number = 27;     //Variable initialization (assigning a value for the first time)
String str = "hello";     //String type initialization, string""Enclose with (double quotation marks)
int[] list = new int[3]     //Creating an array
List<String> arrList = new ArrayList<String>();     //Instantiation of ArrayList class

--If not initialized, the initial value is set to 0 for numeric types such as int and double, false for boolean type, and null for reference type. --Learn later what the instance is

Declaration of constants

final int NUMBER = 5;

--If final is added, it becomes a constant and an error occurs when trying to assign a value. --By convention, constants are often capitalized.

Type of type

    1. Primitive type: 8 types
Primitive type Contents size range
long Large number 64bit -9223372036854775808 ~ 9223372036854775807
int Normal number 32bit -2147483648 ~ 2147483647
shot Small number 16bit -32768 ~ 32767
byte Very small number 8bit -128 ~ 127
double Decimal 64bit about(-)3.40282347E+38(about6~7桁の精度)
float Decimal numbers with relatively low precision 32bit (-)1.79769313486231570E+388 (15-digit precision)
boolean True or false 16bit true or false
char 1 Unicode character 1bit \u0000 ~ \uFFFF
  1. Reference type (reference type): Class

--Typical example is String class, reference type if not primitive type

reference) About Java Primitive Types and Reference Types


System.out.print((int)3.2);     //The result is 3

--Forcibly perform type conversion by explicitly performing type conversion --It seems that it is not used much because data is lost.

Type conversion between character string and number

--String → Numerical value



--Numeric value → character string




I wrote a lot, but I thought it would be better to see Java Road. So let's look at this (round throw).

-Variable -Basic type conversion and cast

Recommended Posts

[Introduction to Java] Variable declarations and types
[Introduction to Java] Variables and types (variable declaration, initialization, data type)
Java variable declaration, initialization, and types
Introduction to java
Introduction to java command
[Java] Variables and types
[Java] Types of comments and how to write them
[Java] Introduction to lambda expressions
[Java] Introduction to Stream API
[Introduction to Java] Variable scope (scope, local variables, instance variables, static variables)
[Introduction to rock-paper-scissors games] Java
Introduction to Effective java by practicing and learning (Builder pattern)
[Introduction to Java] About lambda expressions
[Java] Basic types and instruction notes
Java Primer Series (Variables and Types)
[Introduction to Java] About Stream API
Basic data types and reference types (Java)
Introduction to Functional Programming (Java, Javascript)
Assign evaluation result to Java variable
About Java primitive types and reference types
Java basic data types and reference types
[Java] Exception types and basic processing
Basics of Java development ~ How to write programs (variables and types) ~
Introduction to Scala from a Java perspective, decompiled and understood (basic)
Java starting from beginner, variables and types
Introduction to java for the first time # 2
[Introduction to Java] How to write a Java program
Java implementation to create and solve mazes
[Java] How to output and write files!
Introduction to EHRbase 1-Overview and Environmental Improvement
Output of the book "Introduction to Java"
Introduction to monitoring from Java Touching Prometheus
Java to C and C to Java in Android Studio
Introduction to Java Web Apps Performance Troubleshooting
Introduction to algorithms with java --Search (breadth-first search)
Introduction to Scala from a Java perspective (Class-Tuple edition) to decompile and understand
[Introduction to Java] About array operations (1D array, 2D array declaration, instantiation, initialization and use)
Introduction to Ruby 2
[Introduction to Java Data Structures] Create your own fast ArrayDeque for primitive types
[Java] How to use FileReader class and BufferedReader class
java array variable
[Introduction to Java] About type conversion (cast, promotion)
Introduction to algorithms with java --Search (bit full search)
[Java] How to get and output standard input
About Java data types (especially primitive types) and literals
Introduction to SWING
Try to link Ruby and Java with Dapr
Java upload and download notes to Azure storage
[Monthly 2017/04] Introduction to groovy !! ~ Java grammar / specification comparison ~
[Ruby] "Reference to object" and "Contents of variable"
Java variable scope (scope)
java variable declaration
Introduction to Micronaut 1 ~ Introduction ~
Java variable scope
Java and JavaScript
Introduction to migration
How to get and study java SE8 Gold
Introduction to Apache Beam (1) ~ Reading and writing text ~
[Java] Difference between "final variable" and "immutable object"
Introduction to Doma
An introduction to Groovy for tedious Java engineers