Java Question Answer

Q. a) State the difference between token and identifier, variable.
Ans. A token is the smallest individual unit in a program for e.g.: Keyword, Identifiers, Literals etc. where as an identifier is the name given to different parts of a program e.g. variable, functions, classes etc.
Variable: A memory location that stores a value is known as variable. E.g. int a;
    b) What is variable. Give an example.
Ans. Place holder of data in computer memory. E.g. Int a,b,c;
Q. Define Byte code and JVM.
Ans. Byte code is the compiled format for Java programs. Once a Java program has been converted to byte code, it can be transferred across a network and executed by Java Virtual Machine (JVM). Byte code files generally have a .class extension
Ans: JVM is a platform-independent execution environment that converts Java byte code into machine language and executes it. Most programming languages compile source code directly into machine code that is designed to run on a specific microprocessor architecture or operating system, such as Windows or UNIX. A JVM -- a machine within a machine -- mimics a real Java processor, enabling Java byte code to be executed as actions or operating system calls on any processor regardless of the operating system.
Q. Example the term Object and Class using an example. 
Ans. Object: An instance of a class called Object. Table is an instance of class Furniture.
Class: Blue print of an object is called Class. Example, mango, apple and orange are members of the class fruit.
Q. Name four OOP’S principles.
Ans. Abstraction, Encapsulation, Polymorphism, Inheritance
Abstraction: Abstraction refers to the act of representating essential features without including the background details or explanations.
Encapsulation: The wrapping up of data and methods into a single unit is called Encapsulation.
Polymorphism: Poly means many and morph mean shape, so it is refers to a programming language's ability to process objects differently depending on their data type or signature. More specifically, it is the ability to redefine 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.
Inheritance: Inheritance mean the acquire characters of parent class by child class. Actually it is the process by which objects of one class acquire the properties of objects of anther class. Different kinds of objects often have a certain amount in common with each other. Mountain bikes, road bikes, and tandem bikes, for example, all share the characteristics of bicycles (current speed, current pedal cadence, current gear). Yet each also defines additional features that make them different: tandem bicycles have two seats and two sets of handlebars; road bikes have drop handlebars; some mountain bikes have an additional chain ring, giving them a lower gear ratio.
Q. Mention any two attributes required for class declaration.

Ans: Variables and function or state and behaviour.
Learn JAVA Step by Step

SHARE THIS
Previous Post
Next Post