| Java Interview Questions With "ANSWERS" |
|
 |
Index ‹ java-programmer
|
- Previous
- 1
- Cell phone java questionAre there any sources of information on Java programming of Nokia phones?
Esp. w/ code examples about IRda ja network connetions...
- 1
- You'll be alright.Hi Pandora Xero,
Even though it was more than obvious to everyone,
you felt compelled to make this confession:
" If I'm talking about anything,
I'm talking out my ass. "
Stick in there kid, You'll be alright.
P.S.
Can I help you get an ISP ?
Google is the mark of a troll.
- 4
- Creating Forms in JSPHi ,
I want to create a sample aplication in JSP , which consits of
a basic form , and when the user gives in data in the form , the data
should be stored in the database, and then should be retrived back
when required. Can any one please help out in this as im a total
fresher in JSP .
Please help me out in this..
Thanks in ADVANCE
Sagar meesala
- 4
- Mouse position while drag&drop-operationHi swing experts!
I have the following problem:
I want to move a custom Transferable via Drag&Drop from a JTree to a
JPanel.
The transferable should be shown on the JPanel on the position the
mouse is released.
The trouble is, I can't determine the mouse position on the JPanel.
The mouseListener and mouseMotionListener-routines on the JPanel
obviously don't work while in a standard-java-drag&drop operation.
For example: The JPanel doesn't fire a mouseEntered(..)-Event, when the
panel is entered during a drag&drop-operation.
So, without Mouse-Events, how do I get the drop-coordinates relative to
the JPanel?
Any clues?
Thanks in advance! Your help is very appreciated.
Best,
Michael
- 7
- grid of JLabelsI want to make a grid of JLabels. I want to have 4 rows and 4
columns.Any ideas?
thanks in advance
- 9
- Struts Rapid DevelopmentHi,
I'm looking for a tool, which lets me build web applications using
struts in a rapid development manner.
I know that there exist several tools out there, however I focusing on
the commercial ones, like:
- Camino
- Adalon
- Struts Studio
Can somebody recommend one of them? Which of them is the most
sophisticated and feature reach, when it comes to building large
webapplications?
Thanks,
Fritz
- 10
- javax.comm - SerialPort ProlemHi,
I tried to install the comm-extensions (with Java 1.5) and copied my files:
win32com.dll -> \myjdk\jre\bin
javax.comm.properties -> \myjdk\jre\lib
comm.jar -> \myjdk\jre\lib\ext
I'm using Eclipse.
Now to my problem:
A piece of my code:
portList = CommPortIdentifier.getPortIdentifiers();
try {
portId = CommPortIdentifier.getPortIdentifier( name );
} catch(Exception e) {System.out.println("error on comportIdentifier");}
After executing the first line portList is empty and 2 lines later a
NoSuchPortException is thrown -
it seems that I did something wrong because I don't get any portIdentifiers
at all ... but after searching for hours in the internet I only found hints
where to copy the files but nothing more ...
I would be glad if someone could help me!!
btw: I'm using WinXP
Thomas Pototschnig
- 10
- RandomAccessFile vs. FileChannelAside from memory mapped files for very large files, is there any
benefit between using the RandomAccessFile class and the FileChannel
class? They seem to be abstractions of the same low level I/O.
- 10
- xp sp2 download problem would someone please explain to me why this routine work
on clients ranging from windows (including XP), to linux, but don't work in
my winXP clients that install SP2 ??? the download window don't appears.
OutputStream out = response.getOutputStream();
response.setContentType("application/octet-stream");
//* response.setHeader("Content-Disposition","attachment;
filename=\"" +request.getRequestURI()+ "\";");
FileInputStream fis = new FileInputStream(nomeFile);
byte[] buffer = new byte[1024];
int byteLetti;
while((byteLetti = fis.read(buffer)) != -1){
out.write(buffer, 0, byteLetti);
}
out.flush();
out.close();
fis.close();
thanks!
maz
- 11
- Acknowledgment class/deviceWe assume of having a device that generically we model with the Device
class and that will be best specified with the class VCR extension of
Device.
Moreover we assume of having an application (class) Host that knows the
class Device but not VCR;
I would to make so that the device recognizes himeself (based on its
property/features) and that the class Host make an istance of VCR.
Something like
Device dev = new VCR(... pars ...);
In practical on different devices I'll have the same classes Device and
Host and moreover for everyone device I'll have a specific class
extension of Device (is VCR, PC, Freezer etc.).
The class extension could be in one specific folder.
How to make?
Also ideas, suggestions, link
thanks
- 11
- abstract vs. finalLew wrote:
> It is not the compiler's responsibility to find test code; it's the compiler's
> responsibility to check the compilability of the artifact itself.
>
> Your idea that there should be a tool, perhaps as part of JUnit or similar
> framework, to check for test coverage is a good one.
(Isn't "test coverage" a stronger notion that just "every entity has a test",
more like "every /code path/ has a test"?)
> You could use the presence of such a tool as an evaluative factor in choosing
> an IDE.
>
> But it is no part of what the compiler should do.
Clearly we have different opinions on what compilers "should", or
perhaps "should not" do. I think it's clearly /useful/ for a compiler
to [be able to] note that there's no use made of some declared entity [1]
in some codebase and I would not apply a "should not" to remove a
useful feature. (Usual tradeoff remarks apply.)
I think I'm done.
[1] I spelled `entity` "thingy" in earlier posts, for want of remembering
the word; I'm not trying to change what I meant.
--
Chris "and you've got to be ready" Dollin
Hewlett-Packard Limited Cain Road, Bracknell, registered no:
registered office: Berks RG12 1HN 690597 England
- 13
- Tutorial on java beansHi,
I am newbie to Java, though I know the syntax, OOP and have done
some small applications using it. Can someone suggest me a useful
tutorial to learn java beans.
Thanks in Advance
- 13
- 15
- Connecting J2ME application to Oracle databaseHello,
For my study I have some questions about Java J2ME:
1. Is it possible to develop a J2ME (CLDC/ MIDP) application, which has a
direct connection to a Oracle database?
2. Is there a way for using JDBC within a J2ME (CLDC/ MIDP) application?
Greetings,
Dennis
- 16
- Elipse and ATG DynamoGreetings,
I am new to Eclipse and am hoping to get it to work with ATG Dynamo.
Has anyone used Eclipse in conjunction with ATG's application server?
Eclipse does not seem to support JHTML syntax highlighting. Am I
wrong? Or is there a plug-in somewhere? Thanks.
-jay
|
| Author |
Message |
Jai

|
Posted: 2006-8-25 20:20:00 |
Top |
java-programmer, Java Interview Questions With "ANSWERS"
Hi Friends,
Here is the link for "Java Interview Questions". I hope it will be
useful for all.
I collected the ANSWERS also. So, You can find answers also. Forward
the link to your friends.
Visit the following site :
http://metajai.googlepages.com/
All the Best
Yours Friendly,
Jai
|
| |
|
| |
 |
| |
 |
Index ‹ java-programmer |
- Next
- 1
- Simple Question: How to see an Error stack trace in Tomcat... (Struts)Hi,
I have a simple probleme, I guees. I have build a simple Java Web App
(Struts, Log4J) with some JSP pages, and I have some difficulty to see
the stack trace of a Java Exception when running a JSP page. If the
page has started to be written, I can see the java exception (I see the
stack trace in a classic error page). But if the page has been started
to be written, per exemple when the the java exception is thrown in the
middle of the JSP page (in a DAO call), I cannot see any stack trace in
the page in the Log4J log or in the console... Tomcat is catching the
Exception but not writing it anywhere...
How can I change this? I would like to see the exception either in the
console or in the jsp page... I could maybe check in the Struts-config
to redirect Exception in a Error JSP page, but I doubt it would work,
because the jsp page has started to be written and cannot be change for
an other one in the process to be written.
Thanks for replying.
Etienne.
Montreal
- 2
- [(int)Math.floor(x)] or just [x]?here is the situation...
i have an array... and i select something from random from it.
i pick a random number x by using Math.random() and multiplying it by the
length of the array.
but this gives me a double, not an int.
so when i go to use the array, it needs an int.
in the language spec, it tells me that round-towards-zero is used when
going from floating point to integer, and the casting is done
automatically if possible.
so, given that x is a double, both of these methods are basically
equivalent:
obj = myArray[(int)Math.floor(x)]
and
obj = myArray[x]
only the top version is "safer" in some sense... it helps explain to
anyone who would ever look at the code (including the author when having
to back to it) what is going on.
now, intution says the bottom one is NO SLOWER than the top, because the
top may incur extra overhead due to the function call stack (for
Math.floor)... but i'm not sure. when the runtime environment does the
automatic rounding toward zero, does it basically go through the same
operations as Math.floor anyhow?
which one would most people here use... and most importantly why?
(note, i may come up with a small test program and try to benchmark the
two to get a quantitative answer, and i will post when i do.)
thanks again for all the help,
murat
--
Murat Tasan
email***@***.com
email***@***.com
email***@***.com
http://genomics.cwru.edu
- 3
- Monday as first day of the week not sundayhey,
I'm having trouble to tell JAVA that monday is the first day of the week and
not sunday. This is what I have at the moment
Calendar time;
time = Calendar.getInstance();
time.setFirstDayOfWeek(Calendar.MONDAY);
when I output time.get(Calendar.DAY_OF_WEEK) it always gives me a number on
higher then it actually is since it assumes Sunday is day 1. This really is
a annoying bug in my program. Can anyone help me or set me on the right
track ?
thnx in advance
- 4
- Possible to store JSP output as a string?Greetings all,
Ultimately I'd like to use JSP/JSF for templating, very similiar to the
way I do now with FreeMarker.
I have a chunk of HTML which looks exactly the same on the web and in
email. I'd like to reuse the same template for both.
I've searched around and haven't been able to find a solution to my
problem. I could screen-scrape it, but yuck. Am I stuck with
FreeMarker/Velocity/Etc?
Thanks much!
Jeff Rodriguez
- 5
- ToggleButton oddityI'm trying to create a set of video controls on my application.
I've added JToggleButtons named jtoggleButtonPlay, jToggleButtonPause
and jToggleButtonRew. (All part of the same ButtonGroup
buttonGroupVideoControls)
There's also a combination of JSlider (jSliderFps) and a
JFormattedTextBox (jFormattedTextBoxFps) to set the display rate.
The below code is the change listener for the buttons.
(Each button has a
jToggleButtonX.addChangeListener(new ToggleButtonListener());
line for them)
class ToggleButtonListener implements ChangeListener{
/**
* stateChanged
*
* @param e ChangeEvent
*/
public void stateChanged(ChangeEvent e) {
JToggleButton source = (JToggleButton)e.getSource();
if(!source.isSelected()){
source.setSelected(true);
}
else{}
if(source==jToggleButtonPlay){
int fps = 25;
jSliderFps.setValue(fps);
}
else{
if(source==jToggleButtonPause){
int fps = 0;
jSliderFps.setValue(fps);
}
else{
if(source==jToggleButtonRew){
//at this time lacks any runnable code
}
else{
System.err.println("Event from an invalid source");
System.exit(-1);
}
}
}
}
}
The jSliderFps:s ChangeListener is set to activate the Play button if
frame rate is set above 0 and the Pause button if frame rate is set to 0.
However, when I run the application, only the first click on the control
buttons counts. After that, I can't either activate the other buttons or
set the active button from the slider's ChangeListener.
Every attempt to activate a button after that seems to cause a
java.lang.StackOverflowError.
Any ideas on what's causing this?
--
-Aki "Sus" Laukkanen
- 6
- Why -1 returned from session.getCreationTime() ?When testing my struts code using MockStrutsTestCase the HttpSession
method getCreationTime() returns -1. A negative value suggests some
kind of failure but I can't find any reference to this value in the
API doc. Is it possible to have a session that has a negative creation
time? If so how can this happen?
When I run my code as a regular webapp under Tomcat 5.0.18 all runs
ok.
Rick
- 7
- JDBC extensionHi java developers,
if you are tired on writing SQL-statements and coding java-classes
with get- and set-methods for every column, look at
http://butler.sourceforge.net. It is a object model on top of JDBC
that makes database programming easier. It also has a generator for
generating table classes. Feature requests and contributions are also
welcome.
Best regards,
Fredrik
- 8
- jzlibI downloaded the jzlib. I also compiled all the java source code in the
com directory. how can I use these classes to deflate and inflate
files?
Thanks in advance,
Mike
- 9
- JEditorPane and HTML offset positionGiven the offset from the start of an HTML document, how I can
translate this into the offset when the HTML is rendered in a
JEditorPane? e.g. in the HTML document (not strict HTML but still
renders):
<HTML>test</HTML>
"test" starts at offset 6 in the HTML - but in the JEditorPane only
"test" would be displayed so it would start at offset 0 - if I wanted
to highlight it for example. You can imagine more complicated
documents...
Any ideas greatly apprieciated including if I can use an alternative
to the JEditorPane.
Thanks,
- 10
- A splash screenI am trying to create a splash screen. I would like it to be visible for a
few seconds while the application is initialising. After a timer expires,
the splash screen will close automatically. I have all of this working just
fine.
However, at some point during the application initialisation, it creates the
main window. When this occurs, the main window appears on top of the splash
screen. I would prefer that the splash screen be "top most" when this
occurs.
I have tried various combinations of toFront() and toBack() with no success
whatsoever.
How can I keep my splash screen topmost - preferably without having to mess
with "lost focus" type of events? In VC++, I could do this by creating the
splash screen window with the "TOPMOST" attribute set - but I can't find a
similar attribute in the java window classes.
TIA - Glenn Mc
P.S. For what it is worth, I have attached some snippets of the code I am
using. SplashPanel extends JPanel and contains all of the components making
up the splash screen.
public class SqlManEditor extends JFrame {
private static JWindow splash;
private static void showSplash (final int duration) {
/* final JWindow */ splash = new JWindow ();
SplashPanel content = new SplashPanel ();
splash.setContentPane(content);
splash.pack ();
// Center the splash screen in the display.
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize ();
int x = (screen.width - content.getWidth()) / 2;
int y = (screen.height - content.getHeight()) / 2;
splash.setBounds (x, y, content.getWidth(), content.getHeight());
Thread r = new Thread () {
public void run () {
// TODO: Figure out how to get the splash screen
to be "topmost"
// Currently when the main window is
created, it will appear
// in front of the splash screen.
splash.setVisible (true);
// wait for the specified number of milliseconds
try { Thread.sleep (duration); } catch (Exception e) {}
// When the timer expires hide the window and get
rid of it
splash.setVisible (false);
splash = null;
}
};
r.start ();
}
public static void main (String [] args) {
showSplash (5000);
SqlManEditor s = new SqlManEditor ();
s.toBack (); // After these two lines of
code execute
splash.toFront (); // s is in front and splash
is still in back!
}
}
- 11
- Java Audio question - PLEASE HELPCould some DSP or Java guru please help me ? I have a simple Java
application that records audio signals and does simple analysis on the
collected data. I am using PCM encoding, with sampling frequency 16000
Hz, 16 bits resolution, single or mono channel, little endian and
signed.
The data is read into a ByteArrayOutputStream and then as soon as I
stop recording, the stream contents are written to a byte array, using
'toByteArray()'. After that, I can get the size of this byte array,
which gives me the total number of bytes collected, keeping in mind
that I am using 16 bit resolution, i.e., each sound sample is 16 bits
long. I am using a software tone generator, with the frequency set at
500.0 Hertz.
Now, from simple DSP principles, we know that if the number of samples
collected is 'n' and the sampling frequency is 'fs', then the time
needed to collect these 'n' samples is n/fs, and the fundamental
frequency recorded is the inverse of this time value.
However, I am only getting frequencies as low as 7 Hz, or 8Hz, which
is just absurd. Could someone please tell me if I am doing something
totally incorrect, or where the flaw in my reasoning is. Any help
would be greatly appreciated. Thanks in advance for your help.
- 12
- How to change in CSS class at runtimeHi frinds,
Can anybody tell me that can I pass the dynamic data in my
CSS(Cascading Style Sheel) class.
If yes then how?
Actually I have a CSS which I am including in a number of JSP pages,
Problem is that I want to change the configuration of my CSS class
result differently for the diffrent JSPs.
Please help me out if anybody can.
Thanks & Regards
- 13
- 73 megabyte NullPointerException objects out of memory'ing our JVMOn our IBM 1.4.1 JVM we sometimes get an out of memory error.
According the IBM heapdump and heaproots, it is a large
NullPointerException being thrown from a finalize(). In our
application, should we catch all exceptions in our finalize() methods
and prevent them from being thrown further? What does the
"Finalizer" thread do with the exceptions that it gets from finalize()
methods? Why does this 73megabyte null pointer happen in the first
place??
Any suggestions?
Showing objects whose type is in 'A,R', sorted by total-size.
Addr Size Root-owner Parent Total-size Name
-------------------------------------------------------------------------------
R 0x10143330 32 - - 73,254,488
java/lang/NullPointerException
<0> [73,254,488] 0x10143330 [32] java/lang/NullPointerException
<1> [73,254,456] 0x10143308 [40] array of java/lang/Object
<2> [73,254,056] 0x4043b6f8 [304] class java/lang/ref/Finalizer
<3> [73,253,488] 0x1a450358 [32] java/lang/ref/Finalizer
<4> [73,253,416] 0x1a419818 [32] java/lang/ref/Finalizer
<5> [73,253,344] 0x14bfc2e0 [32] java/lang/ref/Finalizer
<6> [73,253,080] 0x1a3cce70 [32] java/lang/ref/Finalizer
<7> [73,216,312] 0x1a3b3a80 [32] java/lang/ref/Finalizer
<8> [73,216,280] 0x1a3a9938 [32]
java/lang/ref/Finalizer
<9> [73,216,136] 0x1a3858b8 [32]
java/lang/ref/Finalizer
<10> [73,216,064] 0x1a352f00 [32]
java/lang/ref/Finalizer
<11> [73,215,992] 0x1a344b60 [32]
java/lang/ref/Finalizer
<12> [72,964,856] 0x1a344b80 [16]
java/lang/ClassLoader$Finalizer
- 14
- GET and POST in jspHi,
I've been trying to get two parameters passed from a html to a jsp
page. I can read the correct values of the passed parameters but
I am having difficulties distinquishing between those values in an
if-else statement.
The idea is, I need my jsp page to know how the call to it was made. It
can be an INPUT or a VIEW mode.
I've got an entries.html which is:
<html>
<body>
<form action="DocView.jsp" method="POST" accept-charset="UTF-8">
Enter a document of type:
<SELECT NAME="doctype" SIZE=1>
<OPTION VALUE="article">article
<OPTION VALUE="book">book
<OPTION VALUE="manual">manual
</SELECT>
<INPUT TYPE="submit" VALUE="Go">
</FORM>
<BR>
<form action="DocView.jsp" method="POST" accept-charset="UTF-8">
Or view an existing document with id
<SELECT NAME="docid" SIZE=1>
<OPTION VALUE="1">1
<OPTION VALUE="2">2
<OPTION VALUE="3">3
</SELECT>
<INPUT TYPE="submit" VALUE="Go">
</FORM>
</body>
</html>
and a DocView.jsp one:
<%
String doctype = request.getParameter("doctype");
String docid = request.getParameter("docid");
String mode = "";
if(docid != "") {
mode = "VIEW";
}
else if( doctype != ""){
mode = "INPUT";
out.println("doctype = " + doctype + ", mode = " + mode +"<BR>");
out.println("docid = " + docid + ", mode = " + mode);
%>
The if-else statement should identify the type of call was made to
DocView, based on that, actions will be taken.
The code is just to demonstrate the idea of what I am doing. The
actuall code reads data from a MySQL database.
As a result of Docview.jsp I get the correct value of docid if I chose
an id value or a null if not. The same with doctype,
either the choosen doctype is displayed or a null. But the variable
mode does not change.
It is alway VIEW. Or actually it always gets the value that assigned
first to it. If I change else-if with the if statement, then the mode
will always be INPUT.
Now that leads to the conclusion that mode has to be reinitialized! but
How?
I can do the same thing with PHP, but there I can use $_GET['param']
and $_POST['param'] and different if-else statement, and it works
perfectly. Here is just a snip if the statements in PHP (sorry for
having to post a php code, but this might clearify my problem more).
$mode="";
$docid=$_GET['docid'];
$doctype=$_POST['doctype'];
if($docid!="") {
$mode="VIEW";
} else {
$docid=$_POST['docid'];
if ($doctype!="") {
$mode="INPUT";
} elseif ($docid!="") {
$mode="EDIT";
}
}
(the EDIT mode will be added to the jsp later), but this code does
exactly what I want. how can realize the same in my jsp code?
I appreciate any help on that.
Thankfully,
Michael
- 15
- Tomcat help: Java Beans and servlets not working in user directories with UserConfig, jsp isHello all,
I'm using jakarta-tomcat-5.5.7 with jdk 1.5 on solaris 8.
I have configured in web.xml the UserConfig class as such
<Listener className="org.apache.catalina.startup.UserConfig"
directoryName="public_html" userClass="or
g.apache.catalina.startup.PasswdUserDatabase"/>
any jsps in home directories are working but servlets and beans that
are being
used
from jsps are not.
For example I have a directory
/jakarta-tomcat-5.5.7/webapps/steve
in it i have Test.jsp and a subdir WEB-INF in that I have a subdir
classes and
in that I
have a sub directory called blah and in that subdir I have
Product.class
Test.jsp uses blah.Product and this all works in the main webapps
directory.
However if I move the contents of the steve directory to
~steve/public_html/webapps
and I try to load Test.jsp (actually I renamed Test.jsp to
TestProduct.jsp) I
get the error
org.apache.jasper.JasperException: /webapps/TestProduct.jsp(3,0) The
value for
the
useBean class attribute blah.Product is invalid.
I however can use a jsp that does not use any beans in the
~steve/public_html/webapps
directory.
I also have a regular servlet that works in
/jakarta-tomcat-5.5.7/webapps/steve
(with the appropriate web.xml which has the servlet-mapping)
but it won't in
~steve/public_html/webapps
Any help is appreciated.
Thanks
|
|
|