More than 3000 questions in repository. There are more than 900 unanswered questions. Click here and help us by providing the answer. Have a video suggestion. Click Correct / Improve and please let us know.
public static void main(String[] args) throws InterruptedException{
int totalSum = 0;
// Create all the threads and set the count starting point for all of them
for(int count=0;count<10;count++){
TotalUsingThreads newThread = new TotalUsingThreads(count*100);
newThread.start();
collector.add(newThread);
}
boolean allCollected = false;
// Make sure that all thread totals are collected and all threads have completed their tasks
while(!allCollected){
for(int count=0;count<10;count++){
if(collector.get(count).threadTotal == null){
Thread.sleep(100);
break;
}
}
allCollected = true;
}
// sum totals of all threads
for(int count=0;count<10;count++){
totalSum += collector.get(count).threadTotal;
}
Q665. If you have access to a function that returns a random integer from one to five, write another function which returns a random integer from one to seven.
Ans. Java bytecode is the instruction set of the Java virtual machine. Each bytecode is composed by one, or two bytes that represent the instruction, along with zero or more bytes for passing parameters.
Help us improve. Please let us know the company, where you were asked this question :
Ans. Yes and No. JVM is an extra layer that translates Byte Code into Machine Code. So Comparing to languages like C, Java provides an additional layer of translating the Source Code.
Though it looks like an overhead but this additional translation allows Java to run Apps on all platforms as JVM provides the translation to the Machine code as per the underlying Operating System.
Help us improve. Please let us know the company, where you were asked this question :
Q671. What is Byte Code ? Why Java's intermediary Code is called Byte Code ?
Ans. Bytecode is a highly optimized set of instructions designed to be executed by the Java run-time system. Its called Byte Code because each instruction is of 1-2 bytes.
Ans. PATH is the variable that holds the directories for the OS to look for executables. CLASSPATH is the variable that holds the directories for JVM to look for .class files ( Byte Code ).
Help us improve. Please let us know the company, where you were asked this question :
public static void main(String[] args) { int x = 10; int y; if (x < 100) y = x / 0; if (x >= 100) y = x * 0; System.out.println("The value of y is: " + y); }
Ans. The code will not compile raising an error that the local variable y might not have been initialized. Unlike member variables, local variables are not automatically initialized to the default values for their declared type.
Help us improve. Please let us know the company, where you were asked this question :
Ans. With the advent of Internet, HTTP is the most preferred way of communication. Most of the clients ( web thin client , web thick clients , mobile apps ) are designed to communicate using http only. Web Services using http makes them accessible from vast variety of client applications.
Help us improve. Please let us know the company, where you were asked this question :
Q686. Does SQL allow null values ? Can we use it within Where clause ?
Ans. Yes , we can have null values for columns in SQL. Null value represent that the columns value is unknown or haven't been filled. Yes, We can use it within where clause to get the rows with null values.
Help us improve. Please let us know the company, where you were asked this question :
Ans. http protocol on its own is stateless. So it helps in identifying the relationship between multiple stateless request as they come from a single source.
Help us improve. Please let us know the company, where you were asked this question :
Ans. Session info in the request can be intercepted and hence a vulnerability. Cookie can be read and write by respective domain only and make sure that right session information is being passed by the client.
Help us improve. Please let us know the company, where you were asked this question :
LikeDiscussCorrect / Improve  j2ee   servlets   session   session management   web applications   cookies   httpsession   architecture
Ans. Yes. Methods invoked from within a finally block can throw an exception. Failure to catch and handle such exceptions results in the abrupt termination of the entire try block.
Help us improve. Please let us know the company, where you were asked this question :