Search This Blog

Loading...

Thursday, August 11, 2011

Quick Revise: Java OOP's Concepet


*******************Brushup: Exception Handling ***************

Q 1. Which package has the Exception handling related classes ?

Java.lang



Q 2. What are the two types of Exceptions ?

Checked & Unchecked



Q 3. What is the base class of all Exceptions ?

Throwable






Q 4. What is the difference between Exception and Error in java ?

Answer was given in my previous mail



Q 5. What is the difference between throw and throws?

Answer was given in my previous mail



Q 6. Differentiate between Checked Exceptions and Unchecked Exceptions?

Answer was given in my previous mail



Q 7. What are User defined Exceptions?

We can write our own exception class by extending Exception and based on certain condition we can throw this user defined exception in our program.



Q 8. Can a catch block exist without a try block?

No



Q 9. Can a finally block exist with a try block but without a catch?

Yes



Q 10. What will happen to the Exception object after exception handling?

It will be garbage collected



Q 11. The subclass exception should precede the base class exception when used within the catch clause. True/False?

True



Q 12. The statements following the throw keyword in a program are not executed. True/False?

True



Q 13. How does finally block differ from finalize() method?

finally -The finally block is optional and provides a mechanism to clean up regardless of what happens within the try block (except System.exit(0) call). Use the finally block to close files or to release other system resources like database connections, statements etc.

finalize() - method helps in garbage collection. A method that is invoked before an object is discarded by the garbage collector, allowing it to clean up its state. Should not be used to release non-memory resources like file handles, sockets, database connections etc. because Java has only a finite number of these resources and you do not know when the garbage collection is going to kick in to release these non-memory resources through the finalize() method.



Q 14. What are the constraints imposed by overriding on exception handling?

An overriding method in a subclass may only throw exceptions declared in the parent class or children of the exceptions declared in the parent class.

************************************************************************************

Tuesday, August 9, 2011

Core Java: Miscellaneous OOP's concepet in java

*********** First 1. **************

// Q. 1) What will be the output ?
public class Hello1 {

public static void main (String args[]) {

System.out.println (A.a);
System.out.println (B.b);
}

}

// Q. 2) Why static block of class 'A' doesn't execute ?
// Q. 3) Why class 'A' doesn't load when we access the final variable 'a' ?
class A {

static {
System.out.println ("Hi, This is static block of class 'A' !!!!");
}

public static final int a = 100;
}

// Q. 4) Shall the following class 'B' compile successfully, Why?
class B {

static {
System.out.println ("Hi, This is static block of class 'B' !!!!");
b = 200;
}

public static final int b;
}

*******************************************************************

The meaning of AAA rating for countries ???


What is a credit rating?


A credit rating is an opinion of the general creditworthiness of individuals, companies and countries. Lower credit ratings result in higher borrowing costs because the borrower is deemed to carry a higher risk of default. A downgrade for America would mean US bond investors would want to get paid more to compensate for the risk of holding government debt.



What are sovereign credit ratings?


Sovereign credit ratings measure the risk of investing in countries – political as well as economic risk. For instance, Standard & Poor's lowered its AAA credit rating for the US government partly because the talks that led to last week's deal on hiking the borrowing limit "took too long" and were "at times too divisive".



What is the role of credit rating agencies?

Credit rating agencies assess the risk of investing in corporations and governments. The largest are Moody's, Standard and Poor's and Fitch Ratings. They also provide a wide array of financial data and information on bonds, equities and mutual funds.


How do they make money?

Agencies typically receive payment for their services either from the borrower that requests the rating or from subscribers who receive the published ratings and related credit reports.


How much weight does a rating carry?

A lot of investment, such as corporate and government bonds, must carry a credit rating. This has resulted in credit rating agencies becoming very influential. However, their role in the sub-prime crisis, when they rated various mortgage-backed financial instruments that have subsequently been branded "toxic", has damaged their reputation.


What do Standard and Poor's "letter" ratings mean?

AAA - Extremely strong capacity to meet financial commitments. Highest rating
AA - Very strong capacity to meet financial commitments
A - Strong capacity to meet financial commitments, but somewhat susceptible to adverse economic conditions and changes in circumstances
BBB - Adequate capacity to meet financial commitments, but more subject to adverse economic conditions
BBB- (minus) - this is the lowest rating before non-investment grade
BB: Less vulnerable in the near-term but faces major ongoing uncertainties to adverse business, financial and economic conditions
B: More vulnerable to adverse business, financial to meet financial commitments
CCC: Currently vulnerable and dependent on meet financial commitments
CC: Currently highly vulnerable
C: A bankruptcy petition has been filed or similar continued
D: Payment default on financial commitments

Ratings in the 'AAA,' 'AA,' 'A' and 'BBB' categories are regarded by the market as investment grade.

Ratings in the 'BB,' 'B,' 'CCC,' 'CC' and 'C' categories are regarded as having significant speculative characteristics.

Ratings from 'AA' to 'CCC' may be modified by the addition of a plus (+) or minus (-) sign to show relative standing within the major rating categories.

NR indicates that no rating had been requested, there is insufficient information on which to base a rating, or that S&P does not rate a particular obligation as a matter of policy.

What is an outlook definition?

An S&P rating outlook assesses the potential direction in which a rating will move over the next six months to two years.
Positive - may be raised
Negative - may be lowered
Stable - unlikely to change
Developing - may be raised or lowered
NM - not meaningful

Thursday, June 23, 2011

Java Interview Questions

OOPS


1. What is an Object?

2. What is a Class?

3. What is OOAD?

4. What is Data Abstraction ?

5. What is Data Encapsulation?

6. What is the difference between Data Abstraction and Information Hiding?

7. What is Inheritance and what are different types of it?

8. Why Java uses Singly rooted hierarchy?

9. Why does Java not support Multiple Inheritance?

10. Why is Java not 100% pure OOP language?

11. What is Early Binding?

12. What is Polymorphism/Late Binding?

13. What is method overloading?

14. What is method overriding?

15. How is Java different from C++?

16. What is UML and how is it useful in designing large systems?

17. Is UML useful for procedural programming ?

18. What are different notations used in UML ?

19. What is a Use case and an Actor?

20. How to identify an Actor?

21. What is Generalization?

22. What is Association and how it maps into a Java class?

23. What is Aggregation and how it maps into a Java class?

24. What is Composition and how it maps into a Java class?

25. What is Dependency and how it maps into a Java class?

26. What is the purpose of State machine diagrams?

27. What are different kinds of Structure diagrams?

28. What are different kinds of Interaction diagrams?

29. What are different kinds of Behavior diagrams?
--------------------------------------------------------------------------------


Java Fundamentals


30. What is a Java Virtual Machine (JVM)?

31. What is a JVM consisted of?

32. What is a class loader and what is its responsibilities?

33. What is heap and stack?

34. How is your Java program executed inside JVM?

35. What is Java class file's magic number?

36. How JVM performs Thread Synchronization?

37. How JVM performs Garbage Collection?

38. How to profile heap usage?

39. What will you do if VM exits while printing "OutOfMemoryError" and increasing max heap size doesn't help?

40. Should one pool objects to help Garbage Collector?Should one call System.gc() periodically?

41. An application has a lot of threads and is running out of memory, why?

42. If your program is I/O bound or running in native methods, do these activities engage JVM?

43. What is the difference between interpreted code and compiled code?

44. Why Java based GUI intensive program has performance issues?

45. What is 64 bit Java ?

46. What is the difference between JVM and JRE?

47. What are different primitive datatypes in Java?

48. What are expressions,statements and blocks in Java?

49. What is a transient variable?

50. What is the difference between the '&' operator and the '&&' operator?

51. Why main method of Java has public static void?

52. If you have static block, constructor and main method in Java file then what will be the sequence of method calls?

53. What are the command line arguments?

54. Does Java support multi dimensional arrays?

55. What are the restrictions for static method?

56. Why a abstract method cannot be static?

57. Is 'sizeof' a keyword?

58. What is the precedence of operators in Java?

59. How is an argument passed in Java methods?

60. What is the difference between class variable, member variable and automatic(local) variable?

61. When are static and non static variables of a class initialized?

62. Can shift operators be applied to float types?

63. What are different Java declarations and their associated rules?

64. What are Java Modifiers?

65. Explain final modifier.

66. Can you change the reference of the final object?

67. Can abstract class be instantiated?

68. When does the compiler insist that the class must be abstract?

69. Where can static modifiers be used?

70. What is static initializer code?

71. Can an anonymous class implement an interface and extend a class at the same time?

72. What are volatile variables?

73. Can protected or friendly features be accessed from different packages?

74. How many ways can one write an infinite loop?

75. When do you use 'continue' and 'break' statements?

76. What is the difference between 'while' and 'do while' loop?

77. What is an Assertion and why using assertion in your program is a good idea ?

78. Explain Assertions with a code exmaple.

79. How many forms of assertions we have?

80. When assertions should be avoided?

81. What situations are best suitable for implementing assertions?

82. What is Exception ?

83. What is a user-defined exception?

84. What do you know about the garbage collector?

85. Why Java does not support pointers?

86. Does garbage collection guarantee that a program will not run out of memory?

87. What is finally in Exception handling?

88. What can prevent the execution of the code in finally block?

89. Explain 'try','catch' and 'finally' blocks?

90. Define Checked and Unchecked exception.

91. What is the difference between an abstract class and an interface?

92. What is the use of interface?

93. What is serializable interface?

94. Does a class inherit constructors from its superclass?

95. What's the difference between constructors and other methods?

96. If the method to be overridden has access type 'protected', can subclass have the access type as 'private'?

97. If you use super() or this() in a constructor where should it appear in the constructor?

98. What modifiers may be used with an inner class that is a member of an outer class?

99. Can an inner class be defined inside a method?

100. What is an anonymous class?

101. What is a thread?

102. What is the difference between process and threads?

103. What are two types of multitasking?

104. What are two ways of creating threads in Java and why so?

105. How does multithreading take place on a computer with a single CPU?

106. How a Java object be locked for exclusive use by a given thread?

107. What is Synchronization?

108. Explain wait(),notify(), and notifyAll() methods?

109. What is a Daemon thread?

110. How a dead thread can be started?

111. What is the difference between String and StringBuffer?

112. How is '==' different from .equals() method in case of String objects?

113. Explain StreamTokenizer?

114. What is Collection?

115. Explain List,Set and Map.

116. What is the serialization?

117. What is the difference between Serializable and Externalizable interface?

118. What is memory leak?

119. Difference between ArrayList and Vector class?

120. What is the difference between Hashtable and HashMap?

121. What is JFC?

122. What is the difference between JFC Swing and AWT?

123. What is the base class for all swing components?

124. What are lightweight and heavyweight components ?

125. How can a GUI component handle its own events?

126. What is a Layout Manager and what are its different types and their advantages?

127. How are the elements of a GridBagLayout organized?

128. What are the problems faced by Java programmers in absence of layout managers?

129. Where the CardLayout is used?

130. What is the difference between GridLayout and GridBagLayout?

131. How will you add a panel to a frame?

132. What is the difference between Application and Applet?

133. Explain Lifecycle of the Applet and what is the order of method invocation in an applet?

134. What is the difference between Java class and bean?

135. What is difference between trusted and untrusted applet?

136. How do you set Java Library path programmatically?(new)


137. Explain the usage of java.util.Date and more classes and APIs for date handling in Java?(new)

------------------------------------------------------------------------------------

JDBC


138. What is JDBC ?

139. What are four drivers available in JDBC?

140. How do you establish database connection using JDBC?

141. What are the different types of Statements?

142. What is PreparedStatement and how is different from Statement?

143. What is the difference between executeQuery () and execute() ?

144. What is the difference between executeQuery () and executeUpdate()?

145. How do you call a stored procedure in Java?

146. What are new features from JDBC2.0 onwards?

147. How can a cursor move in scrollable result sets?

148. Differentiate TYPE_SCROLL_INSENSITIVE and TYPE_SCROLL_SENSITIVE?

149. How will you differentiate the following two ways of loading a database driver?

150. How can you display a particular web page from an applet?(new)

151. How can you get the hostname on the basis of IP addres ?(new)

152. How can you get an IP address of a machine from its hostname?(new)

153. How do you know who is accessing your server?(new)

154. What are different socket options?(new)

155. What should I use a ServerSocket or DatagramSocket in my applications?(new)


Note: Don't remember the answer of these question but try ti have the concept then you can see the magic while interview.

Thursday, June 16, 2011

Java: Object Class

Class Object

java.lang.Object


public class Object

a) Class Object is the root of the class hierarchy.
b) Every class has Object as a superclass.

Methods:

clone() : Creates and returns a copy of this object.

equals(Object obj) : Indicates whether some other object is "equal to" this one.

finalize() : Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

getClass() : Returns the runtime class of an object.

hasCode() : Returns a hash code value for the object.

notify() : Wakes up a single thread that is waiting on this object's monitor.

notifyAll() : Wakes up all threads that are waiting on this object's monitor.

toString() : Returns a string representation of the object.

wait() : Causes current thread to wait until another thread invokes the notify() method or the notifyAll() method for this object.

Tuesday, June 14, 2011

Struts / Java / J2EE Frequently-Asked Interview Questions

1. Are Struts's action classes Thread-safe?
Yes. Action classes are based on "one-instance and many-threads". This is to conserve resources and to provide the best possible throughput.


2. What are the various Struts Tag libraries?
There are various struts tags. But the most-repeated tags are:
struts-bean.tld
struts-html.tld
struts-logic.tld
struts-nested.tld

3. What is ActionMapping in struts?
Action mapping defines the flow of one request. The possible sequence is
User -> request -> Form -> Validation -> Business Code -> Forward -> JSP -> response -> User.
The components involved are Action classes, Forms and JSP.


4. What are the advantages of having multiple struts-config in the same application?
The implementation with many struts-config is to organize the development work, so that many people may be involved and it is some organized way of doing things. But this would result in some compromise in performance(speed). Technically there is no any difference between single and multiple struts-config files.


5. What are the ways in which resource file can be used in struts?
Defining message resources in struts-config file.
Programmatically using resource files in Java classes or in JSP files.


6. Explain the term 'architecture of the application'?
Architecture is the set of rules (or framework) to bring in some common way of assembling or using J2EE components in the application. This helps in bringing consistency between codes developed by various developers in the team.


7. Which is the architecture followed by struts?
Struts follows MVC architecture.


8. What are components corresponding o M, V and C in struts?

Model : The model represents the data of an application. Anything that an application will persist becomes a part of model. The model also defines the way of accessing this data ( the business logic of application) for manipulation. It knows nothing about the way the data will be displayed by the application. It just provides service to access the data and modify it. Here 'Form Bean' represents Model layer.

View : The view represents the presentation of the application. The view queries the model for its content and renders it. The way the model will be rendered is defined by the view. The view is not dependent on data or application logic changes and remains same even if the business logic undergoes modification. JSP represents View Layer.

Controller : All the user requests to the application go through the controller. The controller intercepts the requests from view and passes it to the model for appropriate action. Based on the result of the action on data, the controller directs the user to the subsequent view. Action classes (action servlets) represent Controller layer.


9. Differentiate between the terms 'Design Patterns', 'Framework' and 'Architecture'.
Design Pattern: The various solutions arrived at for the known problem. This helps to avoid re-inventing the wheel. The risk-free solution can be easily used by others. For example, singleton is the design pattern that you can use instantly to enfore one object per class. You do not need to think of this on your own.
Framework: A framework is a structure or set of rules, used to solve or address complex issues. It is basically a reusable designf for the J2EE applications. For example, Struts, JSF,etc., are the frameworks. You can use these frameworks based on the requirements of your application and each has its own set of advantages.

Architecture: It is a design that describes how the various components in the application fit together. For example, MVC is an architecture which is helpful to define how the components interact within the application.



10. What is the difference between ActionForm and DynaActionForm?
In action form, you need to define the form class that extends ActionForm explicitly, whereas you can define the form dynamically inside the struts-config file when using DynaActionForm.


11. How can you use Validator framework in struts?
Validator Frameworks are helpful when the application needs server-side validation such that the particular set of validations occur very frequently within the same application. This avoids writing complex code in validation() method in every form bean. Using validator framework, there are different pre-written validations in place. You can customize these validations in XML file.


12. What are client-side and server-side vaidations?
Client-side validations: These are the validations that id done using javascripts. There is always a danger involved that the user can get through (crack-through) these validations. But for some simple validations, like converting lower-case to upper-case or date validations can be done, you can use javascripts.
Server-side validations: These are the validations done in server-side using Java components (Form bean or in business logics) where the user has no chance to crookedly get through the system.


13. What are the advantages & differences between using validate() method in form over validations using validator framework.
Refer to the previous-answer.


14. Define the terms authentication and authorisation.
Authentication is the process/rule that validates if the user is allowed to access the system or not.
Authorization is the process/rule that validates if the user is allowed to access the particular part of the system or not. This occurs after user's successful authentication.


15. What are the components provided in J2EE to perform authentication and authorization?
Authentication – RequestProcessor and/or Filter.
Authorization - DTO, JDO or Java or Action classes.


16. Give the difference between between 'DispatchAction' and 'Action'.
A DispatchAction contains various different methods other than the standard execute() method in Action classes. These methods are executed based on some request parameter. For example, you can code in such a way that three buttons (namely Insert, Delete, Update) buttons correspond to different methods such as insert(), delete() and udpate(). The submit button in JSP would have the property that has the value which matches to any one of the methods defined in DispatchAction class.


17. What is pagination technique? How can you design them in struts?
Pagination is the technique where the bulk of results are split into different pages and only the information where the user can conveniently see are displayed in a page. (Like in Goooooogle). This can be achieved in many ways, but the simplest method is to have a query string (say http://www.testwebsite?pageNumber=2) would lead to information corresponding to resultset rows from 11 to 20. Assuming that you want to display 10 related rows of information, you can set the formula as follows:
Starting row = (pageNumber-1) * + 1 which is equal to 11.
Ending row = Starting row + which is equal to 20.


18. How can you populate the drop-down list using form properties?
There are many ways for this. But the best method is to use which defines collection that needs to be used to populate the drop-down list, the property to store the selected value and the collection that is used to display the labels (what we see in JSP page). For Example,

html:options collection="form-collection-property"
property="form-property"
labelProperty="form-another-collection-property"


19. What is the XML parser provided in struts? Can you use it for other purposes?
'Digester' framework. Yes we can use for our applications to store and parse our application-related data.


20. Difference between Struts 1.0 and 1.1

* Perform() method was replaced by execute()
* DynaActionForms are introduced.
* Tiles Concept is introduced
* We can write our own Controller by Inheriting RequestProcessor

Friday, June 10, 2011

Java Classes and Objects Interview Questions

Q1. What restrictions are placed on method overloading?

Two methods may not have the same name and argument list but different return types.


Q2. What is the difference between String and StringBuffer?

String objects are immutable whereas StringBuffer objects are not. StringBuffer unlike Strings support growable and modifiable strings.


Q3. Can a private method of a superclass be declared within a subclass?

Sure. A private field or method or inner class belongs to its declared class and hides from its subclasses.
There is no way for private stuff to have a runtime overloading or overriding (polymorphism) features.


Q4. What is the default value of an object reference declared as an instance variable?

null unless we define it explicitly.


Q5. What is the difference between a constructor and a method?

Or

How can a subclass call a method or a constructor defined in a superclass?

A constructor is a member function of a class that is used to create objects of that class, invoked using the new operator. It has the same name as the class and has no return type. They are only called once, whereas member functions can be called many times. A method is an ordinary member function of a class. It has its own name, a return type (which may be void), and is invoked using the dot operator. Constructor will be automatically invoked when an object is created whereas method has to be called explicitly.

super.method(); is used to call a super class method from a sub class. To call a constructor of the super class, we use the super(); statement as the first line of the subclass’s constructor.


Q6. Can a top-level class be private or protected?

No. A top-level class cannot be private or protected. It can have either "public" or no modifier. If it does not have a modifier it is supposed to have a default access. If a top level class is declared as private/protected the compiler will complain that the "modifier private is not allowed here”.


Q7. Why Java does not support multiple inheritance?

Java does support multiple inheritance via interface implementation.


Q8. Where and how can you use a private constructor?

Private constructor can be used if you do not want any other class to instantiate the class. This concept is generally used in Singleton Design Pattern. The instantiation of such classes is done from a static public method.


Q9. How are this() and super() used with constructors?

this() is used to invoke a constructor of the same class. super() is used to invoke a superclass constructor.


Q10. What is Method Overriding? What restrictions are placed on method overriding?

When a class defines a method using the same name, return type, and argument list as that of a method in its superclass, the method in the subclass is said to override the method present in the Superclass. When the method is invoked for an object of the
class, it is the new definition of the method that is called, and not the method definition from superclass.
Restrictions placed on method overriding
• Overridden methods must have the same name, argument list, and return type.
• The overriding method may not limit the access of the method it overrides. Methods may be overridden to be more public, not more private.
• The overriding method may not throw any exceptions that may not be thrown by the overridden method.


Q11. What are the Object and Class classes used for? Which class should you use to obtain design information about an object?

Differentiate between a Class and an Object?

The Object class is the highest-level class in the Java class hierarchy. The Class class is used to represent the classes and interfaces that are loaded by a Java program. The Class class is used to obtain information about an object's design. A Class is only a definition or prototype of real life object. Whereas an object is an instance or living representation of real life object. Every object belongs to a class and every class contains one or more related objects.


Q12. What is a singleton class?

Or



Q13. What is singleton pattern?

This design pattern is used by an application to ensure that at any time there is only one instance of a class created. You can achieve this by having the private constructor in the class and having a getter method which returns an object of the class and creates one for the first time if its null.


Q14. What is method overloading and method overriding?

Or

What is difference between overloading and overriding?

Method overloading: When 2 or more methods in a class have the same method names with different arguments, it is said to be method overloading. Overloading does not block inheritance from the superclass. Overloaded methods must have different method signatures

Method overriding : When a method in a class has the same method name with same arguments as that of the superclass,
it is said to be method overriding. Overriding blocks inheritance from the superclass. Overridden methods must have same signature.

Basically overloading and overriding are different aspects of polymorphism.

static/early binding polymorphism: overloading
dynamic/late binding polymorphism: overriding

If a class is declared without any access modifiers, where may the class be accessed?

A class that is declared without any access modifiers is said to have package or default access. This means that the class can only be accessed by other classes and interfaces that are defined within the same package.


Q15. Does a class inherit the constructors of its superclass?

A class does not inherit constructors from any of its super classes.


Q16. Which java.util classes and interfaces support event handling?

The EventObject class and the EventListener interface support event processing


Q17. Can an object's finalize() method be invoked while it is reachable?

An object's finalize() method cannot be invoked by the garbage collector while the object is still reachable. However, an object's finalize() method may be invoked by other objects.


Q18. What is the purpose of the Runtime class?

The purpose of the Runtime class is to provide access to the Java runtime system.

It returns the runtime information like memory availability.

* Runtime.freeMemory() --> Returns JVM Free Memory
* Runtime.maxMemory() --> Returns the maximum amount of memory that the JVM will attempt to use. It also helps to run the garbage collector
* Runtime.gc()


Q19. What is the purpose of the System class?

The purpose of the System class is to provide access to system resources.


Q20. Can an unreachable object become reachable again?

An unreachable object may become reachable again. This can happen when the object's finalize() method is invoked and the object performs an operation which causes it to become accessible to reachable object.


Q21. What is a bean? Where can it be used?

A Bean is a reusable and self-contained software component. Beans created using java take advantage of all the security and platform independent features of java. Bean can be plugged into any software application. Bean is a simple class which has set and get methods. It could be used within a JSP using JSP tags to use them.


Q22. What is the functionality of instanceOf() ?
instanceOf opertaor is used to check whether an object can be cast to a specific type without throwing ClassCastException.


Q23. What would happen if you say this = null?

It will come up with Error Message

"The left-hand side of an assignment must be a variable".

I want to create two instances of a class ,But when trying for creating third instance it should not allow me to create . What i have to do for making this?

One way of doing this would be:

public class test1

{

static int cntr=0;

test1()

{ cntr++;

if(cntr>2)

throw new NullPointerException();//u can define a new exception // for this

}

public static void main(String args[])

{

test1 t1= new test1();

System.out.println("hello 1");

test1 t2= new test1();

System.out.println("hello 2");

test1 t3= new test1();

}

}


Q24. What is the difference between an object and an instance?

An Object May not have a class definition. eg int a[] where a is an array.

An Instance should have a class definition.

eg MyClass my=new MyClass();

my is an instance.


Q25. What is heap in Java?

It is a memory area which stores all the objects created by an executing program.


Q26. Why default constructor of base class will be called first in java?

A subclass inherits all the methods and fields (eligible one) from the base class, so base class is constructed in the process of creation of subclass object (subclass is also an object of superclass). Hence before initializing the default value of sub class the super class should be initialized using the default constructor.


Q27. What are the other ways to create an object other than creating as new object?

We can create object in different ways;

1.new operator

2.class.forName: Classname obj = Class.forName("Fully Qualified class Name").newInstance();

3.newInstance

4.object.clone



Q28. What is the difference between instance, object, reference and a class?

Class: A class is a user defined data type with set of data members & member functions

Object: An Object is an instance of a class

Reference: A reference is just like a pointer pointing to an object

Instance: This represents the values of data members of a class at a particular time