Lädt...

🔧 Day-13: Data Types in Java - Class-Specific and Object-Specific Data Types


Nachrichtenbereich: 🔧 Programmierung
🔗 Quelle: dev.to

1). Primitive Data Types:
The Java programming language is statically-typed, which means that all variables must first be declared before they can be used.

example: int grear = 1;

A primitive type is predefined by the language and is named by a reserved keyword.
Like int, byte, char,...

Primitive values do not share state with other primitive values.
Example: int grear = 1;
boolean grear_bike = true;
int total_output = grear + grear_bike
This is not possible.

byte: The byte data type is an 8-bit signed two's complement integer.

  • 128 to 127. The byte data type can be useful for saving memory in large arrays.

short: The short data type is a 16-bit signed two's complement integer. It has a minimum value of -32,768 and a maximum value of 32,767 (inclusive). As with byte, the same guidelines apply .

int: By default, the int data type is a 32-bit signed two's complement integer, which has a minimum value of -231 and a maximum value of 231-1. In Java SE 8 and later, you can use the int data type to represent an unsigned 32-bit integer.

long: The long data type is a 64-bit two's complement integer. The signed long has a minimum value of -263 and a maximum value of 263-1. In Java SE 8 and later, you can use the long data type to represent an unsigned 64-bit long, which has a minimum value of 0 and a maximum value of 264-1.

float: The float data type is a single-precision 32-bit IEEE 754 floating point. Its range of values is beyond the scope of this discussion, but is specified in the Floating-Point Types, Formats, and Values section of the Java Language Specification.

double: The double data type is a double-precision 64-bit IEEE 754 floating point.

boolean: The boolean data type has only two possible values: true and false. Use this data type for simple flags that track true/false conditions. This data type represents one bit of information, but its "size" isn't something that's precisely defined.

char: The char data type is a single 16-bit Unicode character. It has a minimum value of '\u0000' (or 0) and a maximum value of '\uffff' (or 65,535 inclusive).

2). Non-Primitive Data Types:
the Java programming language also provides special support for character strings via the java.lang.String class. Enclosing your character string within double quotes will automatically create a new String object; for example, String s = "this is a string";. String objects are immutable, which means that once created, their values cannot be changed. The String class is not technically a primitive data type, but considering the special support given to it by the language, you'll probably tend to think of it as such.

Default Values:
The following chart summarizes the default values for the above data types.
Data Type Default Value (for fields)
byte 0
short 0
int 0
long 0L
float 0.0f
double 0.0d
char '\u0000'
String (or any object) null
boolean false

Datatypes also classified Class and Object Specific:

static String headquarters; - class specific
String bike_colour; - Object specific

public class Honda {

    static String headquarters;  // static variable shared by all instances / class level
    String bike_colour;         // object-specific variable / object level 

    public static void main(String[] args){
        Honda activa = new Honda(); 

        Honda.headquarters = "Japan";  // setting the static variable 
        activa.bike_colour = "Blue";   // setting the instance variable 

        System.out.println("Honda headquarters located at: " + Honda.headquarters);
        System.out.println("Honda bike colour is: " + activa.bike_colour);
    }
}

Output Like this.

Image description

Ref Doc : https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html

-------------------- End of the Blog -----------------------------

...

🔧 Mastering Object.freeze() and Object.seal() in JavaScript: Controlling Object Mutability


📈 26.98 Punkte
🔧 Programmierung

🔧 Why JavaScript Says "[object Object]" and Not Just "[object]" 🤔


📈 26.98 Punkte
🔧 Programmierung

🔧 A detailed analysis of Java Object size and its comparision with primitive data types.


📈 25.64 Punkte
🔧 Programmierung

🔧 JS Object.assign(), Object.create(). Object.defineProperties() Methods.


📈 25.62 Punkte
🔧 Programmierung

🕵️ CVE-2022-44108 | pdftojson 94204bb Object.cc Object::copy(Object*) stack-based overflow


📈 25.62 Punkte
🕵️ Sicherheitslücken

🔧 C# Tip: Use var for Obvious Types, but Prefer Explicit Types for Ambiguous Types


📈 23.94 Punkte
🔧 Programmierung

🔧 Exploring Non-Primitive Types in Java: A Dive into Object-Oriented Programming


📈 22.25 Punkte
🔧 Programmierung

🔧 day-12: A Comprehensive Guide to Java Objects, Data Types, and Variable Initialization


📈 21.27 Punkte
🔧 Programmierung

🔧 Learning AWS Day by Day — Day 54 — Amazon SQS queue types


📈 20.51 Punkte
🔧 Programmierung

🔧 Python Day - 30 Types of Arguments, Types of variables


📈 20.14 Punkte
🔧 Programmierung

🕵️ Cisco Security Manager Java Deserialization Serialized Java Object privilege escalation


📈 20.01 Punkte
🕵️ Sicherheitslücken

🕵️ SAP NetWeaver AS JAVA 7.5 EP-RUNTIME Serialized Java Object denial of service


📈 20.01 Punkte
🕵️ Sicherheitslücken

🕵️ SAP NetWeaver AS JAVA 7.5 EP-RUNTIME Serialized Java Object Denial of Service


📈 20.01 Punkte
🕵️ Sicherheitslücken

📰 Data Types: 7 Key Data Types


📈 20.01 Punkte
📰 IT Nachrichten

🔧 Day 5 java Data types :


📈 19.91 Punkte
🔧 Programmierung

🔧 Day - 2:Revisiting Java Script Basics-Data Types , functions , scope


📈 19.91 Punkte
🔧 Programmierung

🔧 Understanding Strings, Object Memory, Static vs. Non-Static, and 'this' Keyword in Java Day 7 ...


📈 19.81 Punkte
🔧 Programmierung

🔧 Java 8 vs Java 11 vs Java 17 Comparison and Key Features


📈 18.56 Punkte
🔧 Programmierung

🔧 What is Java Used For in 2023? The Java Programming Language and Java Platform Strengths


📈 18.56 Punkte
🔧 Programmierung

📰 Java-Stager - A PoC Java Stager Which Can Download, Compile, And Execute A Java File In Memory


📈 18.56 Punkte
📰 IT Security Nachrichten

🔧 DAY 5 In Java create an object,


📈 18.45 Punkte
🔧 Programmierung

🔧 Exploring the Key Differences between Object Localization and Object Detection


📈 18.44 Punkte
🔧 Programmierung

🔧 Differences Between Object, {}, and object in TypeScript


📈 18.44 Punkte
🔧 Programmierung

🔧 The Differences Between 'Object', '{}', and 'object' in TypeScript


📈 18.44 Punkte
🔧 Programmierung

🔧 Understanding and Fixing "Object Reference Not Set to an Instance of an Object" in C#


📈 18.44 Punkte
🔧 Programmierung

🔧 Constants, Object.freeze, Object.seal and Immutable in JavaScript


📈 18.44 Punkte
🔧 Programmierung

🔧 How to Use CSS object-fit and object-position


📈 18.44 Punkte
🔧 Programmierung

🔧 day-24: Java Inheritance Explained: Types, Usage & Examples


📈 17.89 Punkte
🔧 Programmierung