Вы находитесь на странице: 1из 10

UNIT I PART A 1. What are the OOP Principles?

The 4 major principles that make a language object-oriented: Encapsulation, Data Abstraction, Polymorphism and Inheritance.

2. What is Encapsulation? Encapsulation is the term given to the process of hiding all the details of an object that do not contribute to its essential characteristics. A technique in which data are packaged together with its corresponding procedures. Encapsulation conceals the functional details of a class from objects that send messages to it.

3. What is Polymorphism? It is the ability of an object to take more than one form. Is the capability of the method to do different things based on the object that it is acting upon. In computer science the term polymorphism means a method which has the same name as another but with different behaviour.

4. What is Inheritance? o o o o One class can inherit traits/properties of another class. class that is inherited is called superclass. Hence, subclass is specialized version of super class. We use the keyword extends for inheriting a class from other

5. What are the features of Java Language? Java Features Are

1) Simple,Small and familiar 2) Object oriented 3) Distributed 4) Robust 5) Secure 6) Platform independent 7) Portable 8) Compiled and Interpreted 9) High performance 10) MultiThreading and interactive 11) Dynamic and extensible 6. What is the need for Java Language? There are lots of applications and websites that won't work unless you have Java installed, and more are created every day. Java is fast, secure, and reliable. From laptops to datacenters, game consoles to scientific supercomputers, cell phones to the Internet, Java is everywhere! 7. What is platform independency? Java is a platform independent language becoz of the bytecode magic of java. Java is called as platform independent because it uses the WORA(Write Once and Run Anywhere) principle In java when we execute the source code...it generates the .class file comprising the bytecodes. Bytecodes are easily interpreted by JVM which is available with every type of OS we install.

8. What is Architecture Neutral? Java was designed to support applications on networks. In general, networks are composed of a variety of systems with a variety of CPU and operating system architectures. To enable a Java application to execute anywhere on the network, the compiler generates an architecture-neutral object file format--the compiled code is executable on many processors, given the presence of the Java runtime system. The Java compiler does this by generating bytecode instructions which have nothing to do with a particular computer architecture. Rather, they are designed to be both easy to interpret on any machine and easily translated into native machine code on the fly.

9. Why Java is important to Internet? Java is a programming language, that can be used to create websites, various processes that run behind the scenes to make internet more secure and reliable and much more. Because java runs on the java virtual machine. Therefore, java applications can run on top of the heterogeneous set of systems connected to the internet.

10. What are the types of programs Java can handle? Java can be used to create two types of programs: applications and applets

11. What is an applet program? An applet is an application designed to be transmitted over the Internet and executed by a java-compatible Web browser. An applet is actually a tiny java program, dynamically downloaded across the network, just like an image, sound file, or video clip. The applet is an intelligent program, not just and animation or media file. In other words, applet is a program that can react to user input and dynamically change not just run the same animation or sound over and over.

12. Compare Application and Applet. (1)Applications are must run inlocal machine where as Applets needs no explicit installation on local machine. (2)Applications mustbe run explicitly within a JVM where as Applets loads & runs itself automatically in a java-enabled browser. (3)Application starts execution with its main method where as applet starts execution with its init method. (4)Application can run with or without GUI but applet must run within a GUI.

13. What are the advantages of Java Language? The advantages of Java are as follows:

Java is easy to learn.

Java was designed to be easy to use and is therefore easy to write, compile, debug, and learn than other programming languages.

Java is object-oriented. This allows you to create modular programs and reusable code.

Java is platform-independent.

14. Give the contents of Java Environment (JDK). JDK contents JDK includes the following programming tools:

java: The tool java is an interpreter, that is also known as launcher of Java applications. This tool interprets the class files generated by the compiler (javac). javac: This tool is known as compiler that converts the source code into Java bytecode jar: The tool jar (java archive files) combines the related class libraries into a single JAR file. javadoc: The javadoc tool generates the document from our source code comments. jdb: It is a debugging tool that is used for debugging the application. javap: It works as a disassembler for the class files. appletviewer: appletviewer runs and debug Java applets without a web browser javah: This is the C header and stub generator. It also writes the native methods extcheck: This tool is used for detecting Jar conflicts apt: This tool processes the annotations jhat: This tool analysis the java heap jstack: This tool prints the Java stack traces generated by Java threads jstat: It works as the Java Virtual Machine statistics monitoring tool

15. Give any 4 differences between C and Java. JAVA is Object-Oriented while C is procedural. Java is an Interpreted language while C is a compiled language. C is a low-level language while JAVA is a high-level language. C uses the top-down {sharp & smooth} approach while JAVA uses the bottom-up {on the rocks} approach. JAVA supports Method Overloading while C does not support overloading at all.

16. Give any 4 differences between C++ and Java. 1. Java does not support operator overloading 2. A class definition in Java looks similar to a class definition in C++, but there is no closing semicolon. 3. Forward reference declarations are not required in Java. 4. Scope resolution operator (::) required in C++ is but not in Java. 4. In C++ you have to re-declare static data members outside the class but such things are not required in Java 17. What are the different types of comment symbols in Java? Java uses three types of comments: Single-line comment(//). Example: //single-line comment here Multiple-line comment(/**/). Example: /* line 1 her line 2 here */ Documentation comment(/****/). It is multiple-line and used with javadoc utility to create application documentation. 18. What are the data types supported in Java? The following table shows the default values for the data types: Keyword Description Byte-length byte integer short int Short integer Integer Size/Format 8-bit two's complement 16-bit two's complement 32-bit two's

long float

Long integer

complement 64-bit two's complement 32-bit IEEE 64-bit IEEE 16-bit Unicode character true or false

Single-precision floating point Double-precision double floating point char boolean A single character A boolean value (true or false)

19. How is a constant defined in Java? A constant is a variable whose value cannot change once it has been assigned. 'public static final' variables are constant.

In Java, the final keyword can be used with primitive data types and immutable objects (e.g., String) to c

20 What is the use of final keyword? The final keyword indicates that an object is fixed and cannot be changed. The three places where final keyword is used are: Data Field Method Class 21. What are the different types of operators used in Java? Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

Arithmetic Operators Relational Operators Bitwise Operators Logical Operators Assignment Operators Misc Operators

22. What is short-Circuit operator? The && and || operators "short-circuit", meaning they don't evaluate the right hand side if it isn't necessary. false && ... - it is not necessary to know what the right hand side is, the result must be
false true || ... true

- it is not necessary to know what the right hand side is, the result must be

23. What is the need for static variables? If you define a field as static, then there is only one such field per class. In contrast, each object has its own copy of all instance fields. For example, let's suppose we want to assign a unique identification number to each employee. We add an instance field id and a static field nextId to the Employee class: class Employee { ... private int id; private static int nextId = 1; } Now, every employee object has its own id field, but there is only one nextId field that is shared among all instances of the class. Let's put it another way. If there are one thousand objects of the Employee class, then there are one thousand instance fields id, one for each object. But there is a single static field nextId. Even if there are no employee objects, the static field nextId is present. It belongs to the class, not to any individual object.

24. What is the need for static methods? Static methods are methods that do not operate on objects. For example, the pow method of the Math class is a static method. The expression: Math.pow(x, y) Computes the power xy. It does not use any Math object to carry out its task. In other words, it has no implicit parameter. In other words, you can think of static methods as methods that don't have a this parameter. Because static methods don't operate on objects, you cannot access instance fields from a static method.

But static methods can access the static fields in their class.

26.Why is main method assigned as static?


To access the static method the object of the class is not needed. The method can be access directly with the help of ClassName. So when a program is started the jvm search for the class with main method and calls it without creating an object of the class.

27. What are the types of variables Java handles? Java variables can be categorized into the following seven types: 1. 2. 3. 4. 5. 6. 7. Class Variable Instance Variable Array Component Variable Method Parameter Variable Constructor Parameter Variable Exception Handler Parameter Variable Local Variable

28. What are the relationships between classes? Dependence (Uses-a) Aggregation (Has-a) Inheritance (Is-a) 29. What is the general form of a class? (access specifier) <Class> Classname [extends superclassname/implements interface] { Fields declaration; methods definition; } 30. What is the use of new keyword? Objects in java are created using new operator New operator creates an object of the specified class and returns the reference to that object. Eg: Rectangle rect1; //declare

Rect1 = new rectangle(); //instantiate (or) Rectangle rect1 = new rectangle(); 31. What is a constructor? A constructor is a method which is invoked when an object of a class is created. A class can have more than one constructor. A constructor is always called by new operator. Types of constructor: Default constructor. Parameterized constructor. General form of a constructor [access-specifier] class name (arguments) { Statements; 32. What is the difference between a constructor and a method? It has the same name as the class. A class can have more than one constructor. It has no return value. It is always called with new operator.

33. What is the use of this keyword? this Keyword this can be used inside any method to refer to the current object. this keyword has two meanings:

// A redundant use of this. Box(double w, double h, double d) { this.width = w; this.height = h; this.depth = d; } 34. What is Garbage collection? o The purpose of garbage collection is to identify and discard objects that are no longer needed by a program so that their resources can be reclaimed and reused.

o A Java object is subject to garbage collection when it becomes unreachable to the program in which it is used. 35. What is the use of finalize method? It is similar to destructor in c++. Only one finalize can be defined in a class. This method is called before the garbage collector removes the object. Objects utilize the resources other than memory, such as file etc., finalize method is defined in these situations to free these resources.

36. What is method overloading? Methods whose headings differ in the number and type of formal parameters are said to be overloaded methods. The parameter list that differentiates one method from another is said to be the method signature list.

Вам также может понравиться