1) Can a class be it’s own event handler? Explain how to implement this.
Ans: Sure. an example could be a class that extends Jbutton and implements ActionListener. In the actionPerformed method, put the code to perform when the button is pressed.
2) Why does JComponent have add() and remove() methods but Component does not?
Ans: because JComponent is a subclass of Container, and can contain other components and jcomponents.
3) How would you create a button with rounded edges?
Ans: there’s 2 ways. The first thing is to know that a JButton’s edges are drawn by a Border. so you can override the Button’s paintComponent(Graphics) method and draw a circle or rounded rectangle (whatever), and turn off the border. Or you can create a custom border that draws a circle or rounded rectangle around any component and set the button’s border to it.
4) If I wanted to use a SolarisUI for just a JTabbedPane, and the Metal UI for everything else, how would I do that?
Ans: in the UIDefaults table, override the entry for tabbed pane and put in the SolarisUI delegate.
5) What is the difference between the ‘Font’ and ‘FontMetrics’ class?
Ans: The Font Class is used to render ‘glyphs’ - the characters you see on the screen. FontMetrics encapsulates information about a specific font on a specific Graphics object. (width of the characters, ascent, descent)
6) What class is at the top of the AWT event hierarchy?
Ans: java.awt.AWTEvent. if they say java.awt.Event, they haven’t dealt with swing or AWT in a while.
7) Explain how to render an HTML page using only Swing.
Ans: Use a JEditorPane or JTextPane and set it with an HTMLEditorKit, then load the text into the pane.
8) How would you detect a keypress in a JComboBox?
Ans: This is a trick. most people would say ‘add a KeyListener to the JComboBox’ - but the right answer is ‘add a KeyListener to the JComboBox’s editor component.’
9) Why should the implementation of any Swing callback (like a listener) execute quickly?
Ans: Because callbacks are invoked by the event dispatch thread which will be blocked processing other events for as long as your method takes to execute.
10) In what context should the value of Swing components be updated directly?
Ans: Swing components should be updated directly only in the context of callback methods invoked from the event dispatch thread. Any other context is not thread safe.
11) Why would you use SwingUtilities.invokeAndWait or SwingUtilities.invokeLater?
Ans: I want to update a Swing component but I’m not in a callback. If I want the update to happen immediately (perhaps for a progress bar component) then I’d use invokeAndWait. If I don’t care when the update occurs, I’d use invokeLater.
12) If your UI seems to freeze periodically, what might be a likely reason?
Ans: A callback implementation like ActionListener.actionPerformed or MouseListener.mouseClicked is taking a long time to execute thereby blocking the event dispatch thread from processing other UI events.
13) Which Swing methods are thread-safe?
Ans: The only thread-safe methods are repaint(), revalidate(), and invalidate()
14) Why won’t the JVM terminate when I close all the application windows?
Ans: The AWT event dispatcher thread is not a daemon thread. You must explicitly call System.exit to terminate the JVM.
courtesy:http://www.crackthecampus.com
The test contained 3 questions:
1. design a class diagram or date model for this
problem:
A company has some clients and some officers. Also it
has some rooms to be used for meetings between client
and officers. one officer is responsible for each
room. and room has unique room id. a meeting will be
aranged only when the officer and client are free and
room is also free. the officer and clients must be
registered to the system which will give them unique
email ids. arrange the meetings. dont write ode.
2. write a program to find the occurance of charachers
'!', 'replace all odd occurance of '?' to '.'.
3. there was a given program to insert a value at the
proper postion in a doubly linked list. there was some
logical error in that due to which it was not working
properly. find out that error. it was easy.
Sapient test 2nd round
This is also technical round .Duration 1hr
.
You have to write two programs .in any language .preferably c++ and java.
Program 1.
Name : Post - mails
Some conditions are given like if you cover some distance you have to pay this amount , if postal weight is this then u have to pay this amount .
Thus five to six conditions are given , you have to write the program to get the distance of post – mail / sort / print / the result .
Very simple program just use if and else loop .
Given : getdistance() is function which gives you the distance between two cities.
Program 2
Name : compress and decompress the string .
One string is given like : aaabbbbbcddddeeee
You hav to compress the string like a3b5c1d4e4
And it may happen while transferring the compress string some non alphanumeric characters can add in compressed string so compressed string can become a@3b%5c*1d$4e4 like this you have to remove this extra characters.
Those who cleared this test hav technical interview round
Technical interview :
50 minutes technical interview .
10 min:Debugging
q1 .They had given me one program for debugging. The program is in java .and don’t hav any syntax error. Just logical error.
10 min :
Then told me to correct the mistake I had done in 2nd round answer paper.
10 min :
About My project
10 min :
curriculum /academic subjects .
10 min :
Extra activity – like IEEE membership / achievements / seminars / paper presentation / competitions etc.
5 min:
SAPIENT HIRING TEST
TEST 1
part 1. They gave a Java Program to convert the numeric to Words, and there was a bug in it. we have to solve it and give the comments. There is no Syntax error but only the logical error.
The program compiles without errors and runs, but the desired output is not got. for example
Input: 456
Output : four hundred and fifty six (correct)
Input :14000
Output : hundred and fourteen thousand.(wrong)
Desired output : fourteen hundred thousand.
Input :235126
output : hundred and two hundred and thirtyfive thousand hundred and one hundred and twenty six(wrong)
I am not much clear about the question but frame it out.(15 minutes)
part 2. you have to write a program to calculate the sales price of the product for a given conditions. it is very simple.(20 minutes)
part 3. You need to create a class diagram or data model for the given requirements. the requirement is as follows
In a village there are only few families and there were only one newspaper/magazine agent.
there are lot of news paper and magazine available and every month a new magazine or newspaper it introduced.
Every family is getting at least one newspaper or magazine.
Every month at the end the cost is calculated and collected.
Suppose if a family wants to cancel the subscription, they should be able to do it at any day of the month.
The family should be billed only for the days which they got the newspaper or magazine.
The agent plans to buy a computer and proceed. Please create a class diagram or data model which helps him in developing a new software for it. Do not write the code or Flowchart.(25 minutes)
part 4. Please describe in 50 words. explain a situation in which you helped a person to excel in life in the field which you are more familiar and the person is nil about it.(3 minutes)
Sapient Paper
1. In 1978, a kg of paper was sold at Rs25/-. I f the paper rate increases at 1.5% more than inflation rate which is of 6.5% a year , then what wil be the cost of a kg of paper after 2 years?