Java- A Cup of Coffee
Java- A Cup of Coffee
Now let me explain each and every line of the above-mentioned program.
1. The program begins with a comment to specify the program purpose. A comment is an explanatory
statement which allows you to understand the code easily. Comments do not appear in the output screen.
They are not executed. Java supports two types of comments: single-line and multi-line.
A single-line comment starts with // and the remaining line is considered in the comment.
A multi-line comment starts with /* and ends with */.
2. A class is a place holder for Java code. All the Java codes needs to be encapsulated within a class. Class
should begin with the ‘class’ keyword followed by the class name. A class name should be user-defined and
must be in CamelCase, which means First letter of every word comprising of class name should be in capital
letter.
4. A program execution begins from the main() method. In the main method you can create the object of the
defined class and have an access to the member method by using the dot(.) operator. The beginning and
ending of main method is done by using ‘{‘ and ‘}’ respectively.
public: It is an access specifier, which specifies if the method can be used by other members of the
program.
static: The Java environment should be able to call this method without creating an instance of the
class, so, this method must be declared as static.
void: The return type of this method is void, which means it will not return any value.
main: This is the beginning point of execution of the program.
String args[]: Arguments to the method must be an array of Strings, and the array is called ‘args’.
1. What does the Java compiler translate the Java program into?
(a) Bytecode (b) HLL
(c) Code (d) Source code
2. Command javac is used for
(a) Interpretation (b) Compilation
(c) Execution (d) None of the these
3. What does JDK stand for?
(a) Java Domain Kit (b) Java Deployment Kit (c) Java Data Kit (d) Java Development Kit
4. Everything in Java is written inside __________.
(a) an object (b) variable (c) a class (d) a method
5. A single-line comment starts with:
(a) /* (b) // (c) / (d) */
6. What is the method that tells the compiler to print a message on the screen in a new line?
(a)System(b)Text in quotes(c)println()(d)out
7. In Java, what is the return type of the main() method?
(a)char(b)int (c)string(d)void
8. The process of enclosing data and methods at the same location is called:
(a)Data Hiding(b)Abstraction(c)Encapsulation(d)Polymorphism
9. Which of the following options is the correct syntax for creating an object of a class?
(a) Object object-name; (b)Object-name class-name;
(c)Class-name object-name; (d)Object-name object;
10. What is the extension of saved Java file?
(a) .java (b) .javac (c) .doc (d) .exe
Subjective Questions
1. List the key concepts of OOPs and discuss.
2. Distinguish between data abstraction and data encapsulation.
3. Define the following terms:
(a) JDK (b) JVM (c) JRE (d) JCL
4. What is the main() method in Java?
5. What is the significance of semicolon(;) in Java?
6. Define the features of Java programming language.
7. How many types of comments are there in Java?
8. Why Java is called platform-independent?
http://122.176.26.123:810/Teacher.html