Showing posts with label 1. Show all posts
Showing posts with label 1. Show all posts

Sunday, 24 January 2016

Elementary Concepts of Object & Class



Q. What is an Object?
Ans: An Object is an identifiable entity with some characteristics and behavior. 
E.g. take a class 'Car'. A car class has characteristics like colour, gears, power, length etc. now we create the object of that class 'Car' namely 'Indica'.

Q. What is OOP? What are the features/concepts in OOP's?
OR
Name any two OOP'S principles.
Ans: The Object Oriented Programming Paradigm is the latest in the software development and the most adopted one in the programming development. The Paradigm means organizing principle of a program. It is an approach to programming. 
The concepts of OOP's are: 
(1) Data Abstraction 
(2) Data Encapsulation 
(3) Modularity 
(4) Inheritance 
(5) Polymorphism.

Q. Explain all the Concepts of OOP's?
Ans: 
Abstraction: It refers to the act of representing essential features without including the background details or explanation. 
Encapsulation: It is the way of combining both data and the function that operates on the data under a single unit. 
Modularity: It is the property of a system that has been decomposed into a set of cohesive and loosely couple modules. 
Inheritance: It is the capability of one class of thing to inherit properties from another class.
Polymorphism: It is the ability for a message or data to be processed in more than one form.

Q. What are the advantages of OOP's?
Ans: 
(1) Elimination of redundant coding system and usage of existing classes through inheritance.
(2) Program can be developed by sharing existing modules.
(3) Possibilities of multiple instance of an objects without any interference.
(4) Security of data values from other segment of the program through data hiding.

Q. What is Class? How Object is related to the Class?
Ans: A Class represent a set of Objects that share common characteristics and behavior. Objects are instance of a class. The Object represents the abstraction representation by the class in the real sense.

Q. What is the need of a class in Java?
Ans: Classes in Java are needed to represent real-world entities, which have data type properties. Classes provide convenient methods for packing together a group of logical related data items and functions that work on them. In java the data items are called fields & the functions are called methods.

Q. What are Methods? How are these related to an Objects?
Ans: A Method is an operation associated to an Object. The behavior of an Object is represented through associated function, which are called Methods.

Q. Point out the differences between Procedural Programming and Object Oriented Programming.
Ans: Procedural programming aims more at procedures. The emphasis is a doing things rather then the data being used. In procedural Programming parading data are shared among all the functions participating thereby risking data safety and security. Object Oriented Programming is based on principles of data hiding, abstraction, inheritance and polymorphism. It implements programs using classes and objects, In OOP's data and procedure both given equal importance. Data and functions are encapsulated to ensure data safety and security.

Q. What is an abstraction?
Ans: An abstraction is a named collection of attributes and behaviors required to represent an entity or concept for some particular problem domain. 

Q. What is inheritance and how it is useful in Java.
Ans: It is process by which objects of one class acquire the properties of objects of another class. Inheritance supports the concepts of hierarchical representation. In OOP the concepts of inheritance provides the idea of re-usability.

Q. What role does polymorphism play as java feature?
Ans: It mean the ability to take more than one form. 
For example, an operation, many types of data used in the operation.

Q. What is Data hiding?
Ans: Data Hiding means restricting the accessibility of data associated with an object in such a way that it can be used only through the member methods of the object.

Q. What are nested classes?
Ans: It is possible to define a class within another class, such classes are known as nested classes. A nested class has access to the members including private members of the class in which it is nested. However the enclosing class not have access to the members of the nested class.

Q. Differentiate between base and derived class.
Ans: 
BASE CLASS - A class from which another class inherits (Also called SUPER CLASS).
DERIVED CLASS - A class inheriting properties from another class. (Also called SUB CLASS).

Introduction to Java & BlueJ Environment

Q. What is Java?
Ans: Java is a general purpose, high-level programming language developed by Sun Microsystems. A small team of engineers, known as the Green Team, initiated the language in 1991. Java was originally called OAK, and was designed for handheld devices and set-top boxes. Oak was unsuccessful, so in 1995 Sun changed the name to Java and modified the language to take advantage of the burgeoning World Wide Web.

 
Q. Why is Java often termed as a platform?
Ans: Platform is the environment in which programs execute. Instead of interacting with the Operating System directly, Java programs runs on a virtual machine provided by Java, therefore Java is often referred to as a platform also.

Q. What is a ByteCode?
Ans: Bytecode is a set of pseudo mechanic language instructions that are understood by the JVM (Java Virtual Machine) and are independent of the underlying hardware.

Q. What do you understand by JVM?
Ans: JVM or Java Virtual Machine is an abstract machine designed to be implemented on top of existing processors. It hides the underlying OS from Java application. Programs written in Java are compiled into Java byte-code, which is then interpreted by a special java Interpreter for a specific platform. Actually this Java interpreter is known as Java Virtual Machine (JVM).

Q. What is JDK (Java Development Kit)?
Ans: The Java development kit comes with a collection of tools that are used for developing and running java programs.

Q. What are Java APIs?
Ans: The Java APIs (Application Program Interface) consist of libraries of pre-compiled code that programmers can use in their application.

Q. Write the five characteristics of Java/BlueJ?
Ans: 
1. Write Once Run Anywhere 
2. Light weight code 
3. Security 
4. Built in Graphics 
5. Object Oriented Language 
6. Support Multimedia 
7. Platform Independent. 
8. Open Product.

Q. What do you know about BlueJ?
Ans: BlueJ is a Java development environment. It is an IDE (Integrated Development Environment), which includes an editor a debugger and a viewer. 

Q. How you create, compile and execute a program in Java or BlueJ? Explain your answer?
Ans: 
Create: Click on new class button from BlueJ editor, then type the class name a program icon will be created. double click on it, a program editor will be open, erase the code and type your program coding. 
Compile: click the compile button on the left of the window or right click on the class icon and select compile from the menu options. Execute: Right click on the class icon and select new class name option. A dialogue box appears type the name of the object. A object icon will be created at the bottom. Right click on the object icon and select the method we want to execute.

Q. The two types of Java programs/applications are?

Ans: The two types of Java Applications are 'Internet Applets' and 'Stand alone application'.


Q. State the distinguishing features of Java and C++?
Ans: 
(i) Java does not support operator overloading.
(ii) Java does not use pointers.
(iii) There are no header files in Java.
(iv) Java does not have template classes as in C++.

Q. State the differences between Syntax errors and Logical errors.
Ans: The compiler can only translate a program if the program is syntactically correct; otherwise the compilation fails and you will not be able to run your program. Syntax refers to the structure of your program and the rules about that structure.
The second type of error is a run-time error, so-called because the error does not appear until you run the program. In Java, run-time errors occur when the interpreter is running the byte code and something goes wrong.

Q. "Object is an instance of a class", explain?
Ans: Object of a class contains data and functions provided in a class. it possesses all the features of a class. Hence object is termed as instance of a class.

Q. Name four basic features of JAVA.
Ans: Basic features of Java as follows:
i) It is an object oriented language.
ii) Java program is both compiled and interpreted.
iii) Java program can be application or applet.
iv) java is case sensitive language, i.e. it distinguished upper and lower case letters.

Q. Differentiate between Compiler and Interpreter.
Ans: Compiler convert source code to machine language whole at a time. Interpreter converts program from high level language to machine level language line by line or statement by statement.

Q. Java uses compiler as well as interpreter, explain.
Ans: Java compiler converts Java source code to byte code. This byte code is further converted into machine code to make it applicable for the specific platform by using interpreter.

Q. Differentiate between Source code and Byte code.
Ans: Source code is the program developed in Java Language, which is input to a computer through the keyboard. Compiler converts source code to byte code for interpretation.

Q. Differentiate between Testing and Debugging.
Ans: Testing is the process of checking program logic manually to ensure whether it contains any error or not. Debugging is the process of removing errors from a program.