You are on page 1of 3

1. What are the three OOPs principles and define them?

Answer:
Encapsulation – is binding variables and methods under single entity.
Inheritance – is acquiring the properties of one class to another class.
Polymorphism – is the ability of an object to take on many forms.

2. What is a compilation unit?


Answer:
The source code for a java class is called a compilation unit. A simple compilation unit contains
a single class definition and is named for that class.

3. What are identifiers and what is naming convention?


Answer:
Identifiers - are names used for classes, variables and methods.
Naming convention - is a rule to follow as you decide what to name your identifiers such as
class, package, variable and method.

4. What are different comments?


Answer:
Single line comments – is used to comment only one line.
Multi – line comments – is used to comment multiple lines of code.
Special javadoc comments – are any multi-line comments that are paced before class, field or method
declarations. They must begin with a slash and two stars and it contains tags to add more information to
your comments.

5. What is meant by variable?


Answer:
Variable is name of reserved area allocated in memory. In other words, it is name of memory
location

6. What are the kinds of variables in Java? What are their uses?
Answer:
Numeric variables - holds numbers or digits and can be used for mathematical computations.
Textual data - holds text, such as letters of the alphabet, and other characters
Boolean data - holds a value of true or false

7. How do you assign values to variables?


Answer:
The most common form of statement in a program uses the assignment operator, =, and either an
expression or a constant to assign a value to a variable.

8. What is a literal? How many types of literals are there?


Answer:
Literal are exact representations a constant. There are five types of literals can be classified as
integer literals, floating-point literals, character literals, string literals and Boolean literals.

9. What is an array?
Answer:
Arrays are used to store a collection of data, but it may be useful to think of an array as a
collection of variables that are all of the same type.

10. What is a string?


Answer:
String is actually a non-primitive data type, because it refers to an object.

11. Which operator is to create and concatenate string?


Answer:
Concatenation in the Java programming language is the operation of joining two strings together.
You can join strings using the addition (+) operator.

12. What are the Logical operators?


Answer:
&& Logical and – returns true if both statements are true.
|| Logical or – returns true if one of the statements is true.
! Logical not – reverse the result, returns false if the result is true.

13. What is the % operator?


Answer:
This is % known as the modulus or remainder operator. The % operator returns the remainder of
two numbers.
14. What is the difference between prefix and postfix of -- and ++ operators?
Answer:
Prefix causes the variable to increment or decrement before another operation. Postfix causes the variable
to increment or decrement after another operation.

15. What is the difference between while statement and a do statement?


Answer:
A while loop statement repeatedly executes a target statement as long as a given condition
remains true. A do while loop executes the statements in the code block at least one time even if
the condition fails.

16. What is mean by garbage collection?


Answer:
The garbage collector or just collector, attempts to reclaim garbage or memory occupied by
objects that are no longer in use by the program.

17. On successful compilation a file with the class extension is created. Why?
Answer:
After the file compile, a byte code file will be generated with an extension .class file as executable file.

18. Java compiler stores the .class files in the path specified in CLASSPATH environmental
variable? Why?
Answer:
Because CLASSPATH is an environment variable which is used by Application Class Loader to locate
and load the .class files.

19. Can a for statement loop indefinitely? Why?


Answer:
Yes, for loop can be indefinitely. If you use two semicolons ;; in the for loop it will be indefinite
loop.

20. What are difference between break and continue?


Answer:
Break statement mainly used to terminate the enclosing loop such as while, do-while, for or
switch statement wherever break is declared. Continue statement mainly skip the rest of loop
wherever continue is declared and execute the next iteration.

You might also like