My Hindi Forum

Go Back   My Hindi Forum > New India > Young World
Home Rules Facebook Register FAQ Community

Reply
 
Thread Tools Display Modes
Old 23-12-2009, 06:18 AM   #21
masterstroke
Member
 
masterstroke's Avatar
 
Join Date: Dec 2009
Posts: 33
Rep Power: 0
masterstroke is on a distinguished road
Post Do I need to import java.lang package any time? Why?

No. It is by default loaded internally by the JVM. The java.lang package is always imported by default.
masterstroke is offline   Reply With Quote
Old 23-12-2009, 06:18 AM   #22
masterstroke
Member
 
masterstroke's Avatar
 
Join Date: Dec 2009
Posts: 33
Rep Power: 0
masterstroke is on a distinguished road
Smile Can I import same package/class twice? Will the JVM load the package twice at runtime

One can import the same package or same class multiple times. Neither compiler nor JVM complains anything about it. And the JVM will internally load the class only once no matter how many times you import the same class.
masterstroke is offline   Reply With Quote
Old 23-12-2009, 06:20 AM   #23
masterstroke
Member
 
masterstroke's Avatar
 
Join Date: Dec 2009
Posts: 33
Rep Power: 0
masterstroke is on a distinguished road
Smile Does importing a package imports the sub packages as well?

Does importing com.abhi.* also import com.abhi.pgr.*?

No you will have to import the sub packages explicitly. Importing com.abhi.* will import classes in the package abhi only. It will not import any class in any of its sub packages.
masterstroke is offline   Reply With Quote
Old 23-12-2009, 06:20 AM   #24
masterstroke
Member
 
masterstroke's Avatar
 
Join Date: Dec 2009
Posts: 33
Rep Power: 0
masterstroke is on a distinguished road
Smile Explain the usage of Java packages.

A Java package is a naming context for classes and interfaces. A package is used to create a separate name space for groups of classes and interfaces.

Packages are also used to organize related classes and interfaces into a single API unit and to control accessibility to these classes and interfaces.

For example: The Java API is grouped into libraries of related classes and interfaces; these libraries are known as package.
masterstroke is offline   Reply With Quote
Old 23-12-2009, 06:21 AM   #25
masterstroke
Member
 
masterstroke's Avatar
 
Join Date: Dec 2009
Posts: 33
Rep Power: 0
masterstroke is on a distinguished road
Smile Are the imports checked for validity at compile time?

e.g. will the code containing an import such as java.lang.abhi compile?

Yes the imports are checked for the semantic validity at compile time. The code containing above line of import will not compile. It will throw an error saying, cannot resolve symbol.
masterstroke is offline   Reply With Quote
Old 23-12-2009, 06:24 AM   #26
masterstroke
Member
 
masterstroke's Avatar
 
Join Date: Dec 2009
Posts: 33
Rep Power: 0
masterstroke is on a distinguished road
Smile 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.
masterstroke is offline   Reply With Quote
Old 25-12-2009, 07:01 AM   #27
sunita
Member
 
sunita's Avatar
 
Join Date: Dec 2009
Posts: 64
Rep Power: 15
sunita is on a distinguished road
Smile What is the default value of an object reference declared as an instance variable?

null unless we define it explicitly.
sunita is offline   Reply With Quote
Old 25-12-2009, 07:01 AM   #28
sunita
Member
 
sunita's Avatar
 
Join Date: Dec 2009
Posts: 64
Rep Power: 15
sunita is on a distinguished road
Smile What is the difference between a constructor and a method?

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 constructor.
sunita is offline   Reply With Quote
Old 25-12-2009, 07:03 AM   #29
sunita
Member
 
sunita's Avatar
 
Join Date: Dec 2009
Posts: 64
Rep Power: 15
sunita is on a distinguished road
Post Does Java support multiple inheritance?

Java does support multiple inheritance via interface implementation.
sunita is offline   Reply With Quote
Old 25-12-2009, 07:03 AM   #30
sunita
Member
 
sunita's Avatar
 
Join Date: Dec 2009
Posts: 64
Rep Power: 15
sunita is on a distinguished road
Smile 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.
sunita is offline   Reply With Quote
Reply

Bookmarks

Tags
java interview question


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



All times are GMT +5. The time now is 01:58 PM.


Powered by: vBulletin
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
MyHindiForum.com is not responsible for the views and opinion of the posters. The posters and only posters shall be liable for any copyright infringement.