Ans. The major difference between java and c is java is an object-oriented language and has mechanism to define classes and objects. Where as c is a procedural language. Java is a true object oriented language where c++ is c with object-oriented extension. The extension part of c++ is somewhere similar to java.
Q2. What is object oriented programming?
Ans. Object oriented programming is a way to develop applications by using objects as building blocks. Object oriented programming involves creating application-using objects, which emulate real world objects in behavior and appearance. The oops is as a set of objects that work together in predefined ways to accomplish tasks.
Q3. What is JAVA?
Ans. Java is a programming language developed by Sun Microsystems which is designed after C++ programming language. However it is architect to be simpler and safer than C++, hence takes away some language features of C++ and adds more to it. It is Object-Oriented and portable across multiple platforms and operating systems.
Once compiled a java program can be executed on different platforms. Compiling java program generates byte-code; an intermediate level of machine code that is further interpreted by an engine that understands this intermediate level of machine code to convert it to the native code of say different platforms like Windows, Solaris, Linux and MacOS etc. This feature makes Java platform independent.
Q4. What is Byte-Code?
Ans. Byte-codes are the basis of Java’s platform independent. You either compile or interpret a program in most programming languages. However a Java program is both compiled and interpreted. With the compiler, a program is translated into an intermediate language called Java byte-code, which is the platform-independent code interpreted by the interpreter on the Java platform.
The interpreter parses and runs each Java byte-code instruction on the computer. Compilation happens just once; interpretation occurs each time the program is executed. Essentially, Byte-codes are the machine language of the Java virtual machine. These byte-codes further get converted to the native machine code by the interpreter engine.
Q5. What is JVM?
Ans. The Java virtual machine executes instructions that a Java compiler generates. Java Virtual Machine is the base for the Java platform and is ported onto various hardware-based platforms. Every Java interpreter, whether it's a development tool or a Web browser that can run applets, is an implementation of the Java VM.
The Java virtual machine has n knowledge of the Java programming language. It understands a particular binary format, the class file format. A class file contains Java virtual machine instructions (or byte-codes) and a symbol table and other supportive information. JVM imposes strong security by having format and structural constraints on a class file. This leads to an interesting outcome: any language with functionality that can be expressed in terms of a valid class file can be hosted by the Java virtual machine.
Q6. What is JAVA Platform?
Ans. We need a software engine to write, compile and run programs in for any language, be it C++, C# or Java. Java Platform is the most basic engine that you will require to write and compile a Java Program. It is a software platform that you install on top of any Hardware Platform like Windows, Sun or Mac OS.
Java Platform has two components
Java Virtual Machine (JVM) and Java Application Programming Interface (Java API).
Q7. What is JDK?
Ans. JDK is the acronym for Java Development Kit- essentially a Java platform, consisting of the API classes, a Java compiler, and the Java Virtual Machine interpreter. The JDK is used to compile Java applications and applets. The most current version is the J2SE.
If you use J2SE 1.2 and later to develop applications, you are using what's known as the Java 2 Platform. The latest Java 5 or J2SE 1.5 is Sun’s most ambitious upgrade that has several enhancements to the Java language that did not exist so far.
Q8. What is Encapsulation?
Ans. Encapsulation provides the basis for again modularity- by hiding information from unwanted outside access and attaching that information to only methods that need access to it. This binds data and operations tightly together and separates them from external access that may corrupt them intentionally or unintentionally.
Encapsulation is achieved by declaring variables as Private in a class- this gives access to data to only member functions of the class. A next level of accessibility is provided by the Protected keyword which gives the derived classes the access to the member variables of the base class- a variable declared as Protected can at most be accessed by the derived classes of the class.
Q9. What are the advantages of encapsulation in object oriented software development?
Ans. Advantages of encapsulation
Encapsulation is the process to hide data from the outside world. It provides security so that only valid object can access the data of a class using class methods. It helps in job specification by methods defined under the class.
Q10. What is casting?
Ans. Casting is the process to convert the data type of a variable one to another
For a statement, Java provides two types of casting:
1. Implicit typecast happens when data type is automatically converted into the higher type from lower.
2. Explicit typecast happens when we want to convert a higher data type to lower type.
Ans. Java 1.2 provides some additional features those are present in java1.1.
These features are
1. Swings programming
2. Collection Objects
3. JIT compiler
4. More flexible security features etc.
Ans. Whitespaces, identifiers, literals, comments, separators, keywords.
Q13. Define all the Data types used in Java.
Ans.
Name Width
Long 64
Int 32
Short 16
Byte 8
Float 32
Double 64
Float 32
Char 16
Boolean store true/false
Q14. Name all bit wise operators used in Java.
Ans.
Operator Result
~ Bitwise unary Not
& Bitwise And
| Bitwise or
^ Bitwise exclusive or
>> Shift right
>>> Shift right zero fill
<< Shift left
&= Bitwise and assignment
!= Bitwise or assignment
^= Bitwise exclusive or
>>= Shift right
>>>= Shift right zero fill assignment
<<= Shift left assignment
Q15. What is the use of Compiler class?
Ans. The Compiler class supports the creation of Java environments in which java byte code is compiled into executable code rather than interpreted. It is not for normal programming.
Q16. Which ‘+’ is addition? Which is concatenation?
Ans. If neither operand of + is a reference to a String object, the operator is the arithmetic addition operator, not the string concatenation operator. Note that Java does not allow a program to define overloaded operators. However, the language defines the + operator to have a meaning that is fundamentally different from arithmetic addition if at least one of its operands is a String object.
Q17. Write a note on Abstraction.
Ans. It is an essential element of object-oriented programming. Humans manage complexity through abstraction. A powerful way to manage abstraction is through the use of hierarchical classifications. This allows you to layer the semantics of complex systems, breaking into more manageable pieces.
Q18. What are hardware and software requirements to run Java?
Ans. Because java runs on man y platforms, you can run java programs on any machine and any operating system. It requires a fast processor, ample memory and 256 color (or better) video support.
More you need-
A text editor
Development tools like JDK KIT
Java enabled web browser- Netscape Navigator, Internet Explorer.
Q19. What is difference between Boolean & operator and the logical && operator?
Ans. Boolean and compares two number by every bit of that number but && operator compare two number as whole.
Q20. When sending command-line arguments to java or javac the * character is treated as a wildcard. How can I quote it?
Ans. class star
{
public static void main(String app[])
{
String h;
h=app[0];
System.out.println(h);
}
}
In this program if we pass simple *(star) it will return any file name with class extension which is stored in buffer.
For example abc.class
If we Quote it with “*” Then it will return * character.
For example *
Q21. Why java is Dynamic programming?
Ans. Java programs carry with them substantial amounts of run-time type information that used to verify and resolve accesses to objects at run time. This makes it possible to dynamically link code in a safe and expedient manner. In the applet environment byte code may be dynamically updated on a running machine.
Q22. What are the advantages of encapsulation in object oriented software development?
Ans. Advantages of encapsulation
Encapsulation is the process to hide data from the outside world
It provide security so that only valid object can access the data of a
Class using class methods.
It helps in job specification by methods defined under the class.
Q23. Why Java is important to the Internet?
Ans. Java expands the universe of objects that can move about freely in cyberspace. Java provides the secure transaction on the Internet using applet programming. This program can run on java enables web browser with more security like firewall etc.
Q24. How java provides double security?
Ans. Java is both compile and interpreter base language. Java compiles the program and convert it into the byte code all the syntax error are checked at that time. After that it is converted into native and runtime exceptions are checked.
So a java program checked double time before it run an provide double security.
Ans. The Date class encapsulates the current data and time provide numbers of methods to manipulate Date.
Ans. Java’s stream based I/O is built upon four abstract classes : InputStream OutputStream, Reader and Writer. Input/Output Stream are designed for byte streams. Reader and Writer are designed for character streams. These classes have the separate hierarchies.
On the Internet applet provides these security feature .on body can alter the applet if it is transfer to the client machine.
Q27. Define vector. What are advantages of Vector over arrays?
Ans. Vector class can be used to create a generic dynamic array known as vector that hold objects of any type and any number. The objects do not have to be homogeneous. Vector are created like arrays:
E.g. Vector list = new Vector (5);
Advantages: It is convenient to use vectors to store objects.
A vector can be used to store a list of objects that may very in size.
Creation of an array involves three steps:
Declare the array.
Create memory locations.
Put values into the memory locations.
E.g. int age[]= new int[5];
We can add and delete objects from the list as and when required.
Q28. Explain the syntax of for loop in java.
Ans. For (initialization; test condition; increment)
{
Body of loop
}
Q29. What is the value of int variable ‘a’ after execution of the following program segment?
Int a=-1;
a=a>>>24;
Ans. The answer is 225.
Ans. Constants are fixed they cannot changed. Symbolic constant names provided to the value and that value can be accessed with that name.
For example pi and exp define in the math class. Which is defined in the java.lang package.
Ans. There are three parts of a class
1.Class name
2.Body of the class
3.Closing of the body
Ans. The data or variables, defined within a class are called instance variables. The code is contained within methods. The instance variables are acted upon and accessed by the methods defined for that class. Variables defined within a class are called instance variables because each instance of the class contains its own copy of these variables.
Ans. An object is a blue print of a class. An object is a class variable. An object is a representation of a class that holds data and allows operations to be performed on it self. Class is a definition of a data type whereas an object is a variable or an instance of the class type. An object is a representation of a type that holds data and allows operations to be performed on it self.
Q34. What is the difference between Methods and Constructors?
Ans. Method and Constructors both defined under the class but there is some difference between method and constructor
Method Constructor
Defined with any name Always having the same name as the name of the class
Return can be specified No return type is specified
Declared as abstract Never declared as abstract
Invoked by the reference of the object of a class Invoked when ever the memory is allocated to the object
Q35. Compare overloading and overriding methods.
Ans. Difference between overloading and overriding is:
Overloading Overriding
Overloading happens with in the same class Overriding happens with in super and Sub class
In overloading methods having same name, In overriding methods having same name same can called by same object of the class but with parameters but can call by the different objects different parameters of different class.
Q36. Differentiate between Java array and vector.
Ans. Difference between Java array and vector is:
Array Vector
Arrays are static Vectors are dynamic
No legal method to handle array Provides different types of legal methods to handle vector
Not related the collection Related to the collection object
We can’t return any array value withoutArray index Vector’s element value can be returned without index value
Q37. When do we declare a method or class final?
Ans. Methods are declared final when we want to prevent these methods to override.
Classes are declared final so that these are not inherited.
Q38. What is a Constructor? What are its special properties?
Ans. Constructors are the method defining by the same name as the name of the class. Used to initialize an object at the time of object creation. Special property of a constructor is that it doesn’t have any return type.
Q39. What is a Constructor? What are its special properties?
Ans. Constructors are the method defining by the same name as the name of the class. Used to initialize an object at the time of object creation. Special property of a constructor is that it doesn’t have any return type.
Q40. What is the difference between multiple inheritance and single inheritance? Which does java support?
Ans.
Multiple Inheritance
Single inheritance
In multiple inheritance a sub class can have more than one super class
In single inheritance a sub class can have only one super class.
Java support only single inheritance, but it can implements the concept of multiple inheritance using interfaces.
Q41. What restrictions are placed on method overloading?
Ans. Restrictions
In methods overloading, overloaded methods must have same name.
They must different parameters.
They must define under the same class.
Q42. Name all the control statement used in java.
Ans. Decision control If and switch
Loop control While, do while, for
Label statements Break continue
Q43. What is the use of return statement?
Ans. The return statement is used to explicitly return from a method. It causes program control to transfer back to the caller of the method. Return statement always return a single value.
Q44. Define the syntax to declare an object.
Ans. classname xx=new classname();
E.g. Box xx=new my Box();
Q45. What is use of ‘this’ keyword?
Ans. This can be used to inside any method to refer the current object of the class. This is always a reference to the object on which the method was invoked. e.g
my(int i,int j,int k)
{ this.i=I, this.j=j, this.k=k; }
Q46. What do you mean by Garbage Collection?
Ans. Java provides a special feature in classes the object of class is de allocated automatically when it is not in use this process is called garbage collection.
Q47. Define static in Java.
Ans. Static keyword is used with variables and methods. So that they call by the reference of class name in which they are declared without creating the object of that class.
Q48. What is the use of final keyword?
Ans. Final keyword used with variables to make constant declaration , with classes to prevent inheritance, and with method to prevent overriding.
Q49. Differentiate String and StringBuffer class.
Ans. String and StringBuffer classes both creates String object. String represents fixed-length immutable character sequences. But StringBuffer represents grow able and write able character sequences. StringBuffer also allow the alteration at the middle of the string.
Q50. Name all the methods provided in the String class to manipulate Strings.
Ans. Length(),toString(),charAt(),getChars(),getBytes(),toCharArray(),equals(),startsWith(),
endsWith() ,indexOf(),lastIndexOf(),substring().
Q51. What are Wrappers?
Ans. Data types are the not part of the object hierarchy. They are passed by the reference. There is no way to refer to the same instance of an int. Java provides classes that corresponds to each of the simple types. These classes encapsulate, or wrap the simple type within a class and refer as Wrappers.
Q52. List all the wrapper classes.
Ans. Integer, Byte, Long, Short, Float, Double, Character, Boolean.
Q53. Define System Class.
Ans. The System class holds a collection of static methods and variables. The standard input, output and error output of the java run time are stored in the in ,out and err variables.
Q54. Name the super class of the java classes.
Ans. Object is the super class of all the java classes.
Q55. Define Class.
Ans. Class encapsulates the run-time state of an object or interface. Object of type Class are created automatically, when classes are loaded.
Q56. Name all the methods provided by Math class.
Ans. sin(), cos(), tan(), asin(), acos(), atan(), atan2(), exp(), log(), pow(). sqrt(), abs(), floor(), max(), ceiling(), min(), round(), random(), toRadians(), toDegrees().
Q57. What are objects? How are they created?
Ans. An object is an instance of a data type. An object in OOPs is instance of class. Object is used access the members of a class. To create an object of class we use new keyword.
E.G. if ABC is a class and we want to declare an object obj for this class. The
ABC obj = new ABC ();
Q58. What do you understand by static?
Ans. There will be times when you will want to define a class member that will be used independently of any object of that class. To create such a member, precede its declaration with the keyword static. When a member is declared static, it can be accessed before any objects of its class are created, and without reference to any object. You can declare both methods and variables to be static. The most common example of a static member is main (). Main () is declared as static because it must be called before any object exists.
Q59. What are restrictions of static methods?
Ans. The can only call others static methods.
They must only access static data
They cannot refer to this or super in any way.
Q60. What is difference between interface and class?
Ans. Through the use of interface keyword, Java allows you to fully abstract the interface from its implementation. That is, using interface you can specify what a class must do but not how it does it. Interfaces are syntactically similar to classes, but they lack instance variable, and their methods are declared without any body.
Q61. What are interfaces in java?
Ans. An interface is a contract in the form of a collection of method and constant declarations. When a class implements an interface, it promises to implement all of the methods declared in that interface. Interfaces are useful for capturing similarities among unrelated classes without artificially forcing a class relationship, declaring methods that one or more classes are expected to implement and revealing an object's programming interface without revealing its class. Java uses ‘interface’ and ‘abstract Class’ to define interfaces.
Q62. What are methods in java?
Ans. When you create a class, you will specify the code and date that constitute that class. Collectively these elements are called members of the class. Specifically, the data defined by the class are referred to as member variables and the code that operates on that data is called as a member method or simply method.
Q63. How does String classes differ from StringBuffer class?
Ans. A Java string in an instantiated object of the string class. String Buffer is a peer class of string. While string creates strings of fixed length, string Buffer creates strings of flexible length that can be modified in terms of both length and content. We can insert characters and sub-strings in the middle of string, or append another string to the end.
Q64. What is HTML?
Ans. HTML is the synonym for Hyper Text Markup Language. HTML is used to create static web pages. HTML uses tags to create web pages.
Ans. Canvas class and graphics class both are used for drawing purpose. Canvas encapsulates a blank window upon which you can draw. This class contains methods for drawing strings, lines, rectangles and other shapes defined in the graphics class, which is a part of the java.awt package.
Ans. An applet is a Java program that runs within the Java enabled web browsers like Netscape Communicator and Internet explorer. Applets often use a graphical user interface and may have text, images, buttons, scrollbars, and sound. Applets can be embedded in HTML.
It is automatically executed by applet-enabled we-browser. Every applet is a subclass of java.applet.Applet. Applet init() method is called exactly once in its life cycle i.e. when it is loaded. Start() is called each time the browser visits he page. Stop() is called when browser leaves the page. Destroy() is called when browser unloads the applet.
No, Applet does not have constructors.
Q67. What is JAVA API?
Ans. The Java Application Programming Interface (API) is prewritten code, organized into packages of similar topics. For instance, the Applet and AWT packages include classes for creating fonts, menus, and buttons. Having Java API in your environment is a pre-requisite of writing and compiling java program.
Sun Microsystems’s J2SE comes bundled with the compiler, a runtime environment, and core API. Before you can develop an application written in the Java programming language, you will need the Java 2 Platform Standard Edition (J2SE) development kit. JESE 5.0 is the most current version of J2SE.
Q68. What is an Applet?
Ans. An applet is a Java program that runs within the Java enabled web browsers like Netscape Communicator and Internet explorer. Applets often use a graphical user interface and may have text, images, buttons, scrollbars, and sound. Applets can be embedded in HTML.
It is automatically executed by applet-enabled we-browser. Every applet is a subclass of java.applet.Applet. Applet init() method is called exactly once in its life cycle i.e. when it is loaded. Start() is called each time the browser visits he page. Stop() is called when browser leaves the page. Destroy() is called when browser unloads the applet.
Q69. What advantages do Java’s layout provides over traditional windowing system?
Ans. Advantages of java layout over windowing system
Java provides different types of layout to arrange and place the component in windows applet/application.
It helps to manage component in window
It helps to hide or unhide components in window
It helps to use more than one container in same window
It helps to manage different container differently in same window
Q70. How does try statement determine which catch clause should be used to handle an exception?
Ans. Try statement checks the type of error is generated by the try block and compare it with all the provided catch block and determine which catch clause will executes.
Q71. What is the use of getDocumentBase() and getCodeBase() methods?
Ans. Java provides the facility to applet to load data from the directory holding the HTML file that started the applet and the directory from which the applet’s class file was loaded. These directory are returned as URL objects by getDocumentBase() and getCodeBase() method.
Ans. ActionEvent, ContainerEvent, FocusEvent, ComponentEvent, InputEvent, ItemEvent, KeyEvent, MouseEvent, TextEvent, WindowEvent
Q73. What is a package?
Ans. The packages are containers for classes that are used to keep the class name spice compartmentalized. Packages are stored in a hierarchical manner and are explicitly imported into new class definitions. To create a package includes package command as the first statement in Java source file. The package statement defines a name space in which classes are stored. If you omit the package statement the class names are put into the default package, which has no name.
Q74. Why do applet classes needed to be declared as public?
Ans. The applet classes are declared as public because they are to be called outside the package. And any class required outside package must be declared as public.
Q75. How do you compile and run applet?
Ans. To compile an applet the javac appletname command is used.
To run the applet appletviewer command is used.
Q76. Is it necessary to catch all type of exception?
Ans. Yes, it is necessary to catch all type of exception to get accurate result from the program. Although there is an exception that we can’t handle is StackOverflow exception in our program.
Q77. Identify correctly constructed package declarations, import statements, and method declarations.
Ans. package packagename; is correct package declaration
import packagename.*; or import packagename.Classname ; is the correct import statement.
public /private methodname([argumentlist]) is correct declaration for methods.
Q78. Explain the five rules for using across attributes.
Ans. 1. Public data is defined by public keyword so that it can be used by any package.
2. To defined private data private keyword is used so that data can not be used outside the class.
3. Default Access specification need not to be defined with any data type.
4. To define protected members so that these members of the class can be extended by the subclasses of same and different packages.
Q79. What are exceptions in java?
Ans. Exceptions in java are used to handle errors. All the exceptions in java extends Exception Class.
Q80. How an Image can be loaded on the Applet window?
Ans. To load the Image on the Applet window the getImage method is defined by the applet class. It has the following forms.
Image getImage(URL url);
Image getImage(URL url, String imageName)
Ans. Component is an abstract class that encapsulates all of the attributes of a visual component- All user interface elements that are displayed on the screen and that interact with user.
Container classes provide container to the components where we can place different Components. All the Containers like window, panel, Frame, all are the sub classes of container class.
Ans. The panel class is a concrete subclass of container. It doesn’t add any new methods. It simply implements container. Panel is the subclass of applet. When screen output is directed to an applet, it is drawn on the surface of a panel object. Panel is a window that does not contain a title bar, menu bar, or border.
Ans. The repaint method is defined by the AWT. It causes the AWT runtime system to execute a call to your applet’s update() method. Which is, in default implementation, calls paint().
Q84. What do you mean by applet viewer?
Ans. An applet viewer executes your applet in a window. This is generally the fastest
and easiest way to test your applet. Using an applet viewer, such as the standard JDK tool, appletviewer.
9 docs|1 tests
|
1. What are some important topics to prepare for a Core Java viva or interview? |
2. How can I prepare for a Core Java viva or interview? |
3. What are some frequently asked questions in a Core Java interview? |
4. What is the significance of the Java collections framework in Core Java? |
5. How does Java handle exceptions and errors? |
|
Explore Courses for Software Development exam
|