Java
 Computer >> コンピューター >  >> プログラミング >> Java

例を含むJavaのバイトクラスフィールド


Byteクラスは、プリミティブ型のバイトの値をオブジェクトにラップします。

以下はバイトクラスのフィールドです-

  • 静的バイトMAX_VALUE −これは、バイトが持つことができる最大値27-1を保持する定数です。
  • 静的バイトMIN_VALUE −これは、バイトが持つことができる最小値-27を保持する定数です。
  • static int SIZE −これは、2の補数のバイナリ形式でバイト値を表すために使用されるビット数です。
  • 静的クラス<バイト>タイプ −これはプリミティブ型のバイトを表すClassインスタンスです。

例を見てみましょう-

import java.lang.*;
public class Demo {
   public static void main(String[] args){
      Byte b1, b2;
      int i1, i2;
      b1 = new Byte("1");
      b2 = Byte.MIN_VALUE;
      i1 = b1.intValue();
      i2 = b2.intValue();
      String str1 = "int value of Byte " + b1 + " is " + i1;
      String str2 = "int value of Byte " + b2 + " is " + i2;
      System.out.println( str1 );
      System.out.println( str2 );
   }
}

出力

これにより、次の出力が生成されます-

int value of Byte 1 is 1
int value of Byte -128 is -128

別の例を見てみましょう-

import java.lang.*;
public class Demo {
   public static void main(String[] args){
      Byte b1, b2;
      String s1, s2;
      b1 = new Byte("-10");
      b2 = Byte.MIN_VALUE;
      System.out.println("Number of bits in b1 = "+b1.SIZE );
      System.out.println("Number of bits in b2 = "+b2.SIZE );
      s1 = b1.toString();
      s2 = b2.toString();
      String str1 = "String value of Byte " + b1 + " is " + s1;
      String str2 = "String value of Byte " + b2 + " is " + s2;
      System.out.println( str1 );
      System.out.println( str2 );
   }
}

出力

これにより、次の出力が生成されます-

Number of bits in b1 = 8
Number of bits in b2 = 8
String value of Byte -10 is -10
String value of Byte -128 is -128

  1. 例を含むJavaの静的ブロック

    静的ブロックは、クラスローダーがクラスをロードするときに実行されます。 main()メソッドの前に静的ブロックが呼び出されます。例を見てみましょう- 例 class Demo{    static int val_1;    int val_2;    static{       val_1 = 67;       System.out.println("The static block has been called.");    }

  2. Eclipseを使用したJavaFX。

    eclipseでJavaFxをセットアップするには、まず、システムにeclipseとJavaが正常にインストールされていることを確認してください。 Mavenの依存関係 Maven依存関係を使用してJavaFX環境をセットアップするには、EclipseでJavaプロジェクトを作成し、以下に示すようにMavenプロジェクトに変換します- 次にpom.xm lファイルは次のJavaFX依存関係を追加し、プロジェクトを更新します。 <dependency>    <groupId>org.openjfx</groupId>