Chapter 1 Java Building Blocks Flashcards
What should be the name of the java class files ?
If you do have a public class, it needs to match the file name, including case. public class Animal2 would not compile in a file named Animal.java
What styles of comment you know in Java ?
There are three styles of comment: a single-line comment
(//), a multiline comment (/* */), and a Javadoc comment (/** */).
What does it mean when an import ends with wildcard (*) ?
A wildcard ending an import statement means you want
to import all classes in that package. It does not include packages that are inside that one.
What is java.lang ?
Special package that is automatically imported. You can still type this package in an import
statement, but you don’t have to.
What is initialized first when an object is instantiated (fields, blocks, constructor)?
When an object is instantiated, fields and blocks of code are
initialized first. Then the constructor is run.
Numeric literals are allowed to begin with.. ?
Numeric literals are allowed to begin with 0 (octal), 0x (hex), 0X (hex),
0b (binary), or 0B (binary). Numeric literals are also allowed to contain underscores as long as they are directly between two other numbers.
Which variable are initialized automatically and which not ?
Variables that represent fields in a class are automatically initialized to their corresponding “zero” or null value during object instantiation. Local variables must be specifically initialized.
What are the types of variables depending on their scope ?
Scope refers to that portion of code where a variable can be accessed. There are three kinds of variables in Java, depending on their scope: instance variables, class variables, and local variables. Instance variables are the nonstatic fields of your class. Class variables are the static fields within a class. Local variables are declared within a method.
Class elements order is… ?
For some class elements, order matters within the file. The package statement comes first if present. Then comes the import statements if present. Then comes the class declaration. Fields and methods are allowed to be in any order within the class.
When an object is eligible for garbage collection ?
An object becomes eligible for garbage collection when there are no more references to it or its references have all gone out of scope.
Which of the following are valid Java identifiers:
java.lang
Public
- java lang is not valid because the dot (.) is not allowed in identifiers;
- Java is case sensitive, so Public is not a reserved word and therefore a valid identifier;