Exercise 1: Create a class that contains an int field and a char field, none of which are initialized. Print their values to verify that Java performs the default initialization
Public classjavathinking {Private Static inti; Private Static CharC; Public Static voidMain (string[] args) {System.out.println (i); System.out.println (c); //the default value for char here is ' \u0000 ' to output thisSystem.out.println (c = = ' \u0000 ');//The result is true to prove that the default value of char is ' \u0000 ' }}
Operation Result:
0true Note: In Java, only member variables are assigned values, and there is no default value for local variables. The second line of output is blank because the code of the white space character is a control character that is not visible below 0x20,0x20
Exercise 2: In this example of Hellodate.java, create a "Hello,world" program that simply outputs the sentence. The class you are writing requires only one method (the "main" method). Executed when the program is started). Remember to set it to static and specify a list of parameters-even if the table is not used at all. Compile with Javac, and then run it in Java. If you're using a different development environment than the JDK, learn how to compile and run it in your environment
Public class javathinking { publicstaticvoid main (string[] args) { System.out.println ("Hello,world");} }
Exercise 3: Find the code snippet that contains the atypename, rewrite it as a complete program, and then compile, run
class atypename{ public atypename () { System.out.println ("full Atypename Code");} } Public class javathinking { publicstaticvoid main (string[] args) { New atypename (); }}
Exercise 4: Rewrite the dataonly code snippet into a program, and then compile, run
classdataonly{inti; DoubleD; Booleanb;} Public classjavathinking { Public Static voidMain (string[] args) {dataonly data=Newdataonly (); DATA.I= 47; DATA.D= 1.1; DATA.B=false; System.out.println (DATA.I); System.out.println (DATA.D); System.out.println (DATA.B); }}
Exercise 5: Modify the previous exercise to assign the data in the DataOnly to the main () method and print it
Answer reference Exercise Four
Exercise 6: Write a program that contains the code snippet for the storage () method defined in this chapter and call it.
Java Programming Ideas Fourth Edition Chapter two answers to the exercises