Java Awt Swing Interview Questions
1 What is the difference between a Choice and a List?
Ans: A Choice is displayed in a compact form that requires you to pull it down to see the list of available choices. Only one item may be selected from a Choice. A List may be displayed in such a way that several List items are visible. A List supports the selection of one or more List items.
2 what interface is extended by AWT event listeners?
Ans: All AWT event listeners extend the java.util.EventListener interface.
3 what is a layout manager?
Ans: A layout manager is an object that is used to organize components in a container.
4 Which Component subclass is used for drawing and painting?
Ans: Canvas
5 what is the difference between a Scrollbar and a Scroll Pane?
Ans: A Scrollbar is a Component, but not a Container. A Scroll Pane is a Container. A Scroll Pane handles its own events and performs its own scrolling.
6 Which Swing methods are thread-safe?
Ans: The only thread-safe methods are repaint (), revalidate (), and invalidate ()
7 which containers use a border Layout as their default layout?
Ans: The Window, Frame and Dialog classes use a border layout as their default layout
8 what is the preferred size of a component?
Ans: The preferred size of a component is the minimum component size that will allow the component to display normally
9 which containers use a Flow Layout as their default layout?
Ans: The Panel and Applet classes use the Flow Layout as their default layout
10 what is the immediate super class of the Applet class?
Ans: Panel
11 Name three Component subclasses that support painting?
Ans: The Canvas, Frame, Panel, and Applet classes support painting
12 what is the immediate super class of the Dialog class?
Ans: Window
13 what is clipping?
Ans: Clipping is the process of confining paint operations to a limited area or shape.
14 what is the difference between a Menu Item and a Check box MenuItem?
Ans: The Checkbox Menu Item class extends the MenuItem class to support a menu item that may be checked or unchecked.
15 what class is the top of the AWT event hierarchy?
Ans: The java.awt.AWTEvent class is the highest-level class in the AWT event-class hierarchy
16 In which package are most of the AWT events that support the event-delegation model defined?
Ans: Most of the AWT-related events of the event-delegation model are defined in the java.awt.event package. The AWTEvent class is defined in the java.awt package.
17 which class is the immediate super class of the Menu Component class?
Ans: Object
18 which containers may have a Menu Bar?
Ans: Frame
19 what is the relationship between the Canvas class and the Graphics class?
Ans: A Canvas object provides access to a Graphics object via its paint () method.
20 How are the elements of a Border Layout organized?
Ans: The elements of a Border Layout are organized at the borders (North, South, East, and West)
and the center of a container.
Java exception handling interview questions
Java exception handling interview questions
1.which package contains exception handling related classes?
Ans: java. Lang
2. what are the two types of Exceptions?
Ans: Checked Exceptions and Unchecked Exceptions.
3 what is the base class of all exceptions?
Ans: java.lang.Throwable
4 what is the difference between Exception and Error in java?
Ans: Exception and Error are the subclasses of the Throw able class. Exception class is used for exceptional conditions that user program should catch. Error defines exceptions that are not excepted to be caught by the user program. Example is Stack Overflow.
5 what is the difference between throw and throws?
Ans: throw is used to explicitly raise a exception within the program, the statement would be throw new Exception (); throws clause is used to indicate the exceptions that are not handled by the method. It must specify this behavior so the callers of the method can guard against the exceptions. Throws is specified in the method signature. If multiple exceptions are not handled, then they are separated by a comma. The statement would be as follows: public void do something () throws IOException, MyException {}
6 Differentiate between Checked Exceptions and Unchecked Exceptions?
Ans: Checked Exceptions are those exceptions which should be explicitly handled by the calling method. Unhandled checked exceptions results in compilation error.
Unchecked Exceptions are those which occur at runtime and need not be explicitly handled. Runtime Exception and its subclasses, Error and its subclasses fall under unchecked exceptions.
7 what are User defined Exceptions?
Ans: Apart from the exceptions already defined in Java package libraries, user can define his own exception classes by extending Exception class.
8 what is the importance of finally block in exception handling?
Ans: Finally block will be executed whether or not an exception is thrown. If an exception is thrown, the finally block will execute even if no catch statement match the exception. Any time a method is about to return to the caller from inside try/catch block, via an uncaught exception or an explicit return statement, the finally block will be executed. Finally is used to free up resources like database connections, IO handles, etc.
9 Can a catch block exist without a try block?
Ans: No. A catch block should always go with a try block.
10 Can a finally block exist with a try block but without a catch?
Ans: Yes. The following are the combinations try/catch or try/catch/finally or try/finally.
11 what will happen to the Exception object after exception handling?
Ans: Exception object will be garbage collected.
12 The subclass exception should precede the base class exception when used within the catch clause. True/False?
Ans: True.
13 Exceptions can be caught or rethrown to a calling method. True/False?
Ans: True.
14 The statements following the throw keyword in a program are not executed. True/False?
Ans: True.
15 How does finally block differ from finalize () method?
Ans: Finally block will be executed whether or not an exception is thrown. So it is used to free resoources. Finalize () is a protected method in the Object class which is called by the JVM just before an object is garbage collected.
16 what are the constraints imposed by overriding on exception handling?
Ans: 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.
1.which package contains exception handling related classes?
Ans: java. Lang
2. what are the two types of Exceptions?
Ans: Checked Exceptions and Unchecked Exceptions.
3 what is the base class of all exceptions?
Ans: java.lang.Throwable
4 what is the difference between Exception and Error in java?
Ans: Exception and Error are the subclasses of the Throw able class. Exception class is used for exceptional conditions that user program should catch. Error defines exceptions that are not excepted to be caught by the user program. Example is Stack Overflow.
5 what is the difference between throw and throws?
Ans: throw is used to explicitly raise a exception within the program, the statement would be throw new Exception (); throws clause is used to indicate the exceptions that are not handled by the method. It must specify this behavior so the callers of the method can guard against the exceptions. Throws is specified in the method signature. If multiple exceptions are not handled, then they are separated by a comma. The statement would be as follows: public void do something () throws IOException, MyException {}
6 Differentiate between Checked Exceptions and Unchecked Exceptions?
Ans: Checked Exceptions are those exceptions which should be explicitly handled by the calling method. Unhandled checked exceptions results in compilation error.
Unchecked Exceptions are those which occur at runtime and need not be explicitly handled. Runtime Exception and its subclasses, Error and its subclasses fall under unchecked exceptions.
7 what are User defined Exceptions?
Ans: Apart from the exceptions already defined in Java package libraries, user can define his own exception classes by extending Exception class.
8 what is the importance of finally block in exception handling?
Ans: Finally block will be executed whether or not an exception is thrown. If an exception is thrown, the finally block will execute even if no catch statement match the exception. Any time a method is about to return to the caller from inside try/catch block, via an uncaught exception or an explicit return statement, the finally block will be executed. Finally is used to free up resources like database connections, IO handles, etc.
9 Can a catch block exist without a try block?
Ans: No. A catch block should always go with a try block.
10 Can a finally block exist with a try block but without a catch?
Ans: Yes. The following are the combinations try/catch or try/catch/finally or try/finally.
11 what will happen to the Exception object after exception handling?
Ans: Exception object will be garbage collected.
12 The subclass exception should precede the base class exception when used within the catch clause. True/False?
Ans: True.
13 Exceptions can be caught or rethrown to a calling method. True/False?
Ans: True.
14 The statements following the throw keyword in a program are not executed. True/False?
Ans: True.
15 How does finally block differ from finalize () method?
Ans: Finally block will be executed whether or not an exception is thrown. So it is used to free resoources. Finalize () is a protected method in the Object class which is called by the JVM just before an object is garbage collected.
16 what are the constraints imposed by overriding on exception handling?
Ans: 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.
Java threading interview Questions
Java threading interview Questions
1 What are the two types of multitasking?
Ans:a. Process-based.
b. Thread-based.
2 .What is a Thread?
Ans: A thread is a single sequential flow of control within a program.
3 what are the two ways to create a new thread?
Ans: A.Extend the Thread class and override the run () method.
B.Implement the Runnable interface and implement the run () method.
4 If you have ABC class that must subclass XYZ class, which option will you use to create a thread?
Ans: I will make ABC implement the Runnable interface to create a new thread, because ABC class will not be able to extend both XYZ class and Thread class.
5 which package contains Thread class and Runnable Interface?
Ans: java. Lang package
6 what is the signature of the run () mehod in the Thread class?
Ans: public void run ()
7 Which methods calls the run () method?
Ans: start () method.
8 which interface does the Thread class implement?
Ans: Runnable interface
9 what are the states of a Thread?
Ans: Ready, Running, Waiting and Dead.
10 where does the support for threading lie?
Ans: The thread support lies in java.lang.Thread, java.lang.Object and JVM.
11 In which class would you find the methods sleep () and yield ()?
Ans: Thread class
12 In which class would you find the methods notify (), notify All () and wait ()?
Ans: Object class
13 what will notify () method do?
Ans: notify() method moves a thread out of the waiting pool to ready state, but there is no guaranty which thread will be moved out of the pool.
14 Can you notify a particular thread?
Ans: No.
15 what is the difference between sleep () and yield ()?
Ans: When a Thread calls the sleep () method, it will return to its waiting state. When a Thread calls the yield () method, it returns to the ready state.
16 what is a Daemon Thread?
Ans: Daemon is a low priority thread which runs in the backgrouund.
17 How to make a normal thread as daemon thread?
Ans: We should call set Daemon (true) method on the thread object to make a thread as daemon thread.
18 what is the difference between normal thread and daemon thread?
Ans: Normal threads do mainstream activity, whereas daemon threads are used low priority work. Hence daemon threads are also stopped when there are no normal threads.
19 Give one good example of a daemon thread?
Ans: Garbage Collector is a low priority daemon thread.
20 what does the start () method of Thread do?
Ans: The thread’s start () method puts the thread in ready state and makes the thread eligible to run. Start () method automatically calls the run () method.
1 What are the two types of multitasking?
Ans:a. Process-based.
b. Thread-based.
2 .What is a Thread?
Ans: A thread is a single sequential flow of control within a program.
3 what are the two ways to create a new thread?
Ans: A.Extend the Thread class and override the run () method.
B.Implement the Runnable interface and implement the run () method.
4 If you have ABC class that must subclass XYZ class, which option will you use to create a thread?
Ans: I will make ABC implement the Runnable interface to create a new thread, because ABC class will not be able to extend both XYZ class and Thread class.
5 which package contains Thread class and Runnable Interface?
Ans: java. Lang package
6 what is the signature of the run () mehod in the Thread class?
Ans: public void run ()
7 Which methods calls the run () method?
Ans: start () method.
8 which interface does the Thread class implement?
Ans: Runnable interface
9 what are the states of a Thread?
Ans: Ready, Running, Waiting and Dead.
10 where does the support for threading lie?
Ans: The thread support lies in java.lang.Thread, java.lang.Object and JVM.
11 In which class would you find the methods sleep () and yield ()?
Ans: Thread class
12 In which class would you find the methods notify (), notify All () and wait ()?
Ans: Object class
13 what will notify () method do?
Ans: notify() method moves a thread out of the waiting pool to ready state, but there is no guaranty which thread will be moved out of the pool.
14 Can you notify a particular thread?
Ans: No.
15 what is the difference between sleep () and yield ()?
Ans: When a Thread calls the sleep () method, it will return to its waiting state. When a Thread calls the yield () method, it returns to the ready state.
16 what is a Daemon Thread?
Ans: Daemon is a low priority thread which runs in the backgrouund.
17 How to make a normal thread as daemon thread?
Ans: We should call set Daemon (true) method on the thread object to make a thread as daemon thread.
18 what is the difference between normal thread and daemon thread?
Ans: Normal threads do mainstream activity, whereas daemon threads are used low priority work. Hence daemon threads are also stopped when there are no normal threads.
19 Give one good example of a daemon thread?
Ans: Garbage Collector is a low priority daemon thread.
20 what does the start () method of Thread do?
Ans: The thread’s start () method puts the thread in ready state and makes the thread eligible to run. Start () method automatically calls the run () method.
object oriented features Interview Questions oops
object oriented features Interview Questions oops
1. Explain what is an object?
An object is a combination of messages and data. Objects can receive and send messages and use messages to interact with each other. The messages contain information that is to be passed to the recipient object.
2. Explain about the Design Phase?
In the design phase, the developers of the system document their understanding of the system. Design generates the blue print of the system that is to be implemented. The first step in creating an object oriented design is the identification of classes and their relationships.
3. Explain about parametric polymorphism?
Parametric polymorphism is supported by many object oriented languages and they are very important for object oriented techniques. In parametric polymorphism code is written without any specification for the type of data present. Hence it can be used any number of times.
4. Explain about multiple inheritance?
Inheritance involves inheriting characteristics from its parents also they can have their own characteristics. In multiple inheritances a class can have characteristics from multiple parents or classes. A sub class can have characteristics from multiple parents and still can have its own characteristics.
5. Explain the mechanism of composition?
Composition helps to simplify a complex problem into an easier problem. It makes different classes and objects to interact with each other thus making the problem to be solved automatically. It interacts with the problem by making different classes and objects to send a message to each other.
6. Explain about overriding polymorphism?
Overriding polymorphism is known to occur when a data type can perform different functions. For example an addition operator can perform different functions such as addition, float addition etc. Overriding polymorphism is generally used in complex projects where the use of a parameter is more.
7. Explain about inheritance?
Inheritance revolves around the concept of inheriting knowledge and class attributes from the parent class. In general sense a sub class tries to acquire characteristics from a parent class and they can also have their own characteristics. Inheritance forms an important concept in object oriented programming.
8. Explain the rationale behind Object Oriented concepts?
Object oriented concepts form the base of all modern programming languages. Understanding the basic concepts of object-orientation helps a developer to use various modern day programming languages, more effectively.
9.Explain about instance in object oriented programming?
Every class and an object have an instance. Instance of a particular object is created at runtime. Values defined for a particular object define its State. Instance of an object explains the relation ship between different elements.
10) Explain about encapsulation?
Encapsulation passes the message without revealing the exact functional details of the class. It allows only the relevant information to the user without revealing the functional mechanism through which a particular class had functioned.
11) Explain about polymorphism?
Polymorphism helps a sub class to behave like a parent class. When an object belonging to different data types respond to methods which have a same name, the only condition being that those methods should perform different function.
12) Explain about object oriented databases?
Object oriented databases are very popular such as relational database management systems. Object oriented databases systems use specific structure through which they extract data and they combine the data for a specific output. These DBMS use object oriented languages to make the process easier.
13) What are all the languages which support OOP?
There are several programming languages which are implementing OOP because of its close proximity to solve real life problems. Languages such as Python, Ruby, Ruby on rails, Perl, PHP, Cold fusion, etc use OOP. Still many languages prefer to use DOM based languages due to the ease in coding.
14) Explain the implementation phase with respect to OOP?
The design phase is followed by OOP, which is the implementation phase. OOP provides specifications for writing programs in a programming language. During the implementation phase, programming is done as per the requirements gathered during the analysis and design phases.
15) Explain about Object oriented programming?
Object oriented programming is one of the most popular methodologies in software development. It offers a powerful model for creating computer programs. It speeds the program development process, improves maintenance and enhances reusability of programs.
16) Explain about a class?
Class describes the nature of a particular thing. Structure and modularity is provided by a Class in object oriented programming environment. Characteristics of the class should be understandable by an ordinary non programmer and it should also convey the meaning of the problem statement to him. Class acts like a blue print.
1. Explain what is an object?
An object is a combination of messages and data. Objects can receive and send messages and use messages to interact with each other. The messages contain information that is to be passed to the recipient object.
2. Explain about the Design Phase?
In the design phase, the developers of the system document their understanding of the system. Design generates the blue print of the system that is to be implemented. The first step in creating an object oriented design is the identification of classes and their relationships.
3. Explain about parametric polymorphism?
Parametric polymorphism is supported by many object oriented languages and they are very important for object oriented techniques. In parametric polymorphism code is written without any specification for the type of data present. Hence it can be used any number of times.
4. Explain about multiple inheritance?
Inheritance involves inheriting characteristics from its parents also they can have their own characteristics. In multiple inheritances a class can have characteristics from multiple parents or classes. A sub class can have characteristics from multiple parents and still can have its own characteristics.
5. Explain the mechanism of composition?
Composition helps to simplify a complex problem into an easier problem. It makes different classes and objects to interact with each other thus making the problem to be solved automatically. It interacts with the problem by making different classes and objects to send a message to each other.
6. Explain about overriding polymorphism?
Overriding polymorphism is known to occur when a data type can perform different functions. For example an addition operator can perform different functions such as addition, float addition etc. Overriding polymorphism is generally used in complex projects where the use of a parameter is more.
7. Explain about inheritance?
Inheritance revolves around the concept of inheriting knowledge and class attributes from the parent class. In general sense a sub class tries to acquire characteristics from a parent class and they can also have their own characteristics. Inheritance forms an important concept in object oriented programming.
8. Explain the rationale behind Object Oriented concepts?
Object oriented concepts form the base of all modern programming languages. Understanding the basic concepts of object-orientation helps a developer to use various modern day programming languages, more effectively.
9.Explain about instance in object oriented programming?
Every class and an object have an instance. Instance of a particular object is created at runtime. Values defined for a particular object define its State. Instance of an object explains the relation ship between different elements.
10) Explain about encapsulation?
Encapsulation passes the message without revealing the exact functional details of the class. It allows only the relevant information to the user without revealing the functional mechanism through which a particular class had functioned.
11) Explain about polymorphism?
Polymorphism helps a sub class to behave like a parent class. When an object belonging to different data types respond to methods which have a same name, the only condition being that those methods should perform different function.
12) Explain about object oriented databases?
Object oriented databases are very popular such as relational database management systems. Object oriented databases systems use specific structure through which they extract data and they combine the data for a specific output. These DBMS use object oriented languages to make the process easier.
13) What are all the languages which support OOP?
There are several programming languages which are implementing OOP because of its close proximity to solve real life problems. Languages such as Python, Ruby, Ruby on rails, Perl, PHP, Cold fusion, etc use OOP. Still many languages prefer to use DOM based languages due to the ease in coding.
14) Explain the implementation phase with respect to OOP?
The design phase is followed by OOP, which is the implementation phase. OOP provides specifications for writing programs in a programming language. During the implementation phase, programming is done as per the requirements gathered during the analysis and design phases.
15) Explain about Object oriented programming?
Object oriented programming is one of the most popular methodologies in software development. It offers a powerful model for creating computer programs. It speeds the program development process, improves maintenance and enhances reusability of programs.
16) Explain about a class?
Class describes the nature of a particular thing. Structure and modularity is provided by a Class in object oriented programming environment. Characteristics of the class should be understandable by an ordinary non programmer and it should also convey the meaning of the problem statement to him. Class acts like a blue print.
Sell your self in interview
How to Sell your self in interview
Are you attending any interview then read these tips on How to sell your self in interview?
When you attend for an interview introduce yourself with a smile and firm handshake. Maintain good eye contact with the employer during conversation. Demonstrate to the recruiter what you want to and can do for the employer today, based on employer research.Show interest in what the interviewer is saying, by nodding your head and leaning toward him/her occasionally. Give positive answers to negative-based questions. Immediately after you leave make notes of important points of discussion
Ask the recruiter prepared questions. Initiate the next step by asking what the next step is.
Ask for the recruiter’s business card for future contact.
Here is an example about how to answer the first question most interviewers ask. “Tell me about yourself” It also allows the job seeker to share with the interviewer the most important thing they want to know – “Why should I hire you?”
1. Personal and Education
This part is used to give the interviewer relevant information concerning you personally and about your educational background. This does not include personal information such as marital status, children, etc. This does include information such as: hometown or state and/or personal attribute. The education should be either the latest obtained and/or major field if relevant to job objective.
2. Early Career/Life Experiences
This part is used to share with the interviewer past work and life experiences relevant to the job objective.
3. Recent Work History/Life Experiences
This is the time for the job seeker to relate to the employer two accomplishments/results of the job seeker that indicate why he/she is the best candidate for the position sought.
4. Why you are here
In this part, the job seeker speaks with enthusiasm that he/she is here for the specific position sought.
5. What to Do
Arrive 10-15 minutes early to the interview location for interview.
Use time wisely to review employer research information.
Have pen and paper. Asking to borrow a pen indicates lack of preparation.
Be enthusiastic. Recruiters remember a positive attitude.
Listen carefully to the interviewer’s complete question before responding.
If needed, pause and take time before answering difficult questions.
Keep going even if you feel you made a mistake.
Carry extra resumes, references, etc. organized in a portfolio
Unless asked, do not discuss salary and benefits.
Are you attending any interview then read these tips on How to sell your self in interview?
When you attend for an interview introduce yourself with a smile and firm handshake. Maintain good eye contact with the employer during conversation. Demonstrate to the recruiter what you want to and can do for the employer today, based on employer research.Show interest in what the interviewer is saying, by nodding your head and leaning toward him/her occasionally. Give positive answers to negative-based questions. Immediately after you leave make notes of important points of discussion
Ask the recruiter prepared questions. Initiate the next step by asking what the next step is.
Ask for the recruiter’s business card for future contact.
Here is an example about how to answer the first question most interviewers ask. “Tell me about yourself” It also allows the job seeker to share with the interviewer the most important thing they want to know – “Why should I hire you?”
1. Personal and Education
This part is used to give the interviewer relevant information concerning you personally and about your educational background. This does not include personal information such as marital status, children, etc. This does include information such as: hometown or state and/or personal attribute. The education should be either the latest obtained and/or major field if relevant to job objective.
2. Early Career/Life Experiences
This part is used to share with the interviewer past work and life experiences relevant to the job objective.
3. Recent Work History/Life Experiences
This is the time for the job seeker to relate to the employer two accomplishments/results of the job seeker that indicate why he/she is the best candidate for the position sought.
4. Why you are here
In this part, the job seeker speaks with enthusiasm that he/she is here for the specific position sought.
5. What to Do
Arrive 10-15 minutes early to the interview location for interview.
Use time wisely to review employer research information.
Have pen and paper. Asking to borrow a pen indicates lack of preparation.
Be enthusiastic. Recruiters remember a positive attitude.
Listen carefully to the interviewer’s complete question before responding.
If needed, pause and take time before answering difficult questions.
Keep going even if you feel you made a mistake.
Carry extra resumes, references, etc. organized in a portfolio
Unless asked, do not discuss salary and benefits.
Subscribe to:
Posts (Atom)