Java Introduction

Q1. What is a Class?
Ans: A class is a blueprint, or prototype, that defines the variable and the methods common to all objects of certain kind
Q2. What is an object?
Ans: An object is a software bundle of variables and related methods. An instance of a class depiciting the state and behavior at that particular timr in real world
Q3. What is a method?
Ans: Encapsulation of a functionality which can be called to perform specific tasks
Q4. What is encapsulation? Explain with an example.
Ans: Encapsulation is the term given to the process of hiding the implementation detials of the object. Once an object is encapsulated, its implementation detials are not immediately accessible any more. Instead they are packaged and are only indirectly accessible via the interface of the object
Q5. What is inheritance? Explain with an example.
Ans: Programming means that a class of objects can inherit properties and methods from another class of objects
Q6. What is polymorphism? Explain with an example.
Ans: In object-oriented programming, polymorphism refers to a programming language's ability to process objects differently depending on their data type or class. More specifically, it is the ability to refine methods for derived classes. For example, given a base class shape, polymorphism enables the programmer to define different area methods for any number of derived classes, such as circles, rectangles and triangles. No matter what shape an object is, applying the area method to it will return the correct results. Polymorphism is considered to be a requirement of any true object-oriented programming language
Q7. Is multiple inheritance allowed in Java?
Ans: No, multiple inheritance is not allowed in Java
Q8. What is interpreter and compiler?
Ans: Java interpreter converts the high level language code into a intermediate form in Java called bytecode, and then executes it, where as a compiler converts the high level language code to machine language making it very hardware specific
Q9. What is JVM?
Ans: The Java interpreter along with the runtime environment required to run the Java application is called Java Virtual Machine (JVM)
Q10. What are the different types of modifiers ?
Ans: There are access modifiers and there are other identifiers. Access modifiers are public, protected and private. Other are final and static
Q11. What are the access modifiers in Java?
Ans: There are three access modifiers. Public, protected and private, the default one if no identifier is specified is called friendly, but programmer cannot specify the friendly identifier explicitly.
Q12. What is a wrapper class?
Ans: They are classes that wrap a primitive data type so it can be used as a object
Q13. What is a static variable and static method? What is the difference between the two?
Ans: The modifier static can be used with a variable and method. When declared as a static variable, there is only one variable no matter how many instances are created, this variable is initialized when the class is loaded. Static method do not need a class to be instantiated to be called, also a non static method cannot be called from static method
Q14. What is garbage collection?
Ans: Garbage collection is a thread that runs to reclaim the momory by destrying the objects that cannot be referenced anymore
Q15. What is abstract class?
Ans: Abstract class is a class that needs to be extended and its methods implemented, a class has to be declared abstract if it has one or more abstract methods
Q16. What is meant by final class, methods and variables?
Ans: This modifer can be applied to class method and variable, when declared as final class the class cannot be extended. When declared as final variable, its value cannot be changed if is primitive value, if it is a reference to the object it will always refer to the same object, internal attributes of the object can be changed
Q17. What is interface?
Ans: Interface is a contact that can be implemented by a class, it has method that need implementation
Q18. What is method overloading?
Ans: Overloading is declaring multiple method with the same name, but with different argument list
Q19. What is method overriding?
Ans: Overriding has same method name, identical arguments used in subclass
Q20. What is singleton class?
Ans: Singleton class means that any given time only one instance of the class is present, in one JVM
Q21. What is the difference between an array and a vector?
Ans: Number of elements in an array are fixed at the construction time, whereas the number of elements in vector can grow dynamically
Q22. What is a constructor?
Ans: In java, the class designer can guarentee initialization of every object by providing a special method called constructor. If a class has a contructor, Java automatically calls that constructor when an object is created, before users can even get their hands on it. So initilization is guaranteed
Q23. What is casting?
Ans: Conversion of one type of data to another when appropriate. Casting makes explicitly converting of data
Q24. What is the difference between final, finally, finalize?
Ans: The modifier final is used on class variable and methods to specify certain behavior explained above. And finally is used as one of the loop in the try catch blocks, it is used to hold code that needs to be executed whether or not the exception occurs in the try catch block. Java provides a method called finalize() that can be defined in the class. When the garbage collector is ready to release the storage for the object, it will first call finalize(), and only on the next garbage-collection pass will it reclaim the objects memory. So finalize(), gives the ability to perform some important cleanup at the time of garbage collection
Q25. What are packages?
Ans: A package is a collection of releated classes and interfaces providing access protection and namespace management
Q26. What is a super class and how can you call a super class?
Ans: When a class is extended that is derived from another class, there is a relationship is created, the parent class is referred to as the super class by the derived class that is the child. The derived class can make a call to the super class using the keyword super. If used in the constructor of the derived class it has to be the first statement
Q27. What is meant by a Thread?
Ans: Thread is defined as an instantiated parallel process of a given program
Q28. What is multi-threading?
Ans: Multi-threading as the name suggest is the scenario where more than one threads are running
Q29. What are two ways of creating a thread? Which is the best way and why?
Ans: Two ways of creating threads are, one can extened from the java language. Thread and can implement the rum method or the run method of a different class can be called which implements the interface Runnable, and then implement the run() method. This latter one id mostly used as first due to java rule of only one class inheritance, with implementing the Runnable interface that problem is sorted out.
Q30. What is deadlock?
Ans: Deadlock is a situation when two threads are waiting on each other to release a resource. Each thread waiting for a response which is held by the other waiting thread. In java, this resource is usally the object lock obtained by the synchronized keyword
Q31. What are the three types of priority?
Ans: MAX_PRIORITY which is 10, MIN_PRIORITY which is 1, NORM_PRIORITY which is 5
Q32. What is the use of synchronizations?
Ans: Every object has a lock, when a synchronized keyword is used on a piece of code, the lock must be obtained by the threadfirst to execute that code, other threads will not be allowed to execute that piece of code till this lock is released.         
     

No comments:

Post a Comment