Conversion of Data Types conversion of various integer data types: Generally, we need to convert different data types. In addition to the boolean type, other data types can be automatically converted to other data types, as long as they follow the principle shown in: package com. ibm. third; publicclass NumberType {// The value of the boolean type belongs to the logical operation. The value can only be true/false publicstaticvoid main (String [] args) {// mutual conversion among various data types // Conversion Type: implicit conversion and display conversion // value type value range: double> float> long> int> short> byte // implicit conversion: convert a value of the type with a small value range to a value of the type with a large Value Range int i2 = 24; doubled = i2; byte b4 = 100; shorts7 = b4; // display conversion: convert a value of a type with a large value range to a type with a small value range. // If the conversion is large or small, data loss may occur. A forced type conversion is required. Double d5 = 12.5d; double d6 = 12.68d; double d7 =-12.68; // forced type conversion format: Target type target property = (target type) original type; int i8 = (int) d5; // convert the double type to an integer. int i9 = (int) d6; int i10 = (int) d7; System. out. println (i8); System. out. println (i9); System. out. println (i10); Object obj; String str = "100"; // Add the value of str to 100 inti11 = Integer. parseInt (str); // convert the string to our int type doubled11 = Double. parseDouble (str); // int --> Integer byte --> Byte // char --> Chara Cter boolean --> Boolean // short --> short long --> Long // double --> Double float --> Float // converts a char value to float char c9 = '9 '; float s9 = c9; System. out. println (s9); // first convert char --> int --> float // int f10 = (int) c9; // float f11 = f10; // System. out. println (f11); // char --> String --> int --> float String str1 = String. valueOf (c9); System. out. println (str1); inti01 = Integer. parseInt (str1); float f01 = Float. parseFloat (str1); System. out. println (f01); // reference type: Other types except basic data types: String ste8; Object obj8 ;}} Java reference type package com. ibm. third; publicclass Student {private Stringname; private int age; private Stringclassroom; public Student () {} public Student (String _ name, int _ age, String _ classroom) {name = _ name; age = _ age; classroom = _ classroom;} publicvoid setName (String _ name) {name = _ name;} public String getName () {r Eturnname;} publicvoid setAge (int _ age) {age = _ age;} publicint getAge () {returnage;} publicvoid setClassroom (String _ classroom) {classroom = _ classroom ;} public String getClassroom () {returnclassroom;} before using global variables and local variable v local variables, you must first initialize them. If the v global variable is used without initialization, the system automatically gives it a default initial value. Package com. ibm. third; publicclass ChangAttr {// member variable // defined in the class, the variable outside the method // defines a member variable can be used in all methods of the class (except for static methods) // you cannot directly use non-static public attributes in static methods. // you do not need to initialize variables when defining a member variable, if no value is specified, the default value is the initial value of the variable type. // The global variable inti = 200; String name; publicstaticvoid main (String [] args) is defined) {// define the local variable String name1 = null; System. out. println (name1); // System. out. println (name);} publicvoid show () {System. out. println (name );} // The local variable // The Position of the variable defined in the method is in the method body // The local variable must be initialized before being called // The local variable can only be in the current method, any other method cannot use the value} to pass package com. ibm. third; publicclass ResultTrans {// pass publicstaticvoid main (String [] args) {String str = "java_lu"; System. out. println ("----------" + str); ResultTrans rt = new ResultTrans (); rt. show (str); System. out. println ("===========" + str); str = rt. show2 (str); System. out. println ("++" + str);} publicvoid show (String str) {str = "ibm"; System. out. println (str);} public String show2 (String str) {str = "ibm"; System. out. println (str); return str ;}} object to pass package com. ibm. third; publicclass ShowObject {publicstaticvoid main (String [] args) {Student st = null; // declare a reference to a Student class Object Student st5 = null; // System. out. println (st); // st is just a reference variable and there is no specific object for creating the Student class, so st is null // if the object's attribute value is retrieved from the null object, a null pointer exception is reported. // System. out. println (st. getName (); // create object st = new Student (); System. out. println (st); System. out. println (st. getName (); Student st2 = st; Student st3 = new Student (); st5 = st3; System. out. println (st2); System. out. println (st3); System. out. println (st5) ;}} example of object and value transfer package com. ibm. third; publicclass Test {publicstaticvoid main (String [] args) {Student st = new Student (); st. setName ("Zhang San"); st. setAge (18); st. setClassroom ("javalu"); System. out. println (st); Test tt = new Test (); tt. show (st); System. out. println (st. getName ();} publicvoid show (Student st) {// The st object created in main is passed to show, so it is an object to pass // a newly created object. Although the object is the same as st, it is not the same object st = new Student ("LITH", 20, "Daqin Dynasty "); system. out. println (st. getName ());}}