<< Chapter < Page | Chapter >> Page > |
The name of the primitive type begins with a lower-case letter and the name of the wrapper type begins with an upper-case letter such as double and Double . Note that in some cases, however, that they are not spelled the same. For example, the Integer class is the wrapper for type int .
Wrapper classes
This has some ramifications as to how variables can be used (passing to methods, returning from methods, etc.) . For example, all variables of primitive types are passed by value to methods meaning that the code in the method only has access to a copy of the variable and does not have the abilityto modify the variable.
False. Primitive data types in Java (int, double, etc.) are not true objects.
True.
False. The char type in Java is a 16-bit Unicode character.
Primitive types contain a single value.
Java supports both primitive types and reference (or object) types.
In Java, a variable of a specified type is represented exactly the same way regardless of the platform on which the application or applet is being executed.
False. In Java, all variables of type int contain signed values.
All variables in Java must have a defined type . The definition of the type determines the set of values that can be stored in the variable and theoperations that can be performed on the variable.
The syntax is shown in boldface below:
public static void main( String[] args )
In this case, the type of variable declared is an array of type String named args (type String[]) . The purpose of the String array variable in the argument list is to make it possible to capture arguments entered on the commandline.
False. Fortunately, Java provides very strict type checking and generally refuses to compile statements with type mismatches.
int firstVariable, secondVariable = 10;
False: In Java, it is possible to initialize the value of a variable when it is declared, but initialization is not required. (Note however that in some situations, the usage of the variable may require that it be purposely initialized.) .
To use a variable, you must notify the compiler of the name and the type of the variable (declare the variable).
variable
Listing 2 . Listing for Answer 1. |
---|
/*File simple4.java
This application reads characters from the keyboard untilencountering the # character and echoes each character to
the screen. The program terminates when the user entersthe # character.
**********************************************************/class simple4 { //define the controlling class
public static void main(String[]args)
throws java.io.IOException {int ch1 = 0;
System.out.println("Enter some text, terminate with #");
while( (ch1 = System.in.read() ) != '#')System.out.print((char)ch1);
System.out.println("Goodbye");}//end main
}//End simple4 class. |
This section contains a variety of miscellaneous information.
Financial : Although the Connexions site makes it possible for you to download aPDF file for this module at no charge, and also makes it possible for you to purchase a pre-printed version of the PDF file, youshould be aware that some of the HTML elements in this module may not translate well into PDF.
I also want you to know that, I receive no financial compensation from the Connexions website even if you purchase the PDF version ofthe module.
In the past, unknown individuals have copied my modules from cnx.org, converted them to Kindle books, and placed them for sale onAmazon.com showing me as the author. I neither receive compensation for those sales nor do I know who does receive compensation. If youpurchase such a book, please be aware that it is a copy of a module that is freely available on cnx.org and that it was made andpublished without my prior knowledge.
Affiliation : I am a professor of Computer Information Technology at Austin Community College in Austin, TX.
-end-
Notification Switch
Would you like to follow the 'Object-oriented programming (oop) with java' conversation and receive update notifications?