java4all@1986 java. Powered by Blogger.

How to add Facebook like button in Your blog?

>> Wednesday, May 25, 2011

First Step: Go to your blog Account .Click on Dashboard icon.

SecondStep: Click on the design icon,now you will get a new page like ARRANGE ELEMENTS,In this section click on EDIT\HTML icon.

ThirdStep: On your keyboard Press ctrl+f and paste <data:post.body/> find it on your template.
Fourth Step:Paste the below code after or before the  <data:post.body/>.Then  Save the template automatically you will get the share button

Code:
 <script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><fb:like layout="standard" show_faces="false" width="350" action="like" colorscheme="light"></fb:like>

Read more...

CORE JAVA INTERVIEW QUESTIONS AND ANSWERS

Q:)What is meant by Checked Exception and Unchecked Exception?
A: CHECKED EXCEPTION:Checked Exception are exception which was raised by the compiler by compilation time.EX:Servelt Exception and  IO Exception.
  UNCHECKED EXCEPTION:Unchecked Exception are the exception which were raised by JVM at runtime .EX:Runtime Exceptions.

Q:)What is difference between Partial Checked Exception and Fully Checked Exception?
A:PARTIAL CHECKED EXCEPTION:This are the Exception if and only if some of it's child classes are Checked partially.
   FULL CHECKED EXCEPTION:This are the Exception if and only if  all it's child classes are  FULL Checked.

Q:What is Overriding?
A:When a class defines a method using the same name, return type, and arguments as a method in its superclass,
the method in the class overrides the method 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.
Methods may be overridden to be more public, not more private..


 
Q:What type of parameter passing does Java support?
A:In Java the arguments are always passed by value .

Q: Can a top level class be private or protected?
A: No. A top level class can not 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 the compiler will complain that the "modifier private is not allowed here". This means that a top level class can not be private. Same is the case with protected.                      
Q:How do I serialize an object to a file?
A:The class whose instances are to be serialized should implement an interface Serializable.
Then you pass the instance to the ObjectOutputStream which is connected to a fileoutputstream.
This will save the object to a file.

 
Q: Which methods of Serializable interface should I implement?
A: The serializable interface is an empty interface, it does not contain any methods. So we do not implement any methods.
    
Q:How can I customize the seralization process? i.e. how can one have a control over the serialization process?
A:Yes it is possible to have control over serialization process. The class should implement Externalizable interface.
This interface contains two methods namely readExternal and writeExternal.
You should implement these methods and write the logic for customizing the serialization process.



Q:What happens to the static fields of a class during serialization?
A:There are three exceptions in which serialization doesnot necessarily read and write to the stream. These are
1. Serialization ignores static fields, because they are not part of ay particular state state.
2. Base class fields are only handled if the base class itself is serializable.
3. Transient fields.


  
Q:Does Java provide any construct to find out the size of an object?
A:No there is not sizeof operator in Java. So there is not direct way to determine the size of an object directly in Java.
     
   

Q:Give a simplest way to find out the time a method takes for execution without using any profiling tool?
A:Read the system time just before the method is invoked and immediately after method returns.
Take the time difference, which will give you the time taken by a method for execution.

To put it in code...

long start = System.currentTimeMillis ();
method ();
long end = System.currentTimeMillis ();

System.out.println ("Time taken for execution is " + (end - start));

Remember that if the time taken for execution is too small, it might show that it is taking zero milliseconds for execution. Try it on a method which is big enough, in the sense the one which is doing considerable amout of processing.
 

Read more...

CORE JAVA INTERVIEW QUESTIONS AND ANSWERS

Q:What if the main method is declared as private?
A:The program compiles properly but at run time it will give "Main method not public." message.


Q:What if the static modifier is removed from the signature of the main method?
A:Program compiles. But at runtime throws an error "NoSuchMethodError".

Q:What if I write static public void instead of public static void?
A:Program compiles and runs properly.

Q:What environment variables do I need to set on my machine in order to be able to run Java programs?
A:CLASSPATH=JAVA_HOME and PATH=location of jdl upto bin floder are the two variables.

Q:Can I have multiple main methods in the same class?
A:No the program fails to compile. The compiler says that the main method is already defined in the class.

Read more...

Log4j

How To write Log4J in our application?
In Log4j there are Appender, Layouts,Levels
 Appenders:Console,File,Jdbc,SMTP......
Layouts:Simple, Pattern,Date,Html,Xml
Levels:DEBUG,FATAL,WARN,INFO,ERROR
STEP:1
 Write a property file and place under src folder. and in D or C drive as your wish.
 For example com.blog.bhaskar.log4j.properties
  Log4J.rootLogger=debug,info,myAppender1
  Log4J.appender.myAppender1=org.apache.log4J.Fileappender
  Log4J.appender.myAppender1.File=c://text.html
  Log4J.appender.myAppender1.Layout=org.apache.log4j.SimpleLayout
  Log4J.appender.myAppender1.Layout=org.apache.log4j.HTMLLayout.

STEP:2
Write a log4j class and place in utili package
  public class Log4jutility{
  public static Logger testLogger=null;
     static{
       try{
         Properties p=new Properties();
         p.load(new FileInputStream(c://log4j.properties));
        PropertyConfigurator.configure(p);
}
    catch(Exception e)
{
testLogger=Logger.getLogger(Log4jUtility.class);
 testLogger.fatal("log4j is not configure");
 e.printStackTrace();
  }
    }
        public static void logInfoMessage(class objclass, String sMessage){
        testLogger=Logger.getLogger(objclass);
        testLogger.info(sMessage);
 }
  public static void logErrorMessage(class objclass, String sMessage){
        testLogger=Logger.getLogger(objclass);
        testLogger.info(sMessage);

 }
  public static void logFatalMessage(class objclass, String sMessage){
        testLogger=Logger.getLogger(objclass);
        testLogger.info(sMessage);

 }
  public static void logDebugMessage(class objclass, String sMessage){
        testLogger=Logger.getLogger(objclass);
        testLogger.info(sMessage);

 }
  public static void logWarnMessage(class objclass, String sMessage){
        testLogger=Logger.getLogger(objclass);
        testLogger.info(sMessage);

 }


}
Step:3
For example if you want to use log4j in your class means (form,actionclass,daoimpl any where) follow the below example.

Take a class provide log4j.
 public class Lo4jDemo{

public static void main(String[] args)
{
Log4jUtility.logInfoMessage(Log4jDemo.class,"information");
 Log4jUtility.logErroeMessage(Log4jDemo.class,"information"); Log4jUtility.logDebugMessage(Log4jDemo.class,"information"); Log4jUtility.logFatalMessage(Log4jDemo.class,"information");
}
}

NOTE:The output of logger message will be displayed in c://text.html(configured in log4j properties) location in the form of  file Layout and an HTML Layout is created automatically in C://text.html

Read more...

CORE JAVA INTERVIEW QUESTIONS AND ANSWERS

Q:What is the difference between an Interface and an Abstract class?
A:     An abstract class can have instance methods that implement a default behavior.
   An Interface can only declare constants and instance methods, but cannot implement default behavior and all methods are implicitly abstract.
   An interface has all public members and no implementation. An abstract class is a class which may have the usual flavors of class members (private, protected, etc.),
   but has some abstract methods.

Q: What is the purpose of garbage collection in Java, and when is it used?
A: 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.
A Java object is subject to garbage collection when it becomes unreachable to the program in which it is used. .

Q:Explain different way of using thread?
A:The thread could be implemented by using runnable interface or by inheriting from the Thread class.
The former is more advantageous, 'cause when you are going for multiple inheritance..the only interface can help.


Q:Difference between HashMap and HashTable?
A:The HashMap class is roughly equivalent to Hashtable, except that it is unsynchronized and permits nulls.
(HashMap allows null values as key and value whereas Hashtable doesnt allow). HashMap does not guarantee that the order of the map will remain constant over time.
HashMap is unsynchronized and Hashtable is synchronized.

Q:Difference between Vector and ArrayList?
A:Vector is synchronized whereas ArrayList is not. Vector performance is low ,
When compared to ArrayList.For multiple Threads acting on an object ArrayList is best suitable.
For a single Thread Vector is suitable.Both are growable and re-sizeable.
Vector introduced in 1.0 version where as ArrayList Introduced in 1.2 version.

Q:What is the difference between a constructor and a method?
A: A constructor is a member function of a class that is used to create objects of that class.
It has the same name as the class itself, has no return type,
and is invoked using the new operator.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.


Q:)Illustrate public,protected,default and private?    
A:public : Public class is visible in other packages, field is visible everywhere (class must be public too)
private : Private variables or methods may be used only by an instance of the same class that declares the variable or method,
A private feature may only be accessed by the class that owns the feature.
protected : Is available to all classes in the same package and also available to all subclasses of the class that owns the protected feature.
This access is provided even to subclasses that reside in a different package from the class that owns the protected feature.
default :What you get by default ie, without any access modifier (ie, public private or protected).
It means that it is visible to all within a particular package.

Q:)What is Difference between static,instance?
A:  static: If the value of variable is same for all objects.For static variables only one copy is created and shared to all objects.
  Instance:I the value of variable is varied from instance to instance.For every object a separated copy of instance is created.
Q:)Why we can't override static methods?
 A: Static means they are associated with class.In static methods ,the binding mechanism is static binding.So it must be available at compile time.


  Q:)What is difference between yield() and sleep()?
A:)When an object invokes yield() ,it returns to ready state.When an object invokes sleep() it goes to waiting state.yeild() is static native, sleep() is only static.

Read more...

FaceBook Login

HTML/JAVASCRIPT

HTML/JAVASCRIPT

HTML/JAVASCRIPT

HTML/JAVASCRIPT

Total Pageviews

STATCOUNTER

  © Blogger template Simple n' Sweet by Ourblogtemplates.com 2009

Back to TOP