Go Language for Java Developers Part 3
Part 3 of a 5 part series that explains the Go language to Java developers.
Join the DZone community and get the full member experience.
Join For FreeIn Java, we have primitive data types and objects. Java support 8 primitive data types:
Reference: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html
Data Type | Value |
---|---|
byte | 0 |
short | 0 |
int | 0 |
long | 0L |
float | 0.0f |
double | 0.0d |
char | '\u0000' |
boolean | false |
The Go language is a statically typed programming language. This means that variable always has specific type that can't be changed. The Go language data type can be divided in main three categories:
- Boolean: A boolean type represents the set of Boolean truth values denoted by the predeclared constants true and false. The predeclared boolean type is bool.
- Numeric: A numeric type represents sets of integer or floating-point values. The predeclared architecture-independent numeric types are: int, float32, float64, etc
- String: A string type represents the set of string values. A string value is a (possibly empty) sequence of bytes. Strings are immutable: once created, it is impossible to change the contents of a string. The predeclared string type is string.
Data Type | Default Value | Range |
---|---|---|
bool | false | true or false |
int | 0 | either int32 or int64 |
int8 | 0 | signed 16-bit integers (-32768 to 32767) |
int16 | 0 | signed 16-bit integers (-32768 to 32767) |
int32 | 0 | signed 32-bit integers (-2147483648 to 2147483647) |
int64 | 0 | signed 64-bit integers (-9223372036854775808 to 9223372036854775807) |
uint | 0 | either 32 or 64 bits |
uint8 | 0 | unsigned 8-bit integers (0 to 255) |
uint16 | 0 | unsigned 16-bit integers (0 to 65535) |
uint32 | 0 | unsigned 32-bit integers (0 to 4294967295) |
uint64 | 0 | unsigned 64-bit integers (0 to 18446744073709551615) |
float32 | 0 | IEEE-754 32-bit floating-point numbers |
float64 | 0 | IEEE-754 64-bit floating-point numbers |
string |
Reference: https://golang.org/ref/spec#Types
Next article we will learn about variables in the Go Language
More Reading
Data Types
Java (programming language)
Strings
32-bit
64-bit
Published at DZone with permission of Ketan Parmar, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Comments