<?xml version="1.0" encoding="UTF-8"?> <rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
><channel><title>Free Question Bank &#187; Languages</title> <atom:link href="http://www.freequestionbank.com/category/tech-crunch/programming-languages/feed/" rel="self" type="application/rss+xml" /><link>http://www.freequestionbank.com</link> <description>Just another WordPress weblog</description> <lastBuildDate>Sat, 20 Feb 2010 05:10:08 +0000</lastBuildDate> <generator>http://wordpress.org/?v=2.9.1</generator> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <item><title>Perl interview questions and answers</title><link>http://www.freequestionbank.com/question/perl-interview-questions-and-answers-techinterviews/</link> <comments>http://www.freequestionbank.com/question/perl-interview-questions-and-answers-techinterviews/#comments</comments> <pubDate>Mon, 18 May 2009 23:08:03 +0000</pubDate> <dc:creator>admin</dc:creator> <category><![CDATA[Interview]]></category> <category><![CDATA[Languages]]></category> <category><![CDATA[Question]]></category> <category><![CDATA[Tech]]></category> <category><![CDATA[perl]]></category> <category><![CDATA[questions]]></category><guid
isPermaLink="false">http://www.freequestionbank.com/blog/?p=583</guid> <description><![CDATA[# What arguments do you frequently use for the Perl interpreter and what do they mean?
# What does the command ...]]></description> <content:encoded><![CDATA[<p># What arguments do you frequently use for the Perl interpreter and what do they mean?</p><p># What does the command ‘use strict’ do and why should you use it?</p><p># What do the symbols $ @ and % mean when prefixing a variable?</p><p># What elements of the Perl language could you use to structure your code to allow for maximum re-use and maximum readability?</p><p># What are the characteristics of a project that is well suited to Perl?</p><p># Why do you program in Perl?</p><p># Explain the difference between my and local.</p><p># Explain the difference between use and require.</p><p># What’s your favorite module and why?</p><p># What is a hash?</p><p># Write a simple (common) regular expression to match an IP address, e-mail address, city-state-zipcode combination.</p><p># What purpose does each of the following serve: -w, strict, -T ?</p><p># What is the difference between for &amp; foreach, exec &amp; system?</p><p># Where do you go for Perl help?</p><p># Name an instance where you used a CPAN module.</p><p># How do you open a file for writing?</p><p># How would you replace a char in string and how do you store the number of replacements?</p><p># When would you not use Perl for a project?</p><p>via <a
href="http://www.techinterviews.com/perl-interview-questions-and-answers">Perl interview questions and answers | TechInterviews</a>.</p> ]]></content:encoded> <wfw:commentRss>http://www.freequestionbank.com/question/perl-interview-questions-and-answers-techinterviews/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>ASP.NET interview questions and answers</title><link>http://www.freequestionbank.com/question/aspnet-interview-questions-and-answers-techinterviews/</link> <comments>http://www.freequestionbank.com/question/aspnet-interview-questions-and-answers-techinterviews/#comments</comments> <pubDate>Mon, 18 May 2009 23:03:51 +0000</pubDate> <dc:creator>admin</dc:creator> <category><![CDATA[Interview]]></category> <category><![CDATA[Languages]]></category> <category><![CDATA[Question]]></category> <category><![CDATA[Tech]]></category> <category><![CDATA[.net]]></category> <category><![CDATA[asp]]></category> <category><![CDATA[questions]]></category><guid
isPermaLink="false">http://www.freequestionbank.com/blog/?p=579</guid> <description><![CDATA[# Describe the difference between a Thread and a Process?
# What is a Windows Service and how does its lifecycle ...]]></description> <content:encoded><![CDATA[<p># Describe the difference between a Thread and a Process?</p><p># What is a Windows Service and how does its lifecycle differ from a â€œstandardâ€ EXE?</p><p># What is the maximum amount of memory any single process on Windows can address? Is this different than the maximum virtual memory for the system? How would this affect a system design?</p><p># What is the difference between an EXE and a DLL?</p><p># What is strong-typing versus weak-typing? Which is preferred? Why?</p><p># Whatâ€™s wrong with a line like this? DateTime.Parse(myString</p><p># What are PDBs? Where must they be located for debugging to work?</p><p># What is cyclomatic complexity and why is it important?</p><p># Write a standard lock() plus double check to create a critical section around a variable access.</p><p># What is FullTrust? Do GAC’ed assemblies have FullTrust?</p><p># What benefit does your code receive if you decorate it with attributes demanding specific Security permissions?</p><p># What does this do? gacutil /l | find /i “about”</p><p># What does this do? sn -t foo.dll</p><p># What ports must be open for DCOM over a firewall? What is the purpose of Port 135?</p><p># Contrast OOP and SOA. What are tenets of each</p><p># How does the XmlSerializer work? What ACL permissions does a process using it require?</p><p># Why is catch(Exception) almost always a bad idea?</p><p># What is the difference between Debug.Write and Trace.Write? When should each be used?</p><p># What is the difference between a Debug and Release build? Is there a significant speed difference? Why or why not?</p><p># Does JITting occur per-assembly or per-method? How does this affect the working set?</p><p># Contrast the use of an abstract base class against an interface?</p><p># What is the difference between a.Equals(b) and a == b?</p><p># In the context of a comparison, what is object identity versus object equivalence?</p><p># How would one do a deep copy in .NET?</p><p># Explain current thinking around IClonable.</p><p># What is boxing?</p><p># Is string a value type or a reference type?</p><p>via <a
href="http://www.techinterviews.com/aspnet-interview-questions-and-answers">ASP.NET interview questions and answers | TechInterviews</a>.</p> ]]></content:encoded> <wfw:commentRss>http://www.freequestionbank.com/question/aspnet-interview-questions-and-answers-techinterviews/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>C# interview questions and answers</title><link>http://www.freequestionbank.com/question/c-interview-questions-and-answers-techinterviews/</link> <comments>http://www.freequestionbank.com/question/c-interview-questions-and-answers-techinterviews/#comments</comments> <pubDate>Mon, 18 May 2009 22:57:17 +0000</pubDate> <dc:creator>admin</dc:creator> <category><![CDATA[Interview]]></category> <category><![CDATA[Languages]]></category> <category><![CDATA[Question]]></category> <category><![CDATA[.net]]></category><guid
isPermaLink="false">http://www.freequestionbank.com/blog/?p=571</guid> <description><![CDATA[
What’s the advantage of using System.Text.StringBuilder over System.String? StringBuilder is more efficient in the cases, where a lot of manipulation ...]]></description> <content:encoded><![CDATA[<ol
style="margin-top: 0in;" type="1"><li
class="MsoNormal"><strong>What’s the advantage of using System.Text.StringBuilder over System.String? </strong>StringBuilder is more efficient in the cases, where a lot of manipulation is done to the text. Strings are immutable, so each time it’s being operated on, a new instance is created.</li><li
class="MsoNormal"><strong>Can you store multiple data types in System.Array? </strong>No.</li><li
class="MsoNormal"><strong>What’s the difference between the System.Array.CopyTo() and System.Array.Clone()? </strong>The first one performs a deep copy of the array, the second one is shallow.</li><li
class="MsoNormal"><strong>How can you sort the elements of the array in descending order? </strong>By calling Sort() and then Reverse() methods.<strong></strong></li><li
class="MsoNormal"><strong>What’s the .NET datatype that allows the retrieval of data by a unique key? </strong>HashTable.<strong></strong></li><li
class="MsoNormal"><strong>What’s class SortedList underneath? </strong>A sorted HashTable.<strong></strong></li><li
class="MsoNormal"><strong>Will <em>finally</em> block get executed if the exception had not occurred? </strong>Yes.<strong></strong></li><li
class="MsoNormal"><strong>What’s the C# equivalent of C++ catch (…), which was a catch-all statement for any possible exception? </strong>A catch block that catches the exception of type System.Exception. You can also omit the parameter data type in this case and just write catch {}.<strong></strong></li><li
class="MsoNormal"><strong>Can multiple catch blocks be executed? </strong>No, once the proper catch code fires off, the control is transferred to the finally block (if there are any), and then whatever follows the finally block.<strong></strong></li><li
class="MsoNormal"><strong>Why is it a bad idea to throw your own exceptions? </strong>Well, if at that point you know that an error has occurred, then why not write the proper code to handle that error instead of passing a new Exception object to the catch block? Throwing your own exceptions signifies some design flaws in the project.<strong></strong></li><li
class="MsoNormal"><strong>What’s a delegate? </strong>A delegate object encapsulates a reference to a method. In C++ they were referred to as function pointers.<strong></strong></li><li
class="MsoNormal"><strong>What’s a multicast delegate? </strong>It’s a delegate that points to and eventually fires off several methods.<strong></strong></li><li
class="MsoNormal"><strong>How’s the DLL Hell problem solved in .NET? </strong>Assembly versioning allows the application to specify not only the library it needs to run (which was available under Win32), but also the version of the assembly.<strong></strong></li><li
class="MsoNormal"><strong>What are the ways to deploy an assembly? </strong>An MSI installer, a CAB archive, and XCOPY command.<strong></strong></li><li
class="MsoNormal"><strong>What’s a satellite assembly? </strong>When you write a multilingual or multi-cultural application in .NET, and want to distribute the core application separately from the localized modules, the localized assemblies that modify the core application are called satellite assemblies.<strong></strong></li><li
class="MsoNormal"><strong>What namespaces are necessary to create a localized application? </strong>System.Globalization, System.Resources.<strong></strong></li><li
class="MsoNormal"><strong>What’s the difference between // comments, /* */ comments and /// comments? </strong>Single-line, multi-line and XML documentation comments.<strong></strong></li><li
class="MsoNormal"><strong>How do you generate documentation from the C# file commented properly with a command-line compiler? </strong>Compile it with a /doc switch.<strong></strong></li><li
class="MsoNormal"><strong>What’s the difference between &lt;c&gt; and &lt;code&gt; XML documentation tag? </strong>Single line code example and multiple-line code example.<strong></strong></li><li
class="MsoNormal"><strong>Is XML case-sensitive? </strong>Yes, so &lt;Student&gt; and &lt;student&gt; are different elements.<strong></strong></li><li
class="MsoNormal"><strong>What debugging tools come with the .NET SDK? </strong>CorDBG – command-line debugger, and DbgCLR – graphic debugger. Visual Studio .NET uses the DbgCLR. To use CorDbg, you must compile the original C# file using the /debug switch.<strong></strong></li><li
class="MsoNormal"><strong>What does the This window show in the debugger? </strong>It points to the object that’s pointed to by this reference. Object’s instance data is shown.<strong></strong></li><li
class="MsoNormal"><strong>What does assert() do? </strong>In debug compilation, assert takes in a Boolean condition as a parameter, and shows the error dialog if the condition is false. The program proceeds without any interruption if the condition is true.<strong></strong></li><li
class="MsoNormal"><strong>What’s the difference between the Debug class and Trace class? Documentation looks the same. </strong>Use Debug class for debug builds, use Trace class for both debug and release builds.<strong></strong></li><li
class="MsoNormal"><strong>Why are there five tracing levels in System.Diagnostics.TraceSwitcher? </strong>The tracing dumps can be quite verbose and for some applications that are constantly running you run the risk of overloading the machine and the hard drive there. Five levels range from None to Verbose, allowing to fine-tune the tracing activities.<strong></strong></li><li
class="MsoNormal"><strong>Where is the output of TextWriterTraceListener redirected? </strong>To the Console or a text file depending on the parameter passed to the constructor.<strong></strong></li><li
class="MsoNormal"><strong>How do you debug an ASP.NET Web application? </strong>Attach the aspnet_wp.exe process to the DbgClr debugger.<strong></strong></li><li
class="MsoNormal"><strong>What are three test cases you should go through in unit testing? </strong>Positive test cases (correct data, correct output), negative test cases (broken or missing data, proper handling), exception test cases (exceptions are thrown and caught properly).<strong></strong></li><li
class="MsoNormal"><strong>Can you change the value of a variable while debugging a C# application? </strong>Yes, if you are debugging via Visual Studio.NET, just go to Immediate window.<strong></strong></li><li
class="MsoNormal"><strong>Explain the three services model (three-tier application). </strong>Presentation (UI), business (logic and underlying code) and data (from storage or other sources).<strong></strong></li><li
class="MsoNormal"><strong>What are advantages and disadvantages of Microsoft-provided data provider classes in ADO.NET? </strong>SQLServer.NET data provider is high-speed and robust, but requires SQL Server license purchased from Microsoft. OLE-DB.NET is universal for accessing other sources, like Oracle, DB2, Microsoft Access and Informix, but it’s a .NET layer on top of OLE layer, so not the fastest thing in the world. ODBC.NET is a deprecated layer provided for backward compatibility to ODBC engines.<strong></strong></li><li
class="MsoNormal"><strong>What’s the role of the DataReader class in ADO.NET connections? </strong>It returns a read-only dataset from the data source when the command is executed.<strong></strong></li><li
class="MsoNormal"><strong>What is the wildcard character in SQL? Let’s say you want to query database with LIKE for all employees whose name starts with La. </strong>The wildcard character is %, the proper query with LIKE would involve ‘La%’.<strong></strong></li><li
class="MsoNormal"><strong>Explain ACID rule of thumb for transactions. </strong>Transaction must be Atomic (it is one unit of work and does not dependent on previous and following transactions), Consistent (data is either committed or roll back, no “in-between” case where something has been updated and something hasn’t), Isolated (no transaction sees the intermediate results of the current transaction), Durable (the values persist if the data had been committed even if the system crashes right after).<strong></strong></li><li
class="MsoNormal"><strong>What connections does Microsoft SQL Server support? </strong>Windows Authentication (via Active Directory) and SQL Server authentication (via Microsoft SQL Server username and passwords).<strong></strong></li><li
class="MsoNormal"><strong>Which one is trusted and which one is untrusted? </strong>Windows Authentication is trusted because the username and password are checked with the Active Directory, the SQL Server authentication is untrusted, since SQL Server is the only verifier participating in the transaction.<strong></strong></li><li
class="MsoNormal"><strong>Why would you use untrusted verificaion? </strong>Web Services might use it, as well as non-Windows applications.<strong></strong></li><li
class="MsoNormal"><strong>What does the parameter Initial Catalog define inside Connection String? </strong>The database name to connect to.<strong></strong></li><li
class="MsoNormal"><strong>What’s the data provider name to connect to Access database? </strong>Microsoft.Access.<strong></strong></li><li
class="MsoNormal"><strong>What does Dispose method do with the connection object? </strong>Deletes it from the memory.<strong></strong></li><li
class="MsoNormal"><strong>What is a pre-requisite for connection pooling? </strong>Multiple processes must agree that they will share the same connection, where every parameter is the same, including the security settings.</li></ol><p>via <a
href="http://www.techinterviews.com/c-sharp-interview-questions-and-answers">C# interview questions and answers | TechInterviews</a>.</p> ]]></content:encoded> <wfw:commentRss>http://www.freequestionbank.com/question/c-interview-questions-and-answers-techinterviews/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>VB.NET Interview Questions</title><link>http://www.freequestionbank.com/question/vbnet-interview-questions/</link> <comments>http://www.freequestionbank.com/question/vbnet-interview-questions/#comments</comments> <pubDate>Thu, 26 Mar 2009 07:51:21 +0000</pubDate> <dc:creator>admin</dc:creator> <category><![CDATA[Interview]]></category> <category><![CDATA[Languages]]></category> <category><![CDATA[Question]]></category> <category><![CDATA[.net]]></category> <category><![CDATA[dot net]]></category> <category><![CDATA[vb]]></category><guid
isPermaLink="false">http://www.freequestionbank.com/?p=432</guid> <description><![CDATA[What is .net.Net is the Development Plateform which provides advanced feature facilities for the web and window application along with ...]]></description> <content:encoded><![CDATA[<p><span
class="Apple-style-span" style="border-collapse: collapse; color: #000000; font-family: 'times new roman'; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;"><span
style="font-weight: 400;"><strong><span
style="font-size: x-small;">What is .net</span></strong></span><span
style="font-weight: 400;"><span
style="font-size: x-small;">.Net is the Development Plateform which provides advanced feature facilities for the web and window application along with the window services . The .Net is the Middle layer between the operating System and the .Net application .The feature of .Net that the .Net Component can talk with each other without worrying about the language in which they are originally.. Two main components are CLR stands for the common Language Runtime and the .Net FrameWork Base classes. The CLR performs the task of converting the IL to native code Which gives the .Net applications to be language Independent . The Other component Like .Net FramwWork Base Classes act as services to be provided to the .Net applications.</span></span></span></p><p><strong><span
style="font-size: x-small;">Differences between VB.Net and C#, related to OOPS concepts?</span></strong></p><p><span
style="font-weight: 400;"><span
style="font-size: x-small;">VB.NET is a windows application<span
class="Apple-converted-space"> </span></span></span></p><p>Where as C# is a console</p><p><strong><span
style="font-size: x-small;">1)What is the difference between vb and vb.net ?<br
/> </span></strong><span
style="font-weight: 400;"><span
style="font-size: x-small;">vb is object based and vb.net is object oriented.In VB.net ,oops concept is used</span></span></p><p><strong><span
style="font-size: x-small;">How can i extract the formated word(bold,italic,underline,font,color etc) from the msword file.</span></strong></p><p><span
style="font-weight: 400;"><span
style="font-size: x-small;">using CommonDialog class</span></span></p><p>eg:</p><p>the code to invoke the default font dialog box by using the FontDialog control is given below:</p><p>private sub displayfont_click(byval sender as system.object,byval e as system.eventargs) handles displayfont.click</p><p>fontdialog.showDialog()</p><p>textbox1.font=fontdialog1.font</p><p>end sub</p><p>the code to invoke the default font dialog box by instantiating the fontdialog class is:</p><p>dim fdialog as new fontdialog()</p><p>private sub displayfont_click(byval sender as system.object,byval e as system.eventargs) handles displayfont.click</p><p>fdialog.showDialog()</p><p>textbox1.font=fontdialog1.font</p><p>end sub</p><p><strong><span
style="font-size: x-small;">How does CLR solves dll hell?</span></strong></p><p><span
style="font-weight: 400;"><span
style="font-size: x-small;">Unlike VB6; .net does not require to generate GUID for the dll&#8217;s. The dll&#8217;s are hosted thru applications ,IIS or windows services. These things internally refer to the physical locations of the file thus even if the dll is updated with certain functionalities the older application can still refer to the previous version of the Dll.</span></span></p><p><strong><span
style="font-size: x-small;">How to send xml file on server using HTTP protocol?</span></strong></p><p><span
style="font-weight: 400;"><span
style="font-size: x-small;">Through SOAP Protocol</span></span></p><p><strong><span
style="font-size: x-small;">What is different between Web.Config and Machine.Config and Where it will be ?</span></strong></p><p><span
style="font-weight: 400;"><span
style="font-size: x-small;">the settings made in the web.config file are applied to that particular web application only whereas the settings of machine.config file are applied to the whole asp.net application.</span></span></p><p><strong><span
style="font-size: x-small;">Whats the difference bt. .dll extension and .exe extension files?</span></strong></p><p><span
style="font-weight: 400;"><span
style="font-size: x-small;">The main difference between .dll and .exe is<span
class="Apple-converted-space"> </span></span></span></p><p>.dll is the In process component where it take up the client&#8217;s memory space to run. So the communication between the application and component(dll) is very fast.</p><p>.EXE is the Out of process component. It uses its own memory(not application memory) to run the component. The communication between the application and component is slow when compared to .dll</p><p><strong><span
style="font-size: x-small;">What is the base class of .net?</span></strong></p><p><span
style="font-weight: 400;"><span
style="font-size: x-small;">System.Object is the base class of .NET</span></span></p><p>It Supports all classes in the .NET Framework class hierarchy and provides low-level services to derived classes. This is the ultimate superclass of all classes in the .NET Framework; it is the root of the type hierarchy.</p><p><strong><span
style="font-size: x-small;">How to store and retrieve images in sql server database through VB.NET</span></strong></p><p><span
style="font-weight: 400;"><span
style="font-size: x-small;">SQL Server supports the ability for clients to store objects within tables</span></span></p><p><span
style="font-weight: 400;"><strong><span
style="font-size: x-small;">What are Jagged Arrarys ?<br
/> </span></strong><span
style="font-size: x-small;">The other type of multidimensional array is the jagged array. A two dimensional jagged array can be thought of as a table where each row can have a different number of columns. Take for example, a table where families are the rows and family members are the columns. Unless each family has the same number of members, each row will have a variable number of columns. You can use a jagged array to represent such a table.<span
class="Apple-converted-space"> </span></span></span></p><p>A jagged array is really an array of arrays. To create a jagged array, you declare the array of arrays with multiple sets of parentheses or brackets and indicate the size of the jagged array in the first set of brackets (parentheses).</p><p><strong><span
style="font-size: x-small;">How can we remove Handlers at Run time ?</span></strong></p><p><span
style="font-weight: 400;"><span
style="font-size: x-small;">RemoveHandler myobj.myEvent, AddressOf MyEventHandler</span></span></p><p><strong><span
style="font-size: x-small;">What are Satellite Assemblies?</span></strong></p><p><span
style="font-weight: 400;"><span
style="font-size: x-small;">Satellite assemblies are user for localizing the applications resources.<span
class="Apple-converted-space"> </span><br
/> A satellite assembly is a DLL that contains only resource strings<span
class="Apple-converted-space"> </span><br
/> .we typically have one satellite assembly DLL for each language. Because these satellite assembly DLLs are separated from the main assembly (an .exe or DLL), it is easier to drop in multi-language support as we progress in your development process.</span></span></p><p><span
style="font-weight: 400;"><strong><span
style="font-size: x-small;">What do you mean by &#8216;Option Strict On&#8217; ?</span></strong></span></p><p><span
style="font-weight: 400;"><span
style="font-size: x-small;">Option Strict</span></span></p><p>Visual Basic language in general does not require explicit syntax to be used when performing operations that might not be optimally efficient (e.g. late binding) or that might fail at run time (e.g. narrowing conversions). This permissive semantics often prevents detection of coding errors and also affects the performance of the application.</p><p>VB.NET enables a programmer to enforce strict semantics by setting this option to &#8220;On&#8221;. When used, this option should appear before any other code. This option can be set to &#8220;On&#8221; or &#8220;Off&#8221;. If this statement is not specified, by default, it is set to &#8220;Off&#8221;.</p><p>Syntax: Option Strict [On / Off]<br
/> When it is set to &#8220;On&#8221;, it disallows any narrowing conversions to occur without an explicit cast operator, late binding and does not let the programmer omit &#8220;As&#8221; clause in the declaration statement. Since setting it to &#8220;On&#8221; requires explicit conversion, it also requires that the compiler be able to determine the type of each variable. Thus it is implied that Option Strict also means Option Explicit.<span
class="Apple-converted-space"> </span></p><p>Visual Basic .NET allows implicit conversions of any data type to any other data type. However, data loss can occur if the value of one data type is converted to a data type with less precision or a smaller capacity. Setting this option to &#8220;On&#8221; ensures compile-time notification of these types of conversions so they may be avoided.</p><p><strong><span
style="font-size: x-small;">How VB Implements the Disonnected Architecture as like VB.Net?<br
/> </span></strong><span
style="font-size: x-small;">In VB to implement a disconnected recordset, after you have filled the recordset with the data, set its active connection property to &#8220;Nothing&#8221;. That breaks the connection to the database.You can locally also save the data of the recordset by using its Save function.</span></p><p>* more <a
href="planetetutors.com">here</a></p> ]]></content:encoded> <wfw:commentRss>http://www.freequestionbank.com/question/vbnet-interview-questions/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Visual Basic Interview Questions</title><link>http://www.freequestionbank.com/question/visual-basic-interview-questions/</link> <comments>http://www.freequestionbank.com/question/visual-basic-interview-questions/#comments</comments> <pubDate>Thu, 26 Mar 2009 07:50:02 +0000</pubDate> <dc:creator>admin</dc:creator> <category><![CDATA[Interview]]></category> <category><![CDATA[Languages]]></category> <category><![CDATA[Question]]></category> <category><![CDATA[vb]]></category><guid
isPermaLink="false">http://www.freequestionbank.com/?p=430</guid> <description><![CDATA[How do you register a component? Expected answer: Compiling the component, running REGSVR32 MyDLL.dll
Name and explain the different compatibility types ...]]></description> <content:encoded><![CDATA[<table
id="AutoNumber1" style="border-collapse: collapse; height: 354px;" border="0" cellspacing="0" cellpadding="0" width="100%" bordercolor="#111111"><tbody><tr><td
width="3%" height="240"><br
class="Apple-interchange-newline" /></td><td
width="97%" height="240" valign="top"><ol><li><span
style="font-weight: 400;"><strong><span
style="font-size: x-small;">How do you register a component?</span></strong><span
style="font-size: x-small;"><span
class="Apple-converted-space"> </span><em>Expected answer:</em><span
class="Apple-converted-space"> </span>Compiling the component, running REGSVR32 MyDLL.dll</span></span></li><li><span
style="font-weight: 400;"><strong><span
style="font-size: x-small;">Name and explain the different compatibility types when creating a COM component.</span></strong><span
style="font-size: x-small;"><em>Expected answer:</em><span
class="Apple-converted-space"> </span>No Compatibility ? New GUID created, references from other components will not workProject Compatibility ? Default for a new component &lt;Not as critical to mention this one&gt;Binary Compatibility ? GUID does not change, references from other components will work</span></span></li><li><span
style="font-weight: 400;"><strong><span
style="font-size: x-small;">Why iss it important to use source control software for source code?</span></strong><span
style="font-size: x-small;"><span
class="Apple-converted-space"> </span><em>Expected answer:</em>Modification history.Code ownership: Multiple people can not modify the same code at the same time.</span></span></li><li><span
style="font-weight: 400;"><strong><span
style="font-size: x-small;">What two methods are called from the ObjectContext object to inform MTS that the transaction was successful or unsuccessful?</span></strong><span
style="font-size: x-small;"><span
class="Apple-converted-space"> </span><em>Expected answer:</em><span
class="Apple-converted-space"> </span>SetComplete and SetAbort.</span></span></li><li><span
style="font-weight: 400;"><strong><span
style="font-size: x-small;">What is the tool used to configure the port range and protocols for DCOM communications?</span></strong><span
style="font-size: x-small;"><span
class="Apple-converted-space"> </span><em>Expected answer:</em><span
class="Apple-converted-space"> </span>DCOMCONFIG.EXE</span></span></li><li><span
style="font-weight: 400;"><strong><span
style="font-size: x-small;">What does Option Explicit refer to?</span></strong><span
style="font-size: x-small;"><span
class="Apple-converted-space"> </span><em>Expected answer:</em><span
class="Apple-converted-space"> </span>All variables must be declared before use. Their type is not required.</span></span></li><li><span
style="font-weight: 400;"><strong><span
style="font-size: x-small;">What are the different ways to Declare and Instantiate an object in Visual Basic 6?</span></strong><span
style="font-size: x-small;"><em>Expected answer:</em><span
class="Apple-converted-space"> </span>Dim obj as OBJ.CLASS with eitherSet obj = New OBJ.CLASS orSet obj = CreateObject(?OBJ.CLASS?) orSet obj = GetObject( ,? OBJ.CLASS?)orDim obj as New OBJ.CLASS</span></span></li><li><span
style="font-weight: 400;"><strong><span
style="font-size: x-small;">Name the four different cursor types in ADO and describe them briefly.</span></strong><span
style="font-size: x-small;"><span
class="Apple-converted-space"> </span><em>Expected answer:</em>The cursor types are listed from least to most resource intensive.Forward Only ? Fastest, can only move forward in recordset Static ? Can move to any record in the recordset. Data is static and never changes.KeySet ? Changes are detectable, records that are deleted by other users are unavailable, and records created by other users are not detectedDynamic ? All changes are visible.</span></span></li><li><span
style="font-weight: 400;"><strong><span
style="font-size: x-small;">Name the four different locking type in ADO and describe them briefly.</span></strong><span
style="font-size: x-small;"><span
class="Apple-converted-space"> </span><em>Expected answer:</em>LockPessimistic ? Locks the row once after any edits occur.LockOptimistic ? Locks the row only when Update is called.LockBatchOptimistic ? Allows Batch Updates.LockReadOnly ? Read only. Can not alter the data.</span></span></li><li><span
style="font-weight: 400;"><strong><span
style="font-size: x-small;">Describe Database Connection pooling (relative to MTS )</span></strong><span
style="font-size: x-small;"><span
class="Apple-converted-space"> </span><em>Expected answer:</em><span
class="Apple-converted-space"> </span>This allows MTS to reuse database connections. Database connections are put to ?sleep? as opposed to being created and destroyed and are activated upon request.</span></span></li><li><span
style="font-weight: 400;"><strong><span
style="font-size: x-small;">What are the ADO objects? Explain them. Provide a scenario using three of them to return data from a database.</span></strong><span
style="font-size: x-small;"><span
class="Apple-converted-space"> </span><em>Expected answer:</em><span
class="Apple-converted-space"> </span>Connection ? Connects to a data source; contains the Errors collectionCommand ? Executes commands to the data source. Is the only object that can accept parameters for a stored procedure.Recordset ? The set of data returned from the database.Scenario: There are many possibilities. The most likely is as follows:Dim conn As ADODB.ConnectionDim rs As ADODB.RecordsetDim Cmd As ADODB.Commandconn.ConnectionString = ?CONNECTION STRING?conn.OpenSet Cmd.ActiveConnection = connCmd.CommandText = ?SQL STATEMENT?Set rs = Cmd.ExecuteSet rs.ActiveConnection = Nothingconn.Close</span></span></li><li><span
style="font-weight: 400;"><strong><span
style="font-size: x-small;">Under the ADO Command Object, what collection is responsible for input to stored procedures?</span></strong><span
style="font-size: x-small;"><span
class="Apple-converted-space"> </span><em>Expected answer:</em><span
class="Apple-converted-space"> </span>The Parameters collection.</span></span></li><li><span
style="font-weight: 400;"><strong><span
style="font-size: x-small;">What are some benefits of using MTS?</span></strong><span
style="font-size: x-small;"><span
class="Apple-converted-space"> </span><em>Expected answer:</em><span
class="Apple-converted-space"> </span>Database Pooling, Transactional operations, Deployment, Security, Remote Execution.</span></span></li><li><span
style="font-weight: 400;"><strong><span
style="font-size: x-small;">What is the benefit of wrapping database calls into MTS transactions?</span></strong><span
style="font-size: x-small;"><span
class="Apple-converted-space"> </span><em>Expected answer:</em>If database calls are made within the context of a transaction, aborting the transaction will undo and changes that occur within that transaction. This removes the possibility of stranded, or partial data.</span></span></li><li><span
style="font-weight: 400;"><strong><span
style="font-size: x-small;">Describe and In Process vs. Out of Process component. Which is faster?</span></strong><span
style="font-size: x-small;"><span
class="Apple-converted-space"> </span><em>Expected answer:</em>An in-process component is implemented as a DLL, and runs in the same process space as its client app, enabling the most efficient communication between client and component.Each client app that uses the component starts a new instance of it.An out of process component is implemented as an EXE, and unlike a dll, runs in its own process space. As a result, exe’s are slower then dll’s because communications between client and component must be marshalled across process boundaries. A single instance of an out of process component can service many clients.</span></span></li><li><span
style="font-weight: 400;"><strong><span
style="font-size: x-small;">What are the main components of the ADO object model? How are they used?</span></strong><span
style="font-size: x-small;"><span
class="Apple-converted-space"> </span><em>Expected answer:</em>Connection: Used to make a connection between your app and an external data source, ie, sql server.Command: Used to build queries, including user-specific parameters, to access records from a data source (which are returned in a Recordset)Recordset:Used to access records returned from an SQL query. With a recordset, you can navigate returned records. You can also add, modify or delete records.</span></span></li></ol><p>* more <a
href="planetetutors.com">here</a></td></tr></tbody></table> ]]></content:encoded> <wfw:commentRss>http://www.freequestionbank.com/question/visual-basic-interview-questions/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>C Interview Questions</title><link>http://www.freequestionbank.com/question/c-interview-questions/</link> <comments>http://www.freequestionbank.com/question/c-interview-questions/#comments</comments> <pubDate>Thu, 26 Mar 2009 07:43:04 +0000</pubDate> <dc:creator>admin</dc:creator> <category><![CDATA[Exam]]></category> <category><![CDATA[Languages]]></category> <category><![CDATA[Question]]></category> <category><![CDATA[c++]]></category> <category><![CDATA[Interview]]></category><guid
isPermaLink="false">http://www.freequestionbank.com/?p=420</guid> <description><![CDATA[1.Difference between arrays and pointers?
- Pointers are used to manipulate data using the address. Pointers use * operator to ...]]></description> <content:encoded><![CDATA[<table
id="AutoNumber1" style="border-collapse: collapse; height: 354px;" border="0" cellspacing="0" cellpadding="0" width="100%" bordercolor="#111111"><tbody><tr><td
width="97%" height="240" valign="top"><span
style="font-weight: 400;"><strong><span
style="font-size: x-small;">1.Difference between arrays and pointers?</span></strong><span
style="font-size: x-small;"><span
class="Apple-converted-space"> </span><br
/> - Pointers are used to manipulate data using the address. Pointers use * operator to access the data pointed to by them</p><p>- Arrays use subscripted variables to access and manipulate data.Array variables can be equivalently written using pointer expression.<span
class="Apple-converted-space"> </span></p><p></span></span><span
style="font-weight: 400;"><span
style="font-size: x-small;">2<strong>. What are the advantages of the functions?</strong></span></span></p><p><span
style="font-weight: 400;"><span
style="font-size: x-small;"> <strong>Answer</strong> &#8211; Debugging is easier</span></span></p><p>- It is easier to understand the logic involved in the program<br
/> - Testing is easier<br
/> - Recursive call is possible<br
/> - Irrelevant details in the user point of view are hidden in functions<br
/> - Functions are helpful in generalizing the program<span
class="Apple-converted-space"> </span></p><p><span
style="font-weight: 400;"><span
style="font-size: x-small;">3<strong><span
class="Apple-converted-space"> </span>How can I open a file so that other programs can update it at the same time?</strong></span></span></p><p><span
style="font-weight: 400;"><strong><span
style="font-size: x-small;">Answer</span></strong><span
style="font-size: x-small;"><span
class="Apple-converted-space"> </span>Your C compiler library contains a low-level file function called sopen() that can be used to open a file in shared mode. Beginning with DOS 3.0, files could be opened in shared mode by loading a special program named SHARE.EXE. Shared mode, as the name implies, allows a file to be shared with other programs as well as your own.</span></span></p><p>Using this function, you can allow other programs that are running to update the same file you are updating.</p><p>The sopen() function takes four parameters: a pointer to the filename you want to open, the operational<br
/> mode you want to open the file in, the file sharing mode to use, and, if you are creating a file, the mode to create the file in. The second parameter of the sopen() function, usually referred to as the “operation flag”parameter, can have the following values assigned to it:</p><p>Constant Description O_APPEND Appends all writes to the end of the file</p><p>O_BINARY Opens the file in binary (untranslated) mode<br
/> O_CREAT If the file does not exist, it is created<br
/> O_EXCL If the O_CREAT flag is used and the file exists, returns an error<br
/> O_RDONLY Opens the file in read-only mode<br
/> O_RDWR Opens the file for reading and writing<br
/> O_TEXT Opens the file in text (translated) mode<br
/> O_TRUNC Opens an existing file and writes over its contents<br
/> O_WRONLY Opens the file in write-only mode</p><p>The third parameter of the sopen() function, usually referred to as the “sharing flag,” can have the following values assigned to it:</p><p>Constant Description<br
/> SH_COMPAT No other program can access the file<br
/> SH_DENYRW No other program can read from or write to the file<br
/> SH_DENYWR No other program can write to the file<br
/> SH_DENYRD No other program can read from the file<br
/> SH_DENYNO Any program can read from or write to the file</p><p>If the sopen() function is successful, it returns a non-negative number that is the file’s handle. If an error occurs, –1 is returned, and the global variable errno is set to one of the following values:</p><p>Constant Description<br
/> ENOENT File or path not found<br
/> EMFILE No more file handles are available<br
/> EACCES Permission denied to access file<br
/> EINVACC Invalid access code<br
/> Constant Description<span
class="Apple-converted-space"> </span></p><p><span
style="font-weight: 400;"><span
style="font-size: x-small;">4.<span
class="Apple-converted-space"> </span><strong>Can static variables be declared in a header file?</strong></span></span></p><p><span
style="font-weight: 400;"><span
style="font-size: x-small;"> You can’t declare a static variable without defining it as well (this is because the storage class modifiers<br
/> static and extern are mutually exclusive). A static variable can be defined in a header file, but this would cause each source file that included the header file to have its own private copy of the variable, which is probably not what was intended.<span
class="Apple-converted-space"> </span><br
/> 6.<strong>How can you check to see whether a symbol is defined?</strong></span></span></p><p><span
style="font-weight: 400;"><span
style="font-size: x-small;"> You can use the #ifdef and #ifndef preprocessor directives to check whether a symbol has been defined<br
/> (#ifdef) or whether it has not been defined (#ifndef).<span
class="Apple-converted-space"> </span><br
/> </span></span></p><p><span
style="font-weight: 400;"><span
style="font-size: x-small;">7.<strong>How do you override a defined macro?</strong></span></span></p><p><span
style="font-weight: 400;"><strong><span
style="font-size: x-small;">Answer</span></strong><span
style="font-size: x-small;"><span
class="Apple-converted-space"> </span><br
/> You can use the #undef preprocessor directive to undefine (override) a previously defined macro.<span
class="Apple-converted-space"> </span><br
/> </span></span></p><p><span
style="font-weight: 400;"><span
style="font-size: x-small;">10.<span
class="Apple-converted-space"> </span><strong>Can a variable be both const and volatile?</strong></span></span></p><p><span
style="font-weight: 400;"><span
style="font-size: x-small;"> Yes. The const modifier means that this code cannot change the value of the variable, but that does not mean that the value cannot be changed by means outside this code. For instance, in the example in<br
/> FAQ 8, the timer structure was accessed through a volatile const pointer. The function itself did not change the value of the timer, so it was declared const. However, the value was changed by hardware on the computer, so it was declared volatile. If a variable is both const and volatile, the two modifiers can appear in either order.<span
class="Apple-converted-space"> </span><br
/> 11.<span
class="Apple-converted-space"> </span><strong>Can include files be nested?</strong></span></span></p><p><span
style="font-weight: 400;"><span
style="font-size: x-small;"> <span
class="Apple-converted-space"> </span><br
/> Yes. Include files can be nested any number of times. As long as you use precautionary measures , you can avoid including the same file twice. In the past, nesting header files was seen as bad programming practice, because it complicates the dependency tracking function of the MAKE program and thus slows down compilation. Many of today’s popular compilers make up for this difficulty by implementing a concept called precompiled headers, in which all headers and associated dependencies are stored in<br
/> a precompiled state.<span
class="Apple-converted-space"> </span></span></span></p><p>Many programmers like to create a custom header file that has #include statements for every header needed for each module. This is perfectly acceptable and can help avoid potential problems relating to #include files, such as accidentally omitting an #include file in a module.<span
class="Apple-converted-space"> </span></p><p><span
style="font-weight: 400;"><span
style="font-size: x-small;">12.<span
class="Apple-converted-space"> </span><strong>Can static variables be declared in a header file?<span
class="Apple-converted-space"> </span><br
/> </strong>Yes there is difference between declaring a static variable as global and local. If it is local, it can be accessed only in the function where it&#8217;s declared. But if it is global, all functions can access it. But, what ever be the case, its value will be retained between functions.<br
/> </span></span></p><p><span
style="font-weight: 400;"><span
style="font-size: x-small;">13.<span
class="Apple-converted-space"> </span><strong>When does the compiler not implicitly generate the address of the first element of an array?</strong></span></span></p><p><span
style="font-weight: 400;"><span
style="font-size: x-small;"> Whenever an array name appears in an expression such as</span></span></p><p>- array as an operand of the sizeof operator</p><p>- array as an operand of &amp; operator</p><p>- array as a string literal initializer for a character array</p><p>Then the compiler does not implicitly generate the address of the address of the first element of an array.<span
class="Apple-converted-space"> </span></p><p><span
style="font-weight: 400;"><span
style="font-size: x-small;">14.<strong>What is the difference between #include &lt;file&gt; and #include “file”?</strong></span></span></p><p><span
style="font-weight: 400;"><span
style="font-size: x-small;">When writing your C program, you can include files in two ways. The first way is to surround the file you<br
/> want to include with the angled brackets &lt; and &gt;. This method of inclusion tells the preprocessor to look for the file in the predefined default location. This predefined default location is often an INCLUDE environment variable that denotes the path to your include files. For instance, given the INCLUDE variable</span></span></p><p>INCLUDE=C:\COMPILER\INCLUDE;S:\SOURCE\HEADERS;</p><p>using the #include &lt;file&gt; version of file inclusion, the compiler first checks the C:\COMPILER\INCLUDE<br
/> directory for the specified file. If the file is not found there, the compiler then checks the<br
/> S:\SOURCE\HEADERS directory. If the file is still not found, the preprocessor checks the current directory.<span
class="Apple-converted-space"> </span></p><p>The second way to include files is to surround the file you want to include with double quotation marks. This method of inclusion tells the preprocessor to look for the file in the current directory first, then look for it in the predefined locations you have set up. Using the #include “file” version of file inclusion and applying it to the preceding example, the preprocessor first checks the current directory for the specified file. If the file is not found in the current directory, the C:COMPILERINCLUDE directory is searched. If the file is still not found, the preprocessor checks the S:SOURCEHEADERS directory.<br
/> The #include &lt;file&gt; method of file inclusion is often used to include standard headers such as stdio.h or<br
/> stdlib.h. This is because these headers are rarely (if ever) modified, and they should always be read from your compiler’s standard include file directory.</p><p>The #include “file” method of file inclusion is often used to include nonstandard header files that you have created for use in your program. This is because these headers are often modified in the current directory, and you will want the preprocessor to use your newly modified version of the header rather than the older, unmodified version.<span
class="Apple-converted-space"> </span></p><p><span
style="font-weight: 400;"><span
style="font-size: x-small;">15.<strong>When function say abc() calls another function say xyz(), what happens in stack?<br
/> </strong>When some function xyz() calls function abc(). all the local variables, static links, dynamic links and function return value goes on the top of all elements of function xyz() in the stack. when abc() exit it&#8217;s return value has been assigned to xyz().<span
class="Apple-converted-space"> </span><br
/> </span></span></p><p><span
style="font-weight: 400;"><span
style="font-size: x-small;">16.<strong>How do you print an address?<span
class="Apple-converted-space"> </span><br
/> </strong>we can print the address of a variable or a function using the following specifiers %u,%p here %u prints address in decimal form and %p prints in hexa decimal form,but remember these two format specifiers print only offset adress but they doesn&#8217;t print code segment address<span
class="Apple-converted-space"> </span></span></span></p><p>there is a another specifier %Fp which prints both the code segment and offset address</p><p><span
style="font-weight: 400;"><span
style="font-size: x-small;">18.<strong>How to find entered number is EVEN or ODD without using conditional statement(not using if.. else,if.. , else if..,while, do&#8230; while&#8230;., for&#8230;.)<br
/> </strong>We can find a number is odd or even by a simple programmain(){int a[2],i;a[0]=0; //0&#8211;means Even Numbera[1]=1; //1&#8211;means Odd numberscanf(&#8220;%d&#8221;,&amp;i);printf(&#8220;%d&#8221;,a[i%2]);getch();}<span
class="Apple-converted-space"> </span><br
/> </span></span></p><p><span
style="font-weight: 400;"><span
style="font-size: x-small;">19.<strong>How to break cycle in circular single link list?<br
/> </strong>we can delete an intermediate one</span></span></p><p><span
style="font-weight: 400;"><span
style="font-size: x-small;">20.<strong>How can I convert a number to a string?<span
class="Apple-converted-space"> </span><br
/> </strong>We can convert number to string using built in function itoa().</span></span></p><p><span
style="font-weight: 400;"><span
style="font-size: x-small;">21.<strong>How to swap the content oftwo variables without a temporary variable<br
/> </strong>void swap(int a,int b)</span></span></p><p>{</p><p>a =a+b;</p><p>b=a-b;</p><p>a=a-b;</p><p>}</p><p><span
style="font-weight: 400;"><span
style="font-size: x-small;">22.<span
class="Apple-converted-space"> </span><strong>How can send unlimited no of arguments to a function, eg printf function can take any no of arguments<br
/> </strong><br
/> using va_list variables in stdarg.h headerfile</span></span></p><p><span
style="font-weight: 400;"><span
style="font-size: x-small;">23.<strong>What is the benefit of using #define to declare a constant?</strong><span
class="Apple-converted-space"> </span><br
/> Using the #define method of declaring a constant enables you to declare a constant in one place and use it throughout your program. This helps make your programs more maintainable, because you need to maintain only the #define statement and not several instances of individual constants throughout your program.</span></span></p><p>For instance, if your program used the value of pi (approximately 3.14159) several times, you might want to declare a constant for pi as follows:</p><p>#define PI 3.14159</p><p>Using the #define method of declaring a constant is probably the most familiar way of declaring constants to traditional C programmers. Besides being the most common method of declaring constants, it also takes up the least memory. Constants defined in this manner are simply placed directly into your source code, with no variable space allocated in memory. Unfortunately, this is one reason why most debuggers cannot inspect constants created using the #define method.<span
class="Apple-converted-space"> </span></p><p><span
style="font-weight: 400;"><span
style="font-size: x-small;">24.<strong>How do you write a C program which can calculate lines of code but not counting comments?<br
/> </strong><br
/> Using file concept with Command line arguments.declare a variable (lcnt) used to count the no of lines.Open a file in read made and then using while loop check the condition for not equal to EOF.Later using if condition check check for new line and increment the variable for counting the lines.</span></span></p><p>Then using while,check for the character &#8216;/&#8217;,'*&#8217; (as the comments start with these characters) and end with (&#8216;*&#8217; and &#8216;/&#8217;).if condition of this is true then break and come out of the block else increment the line.</p><p><span
style="font-weight: 400;"><span
style="font-size: x-small;">25.<strong>How can I search for data in a linked list?</strong></span></span></p><p><span
style="font-weight: 400;"><span
style="font-size: x-small;"> Unfortunately, the only way to search a linked list is with a linear search, because the only way a linked list’s members can be accessed is sequentially. Sometimes it is quicker to take the data from a linked list and store it in a different data structure so that searches can be more efficient.<span
class="Apple-converted-space"> </span><br
/> </span></span></p><p><span
style="font-weight: 400;"><span
style="font-size: x-small;">26.<strong>How to write a C program to find the power of 2 in a normal way and in single step?<br
/> </strong><br
/> U can take logarithm base 2, and check the result is in interger form or floating point form, u can check whether it is power of 2 or not.<span
class="Apple-converted-space"> </span><br
/> </span></span></p><p><span
style="font-weight: 400;"><span
style="font-size: x-small;">27.<strong>What is hashing?</strong><span
class="Apple-converted-space"> </span><br
/> To hash means to grind up, and that’s essentially what hashing is all about. The heart of a hashing algorithm is a hash function that takes your nice, neat data and grinds it into some random-looking integer.</span></span></p><p>The idea behind hashing is that some data either has no inherent ordering (such as images) or is expensive to compare (such as images). If the data has no inherent ordering, you can’t perform comparison searches.</p><p>If the data is expensive to compare, the number of comparisons used even by a binary search might be too many. So instead of looking at the data themselves, you’ll condense (hash) the data to an integer (its hash value) and keep all the data with the same hash value in the same place. This task is carried out by using the hash value as an index into an array.</p><p>To search for an item, you simply hash it and look at all the data whose hash values match that of the data you’re looking for. This technique greatly lessens the number of items you have to look at. If the parameters are set up with care and enough storage is available for the hash table, the number of comparisons needed to find an item can be made arbitrarily close to one.</p><p>One aspect that affects the efficiency of a hashing implementation is the hash function itself. It should ideally distribute data randomly throughout the entire hash table, to reduce the likelihood of collisions. Collisions occur when two different keys have the same hash value. There are two ways to resolve this problem. In “open addressing,” the collision is resolved by the choosing of another position in the hash table for the element inserted later. When the hash table is searched, if the entry is not found at its<br
/> hashed position in the table, the search continues checking until either the element is found or an empty position in the table is found<span
class="Apple-converted-space"> </span></p><p>The second method of resolving a hash collision is called “chaining.” In this method, a “bucket” or linked list holds all the elements whose keys hash to the same value.<span
class="Apple-converted-space"> </span></p><p>When the hash table is searched, the list must be searched linearly.<span
class="Apple-converted-space"> </span></p><p><span
style="font-weight: 400;"><span
style="font-size: x-small;">28.<strong>Diffence arrays and pointers?<br
/> </strong><br
/> To access data using pointers we use the *.</span></span></p><p>to access data stored in array we use indexes such as a[0].</p><p><span
style="font-weight: 400;"><span
style="font-size: x-small;">30.<strong>Can a variable be both const and volatile?<span
class="Apple-converted-space"> </span><br
/> </strong><br
/> This is possible and mostly used in embedded system.The example is Interrupt Status Register.As it is a status register , in the program we should not modify this variable.So it should be a constant.But this variable can be changed by the processor or hardware based on the interrupt condition.So when in the program ,we want to read the value of this varible , it should read the actual value with out any optimisation.For this reason ,the variable can be declared as volatile too</span></span></p><p><span
style="font-weight: 400;"><span
style="font-size: x-small;">31.<strong>Why should we assign NULL to the elements (pointer) after freeing them?</strong></span></span></p><p><span
style="font-weight: 400;"><strong><span
style="font-size: x-small;">Answer</span></strong><span
style="font-size: x-small;"><span
class="Apple-converted-space"> </span><br
/> This is paranoia based on long experience. After a pointer has been freed, you can no longer use the pointed-to data. The pointer is said to “dangle”; it doesn’t point at anything useful. If you “NULL out” or “zero out” a pointer immediately after freeing it, your program can no longer get in trouble by using that pointer. True, you might go indirect on the null pointer instead, but that’s something your debugger might be able to help you with immediately. Also, there still might be copies of the pointer that refer<br
/> to the memory that has been deallocated; that’s the nature of C. Zeroing out pointers after freeing them won’t solve all problems;<span
class="Apple-converted-space"> </span><br
/> </span></span></p><p><span
style="font-weight: 400;"><span
style="font-size: x-small;">32.<strong>What is a “null pointer assignment” error? What are bus errors, memory faults, and core dumps?</strong><span
class="Apple-converted-space"> </span><br
/> These are all serious errors, symptoms of a wild pointer or subscript.</span></span></p><p>Null pointer assignment is a message you might get when an MS-DOS program finishes executing. Some<br
/> such programs can arrange for a small amount of memory to be available “where the NULL pointer points to” (so to speak). If the program tries to write to that area, it will overwrite the data put there by the compiler.</p><p>When the program is done, code generated by the compiler examines that area. If that data has been changed, the compiler-generated code complains with null pointer assignment.</p><p>This message carries only enough information to get you worried. There’s no way to tell, just from a null<br
/> pointer assignment message, what part of your program is responsible for the error. Some debuggers, and some compilers, can give you more help in finding the problem.</p><p>Bus error: core dumped and Memory fault: core dumped are messages you might see from a program running under UNIX. They’re more programmer friendly. Both mean that a pointer or an array subscript was wildly out of bounds. You can get these messages on a read or on a write. They aren’t restricted to null pointer problems.</p><p>The core dumped part of the message is telling you about a file, called core, that has just been written in your current directory. This is a dump of everything on the stack and in the heap at the time the program was running. With the help of a debugger, you can use the core dump to find where the bad pointer was used.</p><p>That might not tell you why the pointer was bad, but it’s a step in the right direction. If you don’t have write permission in the current directory, you won’t get a core file, or the core dumped message.<span
class="Apple-converted-space"> </span></p><p><span
style="font-weight: 400;"><span
style="font-size: x-small;">33.</span><strong><span
style="font-size: x-small;">What are storage class in c</span></strong></span></p><p><span
style="font-weight: 400;"><strong><span
style="font-size: x-small;">Answer</span></strong><span
style="font-size: x-small;"><span
class="Apple-converted-space"> </span><br
/> There r of 4 type of storage class in C</span></span></p><p>static</p><p>auto</p><p>register</p><p>extern</p><p><span
style="font-weight: 400;"><span
style="font-size: x-small;">34.<strong>Following declarations are different from one another<br
/> const char *const s;<span
class="Apple-converted-space"> </span><br
/> char const *const s;<span
class="Apple-converted-space"> </span></strong></span></span></p><p><strong>Answer</strong><span
class="Apple-converted-space"> </span><br
/> There is no difference between the two declarations.</p><p><span
style="font-weight: 400;"><span
style="font-size: x-small;">35.<strong>When should a type cast be used?</strong></span></span></p><p><span
style="font-weight: 400;"><span
style="font-size: x-small;"><br
/> There are two situations in which to use a type cast. The first use is to change the type of an operand to an arithmetic operation so that the operation will be performed properly.</span></span></p><p>The second case is to cast pointer types to and from void * in order to interface with functions that expect or return void pointers. For example, the following line type casts the return value of the call to malloc() to be a pointer to a foo structure.<span
class="Apple-converted-space"> </span></p><p>struct foo *p = (struct foo *) malloc(sizeof(struct foo));<span
class="Apple-converted-space"> </span></p><p><span
style="font-weight: 400;"><span
style="font-size: x-small;">36.<strong>What is a null pointer?</strong></span></span></p><p><span
style="font-weight: 400;"><span
style="font-size: x-small;">There are times when it’s necessary to have a pointer that doesn’t point to anything. The macro NULL, defined in &lt;stddef.h&gt;, has a value that’s guaranteed to be different from any valid pointer. NULL is a literal zero, possibly cast to void* or char*. Some people, notably C++ programmers, prefer to use 0 rather than NULL.</span></span></p><p>The null pointer is used in three ways:</p><p>1) To stop indirection in a recursive data structure</p><p>2) As an error value</p><p>3) As a sentinel value<span
class="Apple-converted-space"> </span></p><p><span
style="font-weight: 400;"><span
style="font-size: x-small;">36.</span></span><strong><span
style="font-weight: 400;"><span
style="font-size: x-small;">What is a const pointer?</span></span></strong></p><p><span
style="font-weight: 400;"><span
style="font-size: x-small;"><br
/> There are cases when you need to define a constant pointer to a variable/object; for instance, when taking a function address, or when you want to protect a pointer from unintended modifications such as assignment of new address, pointer arithmetic, etc. In fact, an object’s this is a constpointer. A constant pointer is declared:</span></span></p><p><span
style="font-weight: 400;"><span
style="font-size: x-small;">37.<strong>when should the volatile modifier be used?</strong></span></span></p><p><span
style="font-weight: 400;"><span
style="font-size: x-small;"><br
/> The volatile modifier is a directive to the compiler’s optimizer that operations involving this variable should not be optimized in certain ways. There are two special cases in which use of the volatile modifier is desirable. The first case involves memory-mapped hardware (a device such as a graphics adaptor that appears to the computer’s hardware as if it were part of the computer’s memory), and the second involves shared memory (memory used by two or more programs running simultaneously).</span></span></p><p>Most computers have a set of registers that can be accessed faster than the computer’s main memory. A good compiler will perform a kind of optimization called “redundant load and store removal.” The compiler looks for places in the code where it can either remove an instruction to load data from memory because the value is already in a register, or remove an instruction to store data to memory because the value can stay in a register until it is changed again anyway.</p><p>If a variable is a pointer to something other than normal memory, such as memory-mapped ports on a<br
/> peripheral, redundant load and store optimizations might be detrimental. For instance, here’s a piece of code that might be used to time some operation:<span
class="Apple-converted-space"> </span></p><p>time_t time_addition(volatile const struct timer *t, int a)<br
/> {<br
/> int n;<br
/> int x;<br
/> time_t then;<br
/> x = 0;<br
/> then = t-&gt;value;<br
/> for (n = 0; n &lt; 1000; n++)<br
/> {<br
/> x = x + a;<br
/> }<br
/> return t-&gt;value &#8211; then;<br
/> }</p><p>In this code, the variable t-&gt;value is actually a hardware counter that is being incremented as time passes. The function adds the value of a to x 1000 times, and it returns the amount the timer was incremented by while the 1000 additions were being performed. Without the volatile modifier, a clever optimizer might assume that the value of t does not change during the execution of the function, because there is no statement that explicitly changes it. In that case, there’s no need to read it from memory a second time and subtract it, because the answer will always be 0. The compiler might therefore “optimize” the function by making it always return 0.</p><p>If a variable points to data in shared memory, you also don’t want the compiler to perform redundant load and store optimizations. Shared memory is normally used to enable two programs to communicate with each other by having one program store data in the shared portion of memory and the other program read the same portion of memory. If the compiler optimizes away a load or store of shared memory, communication between the two programs will be affected.<span
class="Apple-converted-space"> </span></p><p><span
style="font-weight: 400;"><span
style="font-size: x-small;">38.<strong>What is the benefit of using an enum rather than a #define constant?</strong></span></span></p><p><span
style="font-weight: 400;"><span
style="font-size: x-small;">The use of an enumeration constant (enum) has many advantages over using the traditional symbolic constant style of #define. These advantages include a lower maintenance requirement, improved program readability, and better debugging capability.</span></span></p><p>1) The first advantage is that enumerated constants are generated automatically by the compiler. Conversely, symbolic constants must be manually assigned values by the programmer.</p><p>For instance, if you had an enumerated constant type for error codes that could occur in your program, your enum definition could look something like this:</p><p>enum Error_Code<br
/> {<br
/> OUT_OF_MEMORY,<br
/> INSUFFICIENT_DISK_SPACE,<br
/> LOGIC_ERROR,<br
/> FILE_NOT_FOUND<br
/> };</p><p>In the preceding example, OUT_OF_MEMORY is automatically assigned the value of 0 (zero) by the compiler because it appears first in the definition. The compiler then continues to automatically assign numbers to the enumerated constants, making INSUFFICIENT_DISK_SPACE equal to 1, LOGIC_ERROR equal to 2, and FILE_NOT_FOUND equal to 3, so on.</p><p>If you were to approach the same example by using symbolic constants, your code would look something like this:</p><p>#define OUT_OF_MEMORY 0<br
/> #define INSUFFICIENT_DISK_SPACE 1<br
/> #define LOGIC_ERROR 2<br
/> #define FILE_NOT_FOUND 3</p><p>values by the programmer. Each of the two methods arrives at the same result: four constants assigned numeric values to represent error codes. Consider the maintenance required, however, if you were to add two constants to represent the error codes DRIVE_NOT_READY and CORRUPT_FILE. Using the enumeration constant method, you simply would put these two constants anywhere in the enum definition. The compiler would generate two unique values for these constants. Using the symbolic constant method, you would have to manually assign two new numbers to these constants. Additionally, you would want to ensure that the numbers you assign to these constants are unique.</p><p>2) Another advantage of using the enumeration constant method is that your programs are more readable and thus can be understood better by others who might have to update your program later.</p><p>3) A third advantage to using enumeration constants is that some symbolic debuggers can print the value of an enumeration constant. Conversely, most symbolic debuggers cannot print the value of a symbolic constant. This can be an enormous help in debugging your program, because if your program is stopped at a line that uses an enum, you can simply inspect that constant and instantly know its value. On the other hand, because most debuggers cannot print #define values, you would most likely have to search for that value by manually looking it up in a header file.<span
class="Apple-converted-space"> </span></p><p><span
style="font-weight: 400;"><span
style="font-size: x-small;">39.<strong>When is a switch statement better than multiple if statements?<span
class="Apple-converted-space"> </span><br
/> </strong><br
/> The switch statement is better than multiple if statements when there are more than two alternatives to be selected whether the case value matches to the variable of either character or integer type.<span
class="Apple-converted-space"> </span><br
/> </span></span></p><p><span
style="font-weight: 400;"><span
style="font-size: x-small;">40.<strong>What is the difference between a string copy (strcpy) and a memory copy (memcpy)? When should each be used?</strong><span
class="Apple-converted-space"> </span><br
/> The strcpy() function is designed to work exclusively with strings. It copies each byte of the source string to the destination string and stops when the terminating null character () has been moved. On the other hand, the memcpy() function is designed to work with any type of data. Because not all data ends with a null character, you must provide the memcpy() function with the number of bytes you want to copy from the source to the destination.<span
class="Apple-converted-space"> </span><br
/> </span></span></p><p><span
style="font-weight: 400;"><span
style="font-size: x-small;">41.<strong>How can I convert a string to a number?</strong></span></span></p><p><span
style="font-weight: 400;"><span
style="font-size: x-small;"><br
/> The standard C library provides several functions for converting strings to numbers of all formats (integers, longs, floats, and so on) and vice versa.</span></span></p><p>The following functions can be used to convert strings to numbers:</p><p>Function Name Purpose</p><p>atof() Converts a string to a double-precision floating-point value.</p><p>atoi() Converts a string to an integer.</p><p>atol() Converts a string to a long integer.</p><p>strtod() Converts a string to a double-precision floating-point value and reports any “leftover” numbers that could not be converted.</p><p>strtol() Converts a string to a long integer and reports any “leftover” numbers that could not be converted.</p><p>strtoul() Converts a string to an unsigned long integer and reports any “leftover” numbers that could not be converted.</p><p><span
style="font-weight: 400;"><span
style="font-size: x-small;">41.<strong>How can I convert a number to a string?</strong></span></span></p><p><span
style="font-weight: 400;"><span
style="font-size: x-small;"><br
/> The standard C library provides several functions for converting numbers of all formats (integers, longs, floats, and so on) to strings and vice versa The following functions can be used to convert integers to strings:</span></span></p><p>Function Name Purpose</p><p>itoa() Converts an integer value to a string.</p><p>ltoa() Converts a long integer value to a string.</p><p>ultoa() Converts an unsigned long integer value to a string.</p><p>The following functions can be used to convert floating-point values to strings:</p><p>Function Name Purpose</p><p>ecvt() Converts a double-precision floating-point value to a string without an embedded decimal point.</p><p>fcvt() Same as ecvt(), but forces the precision to a specified number of digits.</p><p>gcvt() Converts a double-precision floating-point value to a string with an embedded decimal point.</p><p><span
style="font-weight: 400;"><span
style="font-size: x-small;">42.<strong>Is it possible to execute code even after the program exits the main() function?<span
class="Apple-converted-space"> </span><br
/> </strong><br
/> The standard C library provides a function named atexit() that can be used to perform “cleanup” operations when your program terminates. You can set up a set of functions you want to perform automatically when your program exits by passing function pointers to the atexit() function.<span
class="Apple-converted-space"> </span><br
/> </span></span></p><p><strong><span
style="font-weight: 400;"><span
style="font-size: x-small;">What is the stack?</span></span></strong><span
style="font-weight: 400;"><span
style="font-size: x-small;"><span
class="Apple-converted-space"> </span><br
/> The stack is where all the functions’ local (auto) variables are created. The stack also contains some<br
/> information used to call and return from functions.</span></span></p><p>A “stack trace” is a list of which functions have been called, based on this information. When you start using a debugger, one of the first things you should learn is how to get a stack trace.</p><p>The stack is very inflexible about allocating memory; everything must be deallocated in exactly the reverse order it was allocated in. For implementing function calls, that is all that’s needed. Allocating memory off the stack is extremely efficient. One of the reasons C compilers generate such good code is their heavy use of a simple stack.</p><p>There used to be a C function that any programmer could use for allocating memory off the stack. The<br
/> memory was automatically deallocated when the calling function returned. This was a dangerous function to call; it’s not available anymore.<span
class="Apple-converted-space"> </span></p><p><strong><span
style="font-weight: 400;"><span
style="font-size: x-small;">How do you print an address?</span></span></strong><span
style="font-weight: 400;"><span
style="font-size: x-small;"><span
class="Apple-converted-space"> </span><br
/> The safest way is to use printf() (or fprintf() or sprintf()) with the %P specification. That prints a void<br
/> pointer (void*). Different compilers might print a pointer with different formats. Your compiler will pick<br
/> a format that’s right for your environment.</span></span></p><p>If you have some other kind of pointer (not a void*) and you want to be very safe, cast the pointer to a void*:<span
class="Apple-converted-space"> </span></p><p>printf( “%Pn”, (void*) buffer );<span
class="Apple-converted-space"> </span></p><p><span
style="font-weight: 400;"><span
style="font-size: x-small;">45.<strong>When should the register modifier be used? Does it really help?</strong></span></span></p><p><span
style="font-weight: 400;"><span
style="font-size: x-small;">The register modifier hints to the compiler that the variable will be heavily used and should be kept in the CPU’s registers, if possible, so that it can be accessed faster.<span
class="Apple-converted-space"> </span></span></span></p><p>There are several restrictions on the use of the register modifier.</p><p>First, the variable must be of a type that can be held in the CPU’s register. This usually means a single value of a size less than or equal to the size of an integer. Some machines have registers that can hold floating-point numbers as well.<span
class="Apple-converted-space"> </span></p><p>Second, because the variable might not be stored in memory, its address cannot be taken with the unary &amp; operator. An attempt to do so is flagged as an error by the compiler. Some additional rules affect how useful the register modifier is. Because the number of registers is limited, and because some registers can hold only certain types of data (such as pointers or floating-point numbers), the number and types of register modifiers that will actually have any effect are dependent on what machine the<br
/> program will run on. Any additional register modifiers are silently ignored by the compiler.</p><p>Also, in some cases, it might actually be slower to keep a variable in a register because that register<br
/> then becomes unavailable for other purposes or because the variable isn’t used enough to justify the overhead of loading and storing it.</p><p>So when should the register modifier be used? The answer is never, with most modern compilers. Early C compilers did not keep any variables in registers unless directed to do so, and the register modifier was a valuable addition to the language. C compiler design has advanced to the point, however, where the compiler will usually make better decisions than the programmer about which variables should be stored in registers.</p><p>In fact, many compilers actually ignore the register modifier, which is perfectly legal, because it is only a hint and not a directive.<span
class="Apple-converted-space"> </span></p><p><span
style="font-weight: 400;"><span
style="font-size: x-small;">46.<strong>Can a file other than a .h file be included with #include?</strong></span></span></p><p><span
style="font-weight: 400;"><span
style="font-size: x-small;">The preprocessor will include whatever file you specify in your #include statement. Therefore, if you have the line</span></span></p><p>#include &lt;macros.inc&gt;</p><p>in your program, the file macros.inc will be included in your precompiled program. It is, however, unusual programming practice to put any file that does not have a .h or .hpp extension in an #include statement.<span
class="Apple-converted-space"> </span></p><p>You should always put a .h extension on any of your C files you are going to include. This method makes it easier for you and others to identify which files are being used for preprocessing purposes. For instance, someone modifying or debugging your program might not know to look at the macros.inc file for macro definitions. That person might try in vain by searching all files with .h extensions and come up empty. If your file had been named macros.h, the search would have included the macros.h file, and the searcher would have been able to see what macros you defined in it.<span
class="Apple-converted-space"> </span></p><p><span
style="font-weight: 400;"><span
style="font-size: x-small;">47.<strong>What is Preprocessor?</strong></span></span></p><p><span
style="font-weight: 400;"><span
style="font-size: x-small;">The preprocessor is used to modify your program according to the preprocessor directives in your source code. Preprocessor directives (such as #define) give the preprocessor specific instructions on how to modify your source code. The preprocessor reads in all of your include files and the source code you are compiling and creates a preprocessed version of your source code. This preprocessed version has all of its macros and constant symbols replaced by their corresponding code and value assignments. If your source code contains any conditional preprocessor directives (such as #if), the preprocessor evaluates the condition and modifies your source code accordingly.</span></span></p><p>The preprocessor contains many features that are powerful to use, such as creating macros, performing conditional compilation, inserting predefined environment variables into your code, and turning compiler features on and off. For the professional programmer, in-depth knowledge of the features of the preprocessor can be one of the keys to creating fast, efficient programs.<span
class="Apple-converted-space"> </span></p><p><span
style="font-weight: 400;"><span
style="font-size: x-small;">48.<strong>How can you restore a redirected standard stream?</strong><span
class="Apple-converted-space"> </span><br
/> The preceding example showed how you can redirect a standard stream from within your program. But what if later in your program you wanted to restore the standard stream to its original state? By using the standard C library functions named dup() and fdopen(), you can restore a standard stream such as stdout to its original state.</span></span></p><p>The dup() function duplicates a file handle. You can use the dup() function to save the file handle<br
/> corresponding to the stdout standard stream. The fdopen() function opens a stream that has been<br
/> duplicated with the dup() function.</p><p><span
style="font-weight: 400;"><span
style="font-size: x-small;">53.<strong>What is the heap?</strong><span
class="Apple-converted-space"> </span><br
/> The heap is where malloc(), calloc(), and realloc() get memory.</span></span></p><p>Getting memory from the heap is much slower than getting it from the stack. On the other hand, the heap is much more flexible than the stack. Memory can be allocated at any time and deallocated in any order. Such memory isn’t deallocated automatically; you have to call free().</p><p>Recursive data structures are almost always implemented with memory from the heap. Strings often come from there too, especially strings that could be very long at runtime. If you can keep data in a local variable (and allocate it from the stack), your code will run faster than if you put the data on the heap. Sometimes you can use a better algorithm if you use the heap—faster, or more robust, or more flexible. It’s a tradeoff.</p><p>If memory is allocated from the heap, it’s available until the program ends. That’s great if you remember to deallocate it when you’re done. If you forget, it’s a problem. A “memory leak” is some allocated memory that’s no longer needed but isn’t deallocated. If you have a memory leak inside a loop, you can use up all the memory on the heap and not be able to get any more. (When that happens, the allocation functions return a null pointer.) In some environments, if a program doesn’t deallocate everything it allocated, memory stays unavailable even after the program ends.<span
class="Apple-converted-space"> </span></p><p><span
style="font-weight: 400;"><span
style="font-size: x-small;">54.<strong>How do you use a pointer to a function?</strong></span></span></p><p><span
style="font-weight: 400;"><span
style="font-size: x-small;">The hardest part about using a pointer-to-function is declaring it.</span></span></p><p>Consider an example. You want to create a pointer, pf, that points to the strcmp() function.</p><p>The strcmp() function is declared in this way:</p><p>int strcmp(const char *, const char * )</p><p>To set up pf to point to the strcmp() function, you want a declaration that looks just like the strcmp() function’s declaration, but that has *pf rather than strcmp:</p><p>int (*pf)( const char *, const char * );</p><p>After you’ve gotten the declaration of pf, you can #include &lt;string.h&gt; and assign the address of strcmp() to pf: pf = strcmp;<span
class="Apple-converted-space"> </span></p><p><span
style="font-weight: 400;"><span
style="font-size: x-small;">55.<strong>What is the purpose of realloc( )?</strong><span
class="Apple-converted-space"> </span><br
/> The function realloc(ptr,n) uses two arguments.the first argument ptr is a pointer to a block of memory for which the size is to be altered.The second argument n specifies the<br
/> new size.The size may be increased or decreased.If n is greater than the old size and if sufficient space is not available subsequent to the old region, the function realloc( )<br
/> may create a new region and all the old data are moved to the new region.<span
class="Apple-converted-space"> </span><br
/> </span></span></p><p><span
style="font-weight: 400;"><span
style="font-size: x-small;">56.<strong>What is the purpose of main( ) function?</strong></span></span></p><p><span
style="font-weight: 400;"><span
style="font-size: x-small;"><br
/> The function main( ) invokes other functions within it.It is the first function to be called when the program starts execution.</span></span></p><p>- It is the starting function</p><p>- It returns an int value to the environment that called the program</p><p>- Recursive call is allowed for main( ) also.</p><p>- It is a user-defined function</p><p>- Program execution ends when the closing brace of the function main( ) is reached.</p><p>- It has two arguments 1)argument count and 2) argument vector (represents strings passed).</p><p>- Any user-defined name can also be used as parameters for main( ) instead of argc and argv</p><p>* more <a
href="planetetutors.com">here</a></td></tr></tbody></table> ]]></content:encoded> <wfw:commentRss>http://www.freequestionbank.com/question/c-interview-questions/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>HTML Interview Questions</title><link>http://www.freequestionbank.com/question/interview/html-interview-questions/</link> <comments>http://www.freequestionbank.com/question/interview/html-interview-questions/#comments</comments> <pubDate>Tue, 24 Mar 2009 03:20:59 +0000</pubDate> <dc:creator>admin</dc:creator> <category><![CDATA[Interview]]></category> <category><![CDATA[Languages]]></category> <category><![CDATA[html]]></category> <category><![CDATA[Question]]></category><guid
isPermaLink="false">http://www.freequestionbank.com/?p=368</guid> <description><![CDATA[1. How do I indent the first line in my paragraphs?
This isn&#8217;t really possible in a reliable way, until style ...]]></description> <content:encoded><![CDATA[<p>1. How do I indent the first line in my paragraphs?<br
/> This isn&#8217;t really possible in a reliable way, until style sheets are more widely supported. At this moment, there are several browser-specific kludges and tricks available, but these are not guaranteed to work.</p><p>1) Use a number of &nbsp; (&#160;) characters. Netscape and related browsers do not collapse these, like normal spaces, so this appears as an indent in these browsers. Other browsers can display it as one space.</p><p>2) Put a DD at the beginning of the line. This is syntactically invalid, but Netscape works around this by indenting the line at this ball. Of course, other browsers will handle this differently, and there is no guarantee that Netscape will keep doing this.<br
/> 3) Use a blank, transparent GIF, using WIDTH and HEIGHT to indicate the desired white space. This is a very ugly solution, as it only works if you have image loading on, otherwise you get the &#8220;Image&#8221; icon at the beginning of the line. Not all browsers support resizing using these attributes, and you can only &#8220;indent&#8221; a certain number of pixels, not characters. So the amount of &#8220;indentation&#8221; varies with the font size used to display your document.</p><p>2. How do I indent a lot of text?<br
/> Again, there is no reliable way to do this. Netscape will indent text inside a , but other browsers don&#8217;t have to do this. These could show the text in italics, or perhaps with quotation marks around the text. This could come out very strange.<br
/> An alternative is to use DL without DT and DD, which is invalid HTML, but several browsers work around this error by indenting the text inside it. This is not guaranteed to work.</p><p>If you are willing to use tables for layout purposes, there is another option. Create a one-cell table, as follows:</p><pre>
<center>
<table width="805px">
<tr>
<td>
<div align=left>

</div>
</td>
</tr>
</table>

</center>
</pre><p>A drawback to this solution is that very long blocks inside a table may take a while to download and may not appear until the entire table has been downloaded. Another drawback is that it may force users to resize their viewing window after they have become accustomed to their preferred settings.<br
/> 3. Can I put markup in ALT text?<br
/> No. Character entities (&copy;, &#nnn; and such) are permitted, though.</p><p>If you want to know how to write good ALT texts without markup, please see Alan Flavell&#8217;s essay on choosing ALT texts.</p><p>4. How do I include one file in another?<br
/> Use server-side includes, if your server supports them. Ask your Webmaster if this is the case, and if so, what the exact syntax is for your server.<br
/> Since server-side includes make the document slower, they are not always desirable. If your documents only have a static footer, which doesn&#8217;t change every day, you might be better off by using an editor which can insert files in the current document, or a preprocessor. The C preprocessor can do this, but there are also several HTML-specific preprocessors available.</p><p>5. How do I get scrolling text in the status bar?<br
/> This is not an HTML question, it&#8217;s done with a Javascript. Check any page which has this feature, and copy the script from the source.</p><p>This script has two big problems. One, usually it uses the decrement operator (c&#8211;) at some ball. The &#8220;&#8211;&#8221; sequence in a comment actually closes it on some browsers, so your code may &#8220;leak&#8221; on those browsers. The same goes for &#8220;>&#8221;.</p><p>Second, keep in mind that many people consider this even worse than , and that it also suppresses the status information which normally appears there. It prevents people from knowing where a link goes to.</p><p>6. How do I hide my source?<br
/> You can&#8217;t. The source is necessary for the browser to display your document. You have to send the complete, unencrypted source to the browser. Even if a particular browser doesn&#8217;t have a &#8220;View source&#8221; option, there are many that do, and you can always retrieve the document by hand (using telnet) to get its source. Or check the browser&#8217;s cache.<br
/> You can of course put a few hundred empty lines above the actual source, then newbies who don&#8217;t see the scrollbars will think there is nothing there.<br
/> 7. How can I make a custom rule, or a list with custom bullets?<br
/> There was a proposal in the now-expired HTML 3 draft to handle exactly this: just add SRC to the HR or UL tag, indicating where the image can be found. But until this is more widely supported, you have to use IMG for the rule, with a lot of &#8220;&#8211;&#8221; characters as ALT text for text browsers, and using a DL with only DD tags for each item. Make sure you use ALIGN for the image, which should go at the beginning of the item, of course. This isn&#8217;t as beautiful as a &#8220;real&#8221; list.<br
/> An alternative is using a two column table, with the bullets in the left column, and the text in the right. But this won&#8217;t work well on non-table supporting browsers.</p><p>8. How do I display the current date or time in my document?<br
/> With server-side includes. Ask your webmaster if this is supported, and what the exact syntax is for your server. But this will display the local time on the server, not for the client. And if the document is cached, the date will of course be incorrect after some time.<br
/> JavaScript can be used to display the local time for the client, but as most people already have one or more clocks on their screen, why display another one?</p><p>9. For what screen size should I write?<br
/> HTML does not depend on screen size. The text will be wrapped by the browser when the end of the screen is encountered. The only exception to this is when you use -formatted text, which will only wrap at the line breaks you indicate. So make sure these lines are no longer than 70 characters, otherwise text mode users will see ugly line breaks on their terminals. And users of graphical browsers might have to scroll horizontally to see the rest, which is one of the most hated things to do when you read a document.</p><p>Of course, an image cannot be wrapped, so you have to be careful with that. It seems that 400 or 500 pixels is a reasonable width; anything above 600 will mean a certain percentage of users will have to scroll to see the rightmost bit. This percentage increases with your image width. Keep in mind that not everyone runs his browser at full screen!</p><p>10. How do I get my visitor&#8217;s e-mail addresses?<br
/> You can&#8217;t. Although each request for a document is usually logged with the name or address of the remote host, the actual username is almost never logged as well. This is mostly because of performance reasons, as it would require that the server uses the ident protocol to see who is on the other end. This takes time. And if a cache proxy is doing the request, you don&#8217;t get anything sensible.<br
/> In Netscape 2.0, it was possible to automatically submit a form with a mailto as action, using Javascript. This would send e-mail to the document&#8217;s owner, with the address the visitor configured in the From line. Of course, that can be &#8220;mickey.mouse@disney.com&#8221;. This is fixed in Netscape 2.01.<br
/> The most reliable way is to put up a form, asking the visitor to fill in his e-mail address. If you offer him something in return, he will most likely do it.</p><p>11. How do I do a pagebreak?<br
/> You don&#8217;t. HTML is not a page layout language. It&#8217;s up to the browser to decide where and how to insert page breaks when the document is being printed.</p><p>However, style sheets (not widely supported yet, although Microsoft&#8217;s Internet Explorer is beginning to use it) will include support to indicate preferred balls for page breaks, probably somewhat like the way LaTeX handles this.</p><p>12. How do I make a table which looks good on AOL and Prodigy?<br
/> The best way is probably to include a version in preformatted text. This can be seen by any browser, including Lynx.</p><p>If you absolutely must have a table, check out Alan Flavell&#8217;s document on tables for a good discussion.</p><p>13. How do I center a table?<br
/> The &#8220;correct&#8221; way of doing it is TABLE ALIGN=CENTER, but this doesn&#8217;t work in several popular browsers. Put CENTER around the entire table for these browsers.</p><p>This causes some problems with browser that do support CENTER but not tables, such as Lynx. In these browsers, the contents of the cells is now displayed centered, which is not what is intended. To avoid this, you can put the cell&#8217;s contents in P ALIGN=left or DIV ALIGN=left depending on the amount of text in the cell.</p><p>14. How do I make animated GIFs?<br
/> Ask on the comp.infosystems.www.authoring.images group.</p><p>15. Is there a way to get indexed better by the search engines?<br
/> Yes. Put these two statements in the HEAD part of your documents:</p><pre>
<meta NAME="keywords" CONTENT="keyword keyword keyword keyword">
<meta NAME="description" CONTENT="description of your site">
</pre><p>Both may contain up to 1022 characters. If a keyword is used more than 7 times the keywords tag will be ignored altogether. Also, you can&#8217;t put markup (other than entities) in the description or keywords list. Infoseek and Alta Vista are using this.</p><p>16. How do I redirect someone to my new page?<br
/> The most reliable way is to configure the server to send out a redirection instruction when the old URL is requested. Then the browser will automatically get the new URL. This is the fastest way to do this. You can of course also simply put up a small page with a text like &#8220;This page has moved to http://new.url/, please adjust your bookmarks&#8221;.</p><p>A Netscape-only solution, which doesn&#8217;t work on other browsers, and screws up the &#8220;back&#8221; button in Netscape, is</p><p>META HTTP-EQUIV=&#8221;Refresh&#8221; CONTENT=&#8221;x; URL=new.URL&#8221;</p><p>which will load the new URL after x seconds. This should go in the HEAD of the document. But if you do this, also include a short text saying &#8220;Document moved to new URL so-and-so&#8221; for other browsers.</p><p>(The screwing-up bit refers to the fact that if you press &#8220;Back&#8221; after you have been redirected, you will be taken to the document with the META refresh. Then the refresh will be activated, and so you&#8217;ll jump to the page you just tried to leave.)</p><p>17. How do I get a back button on my page?<br
/> In HTML, this is impossible. Going &#8220;back&#8221; means that you go to the previous page in your history. You might be able to create a link to the URL specified in the &#8220;HTTP_REFERER&#8221; environment variable in your document, but that only creates a link to a new location in your history. Even worse, the information in that variable can be plain wrong. Some browsers incorrectly send the variable when you use a bookmark or type in an URL manually, and some don&#8217;t send that variable at all. Then you would end up with an empty link.<br
/> A JavaScript could use &#8220;history.back()&#8221; to do this, but this only works in Netscape 2.</p><p>18. How do I force a download?<br
/> You can&#8217;t. When someone downloads a document, the server tells the browser what type of file it is. The browser then picks the appropriate helper application, or displays it himself. If the server doesn&#8217;t know the file type, it tells the browser that the file is &#8220;text/plain&#8221;, or just plain text. You will have to ask your server admin to configure this particular file with the MIME type you want.</p><p>&#8220;Forcing&#8221; a download is not what you are supposed to do. After all, what is more convenient than having the proper application started when I download a particular file? Browsing through a download directory can be quite a pain. And most browsers allow the user to download to disk if they want to.</p><p>If the file must be saved to disk, as there is absolutely NO other way to handle it, the MIME type should be &#8220;application/octet-stream&#8221;.</p><p>19. Why is my binary file not downloaded, but shown on the screen?<br
/> Actually, the browser has downloaded the document, it is just treating it as a plain text file. This is because the server said it was a plain text file. To get the file in the helper application (or plug-in), you will have to configure the server to send out the right MIME type, and the browser to start the appropriate helper application for files with that MIME type.</p><p>20. How do I use an image instead of the standard submit button?<br
/> Use INPUT NAME=foo TYPE=image SRC=&#8221;http://url.to/image.gif&#8221; instead of the normal submit tag. There is no way to do this for the reset button.</p><p>Note that some browsers will also send the x and y coordinates of the location where the user clicked on the image to the server. They are available as &#8220;foo.x=000&#038;foo.y=000&#8243; in the CGI input.</p><p>21. How do I get a so-and-so character in my HTML?<br
/> HTML text is supposed to be written in the ISO Latin-1 character set. A complete overview of all the characters in this set is available from:</p><p>o http://www.w3.org/pub/WWW/MarkUp/html3/latin1.html</p><p>o http://ppewww.ph.gla.ac.uk/%7Eflavell/iso8859/</p><p>o http://uts.cc.utexas.edu/%7Echurchh/latin1.html</p><p>22. How do I get a counter?<br
/> Either ask your Webmaster for access to the log files, or for a server-side include which can do this, or use one of the freeware counters available at the CGI archives. There is no HTML tag to do this.<br
/> Counters are quite ball less, though. They can be set to any value the owner wants, so they don&#8217;t give you any information. Because of the delay that often occurs when using an external counter, your visitors may get annoyed with the long loading time of your document. The server&#8217;s log file provides a lot more reliable information for you, and you don&#8217;t have to bother your readers with it.</p><p>23. How do I detect what browser is being used?<br
/> Many browsers identify themselves when they request a document. A CGI script will have this information available in the HTTP_USER_AGENT environment variable, and it can use that to send out a version of the document which is optimized for that browser.<br
/> Keep in mind not all browsers identify themselves correctly. Microsoft Internet Explorer, for example, claims to be &#8220;Mozilla 1.2&#8243; to get at Netscape enhanced documents.<br
/> And of course, if a cache proxy keeps the Netscape enhanced document, someone with an other browser will also get this document if he goes through the cache.</p><p>24. I want to get an audio file to play automatically when someone visits my site!<br
/> Bleh. What if I visit your site at 3am, and there&#8217;s someone sleeping in the next room?</p><p>For Netscape, this is done using the EMBED tag. You can also do this with the Netscape META refresh tag, as described earlier. Just put the URL of the audio file in the CONTENT field.</p><p>There is also a MS Internet Explorer specific tag to do this: BGSOUND SRC=URL which plays the file specified in the SRC attribute automatically. You can add LOOP followed by a value or the keyword &#8220;INFINITE&#8221; to indicate how many times the sound should be played.</p><p>25. Should I put quotes around attribute values or not?<br
/> It depends. It is never wrong to use them, but you don&#8217;t have to if the attribute value consists only of letters, digits, periods and/or hyphens. This is explained in the HTML 2.0 specs.<br
/> Oh, and keep in mind that if you use double quotes, you should escape any quotes inside the value with &#8220;&quot;&#8221; so you don&#8217;t accidentally terminate the value prematurely.</p><p>26. Should I use lower case or upper case for tags?<br
/> Tags are case insensitive, so it doesn&#8217;t matter. This is just a matter of style. Many people prefer upper case, as it makes the tags &#8220;stand out&#8221; better amongst the text.</p><p>28. My images/hyperlinks are coming out all wrong, or don&#8217;t load! What&#8217;s up?<br
/> Most likely you forgot to close a quote at the end of an HREF or SRC. Alternatively, perhaps you used a &#8220;>&#8221; character in an ALT text or somewhere else inside a tag. Although this is legal, several older browsers will think the tag ends there, so the rest is displayed as normal text.</p><p>This especially happens if you use comment tags to &#8220;comment out&#8221; text with HTML tags. Although the correct syntax is  (without &#8220;&#8211;&#8221; occurring anywhere inside the comment), some browsers will think the comment ends at the first > they see.</p><p>29. How do I get a button which takes me to a new page?<br
/> This is done with a small form:</p><pre>
<form ACTION="http://url.you.want.to.go.to/" METHOD=GET>
<input TYPE=submit VALUE="Text on button" NAME=foo>
</form>
</pre><p>If you want to line up buttons next to each other, you will have to put them in a one-row table, with each button in a separate cell.</p><p>*more <a
href="http://www.freejavaguide.com">here</a></p> ]]></content:encoded> <wfw:commentRss>http://www.freequestionbank.com/question/interview/html-interview-questions/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>JAVA INTERVIEW QUESTIONS</title><link>http://www.freequestionbank.com/question/interview/java-interview-questions/</link> <comments>http://www.freequestionbank.com/question/interview/java-interview-questions/#comments</comments> <pubDate>Tue, 24 Mar 2009 03:14:56 +0000</pubDate> <dc:creator>admin</dc:creator> <category><![CDATA[Interview]]></category> <category><![CDATA[Languages]]></category> <category><![CDATA[java]]></category> <category><![CDATA[Question]]></category><guid
isPermaLink="false">http://www.freequestionbank.com/?p=362</guid> <description><![CDATA[1. What is the difference between private, protected, and public?
These keywords are for allowing privileges to components such as java ...]]></description> <content:encoded><![CDATA[<p>1. What is the difference between private, protected, and public?</p><p>These keywords are for allowing privileges to components such as java methods and variables.<br
/> Public: accessible to all classes<br
/> Private: accessible only to the class to which they belong<br
/> Protected: accessible to the class to which they belong and any subclasses.<br
/> Access specifiers are keywords that determines the type of access to the member of a class. These are:<br
/> * Public<br
/> * Protected<br
/> * Private<br
/> * Defaults</p><p>2. What&#8217;s the difference between an interface and an abstract class? Also discuss the similarities. (Very Important)</p><p>Abstract class is a class which contain one or more abstract methods, which has to be implemented by sub classes. Interface is a Java Object containing method declaration and doesn&#8217;t contain implementation. The classes which have implementing the Interfaces must provide the method definition for all the methods<br
/> Abstract class is a Class prefix with a abstract keyword followed by Class definition. Interface is a Interface which starts with interface keyword.<br
/> Abstract class contains one or more abstract methods. where as Interface contains all abstract methods and final declarations<br
/> Abstract classes are useful in a situation that Some general methods should be implemented and specialization behavior should be implemented by child classes. Interfaces are useful in a situation that all properties should be implemented.</p><p>Differences are as follows:</p><p>* Interfaces provide a form of multiple inheritance. A class can extend only one other class.<br
/> * Interfaces are limited to public methods and constants with no implementation. Abstract classes can have a partial implementation, protected parts, static methods, etc.<br
/> * A Class may implement several interfaces. But in case of abstract class, a class may extend only one abstract class.<br
/> * Interfaces are slow as it requires extra indirection to to find corresponding method in in the actual class. Abstract classes are fast.</p><p>Similarities:</p><p>* Neither Abstract classes or Interface can be instantiated.</p><p>How to define an Abstract class?<br
/> A class containing abstract method is called Abstract class. An Abstract class can&#8217;t be instantiated.<br
/> Example of Abstract class:</p><p>abstract class testAbstractClass {<br
/> protected String myString;<br
/> public String getMyString() {<br
/> return myString;<br
/> }<br
/> public abstract string anyAbstractFunction();<br
/> }</p><p>How to define an Interface?<br
/> Answer: In Java Interface defines the methods but does not implement them. Interface can include constants. A class that implements the interfaces is bound to implement all the methods defined in Interface.<br
/> Example of Interface:</p><p>public interface sampleInterface {<br
/> public void functionOne();<br
/> public long CONSTANT_ONE = 1000;<br
/> }</p><p>3. Question: How you can force the garbage collection?</p><p>Garbage collection automatic process and can&#8217;t be forced. You could request it by calling System.gc(). JVM does not guarantee that GC will be started immediately.</p><p>Garbage collection is one of the most important feature of Java, Garbage collection is also called automatic memory management as JVM automatically removes the unused variables/objects (value is null) from the memory. User program can&#8217;t directly free the object from memory, instead it is the job of the garbage collector to automatically free the objects that are no longer referenced by a program. Every class inherits finalize() method from java.lang.Object, the finalize() method is called by garbage collector when it determines no more references to the object exists. In Java, it is good idea to explicitly assign null into a variable when no more in use. I Java on calling System.gc() and Runtime.gc(), JVM tries to recycle the unused objects, but there is no guarantee when all the objects will garbage collected.</p><p>4. What&#8217;s the difference between constructors and normal methods?</p><p>Constructors must have the same name as the class and can not return a value. They are only called once while regular methods could be called many times and it can return a value or can be void.</p><p>5. Can you call one constructor from another if a class has multiple constructors</p><p>Yes. Use this() to call a constructor from an other constructor.</p><p>6. Explain the usage of Java packages.</p><p>This is a way to organize files when a project consists of multiple modules. It also helps resolve naming conflicts when different packages have classes with the same names. Packages access level also allows you to protect data from being used by the non-authorized classes.</p><p>7. Explain in your own words the &#8220;bottom line&#8221; benefits of the use of an interface.</p><p>The interface makes it possible for a method in one class to invoke methods on objects of other classes, without the requirement to know the true class of those objects, provided that those objects are all instantiated from classes that implement one or more specified interfaces. In other words, objects of classes that implement specified interfaces can be passed into methods of other objects as the generic type Object, and the methods of the other objects can invoke methods on the incoming objects by first casting them as the interface type.</p><p>8. What are some advantages and disadvantages of Java Sockets?</p><p>Some advantages of Java Sockets:<br
/> Sockets are flexible and sufficient. Efficient socket based programming can be easily implemented for general communications. Sockets cause low network traffic. Unlike HTML forms and CGI scripts that generate and transfer whole web pages for each new request, Java applets can send only necessary updated information.</p><p>Some disadvantages of Java Sockets:<br
/> Security restrictions are sometimes overbearing because a Java applet running in a Web browser is only able to establish connections to the machine where it came from, and to nowhere else on the network   Despite all of the useful and helpful Java features, Socket based communications allows only to send packets of raw data between applications. Both the client-side and server-side have to provide mechanisms to make the data useful in any way.</p><p>9. Explain the usage of the keyword transient?</p><p>Transient keyword indicates that the value of this member variable does not have to be serialized with the object. When the class will be de-serialized, this variable will be initialized with a default value of its data type (i.e. zero for integers).</p><p>10. What&#8217;s the difference between the methods sleep() and wait()</p><p>The code sleep(1000); puts thread aside for exactly one second. The code wait(1000), causes a wait of up to one second. A thread could stop waiting earlier if it receives the notify() or notifyAll() call. The method wait() is defined in the class Object and the method sleep() is defined in the class Thread.</p><p>11. What would you use to compare two String variables &#8211; the operator == or the method equals()?</p><p>I&#8217;d use the method equals() to compare the values of the Strings and the == to check if two variables point at the same instance of a String object.</p><p>12. Why would you use a synchronized block vs. synchronized method?</p><p>Synchronized blocks place locks for shorter periods than synchronized methods.</p><p>13. What access level do you need to specify in the class declaration to ensure that only classes from the same directory can access it?</p><p>You do not need to specify any access level, and Java will use a default package access level.</p><p>14. Can an inner class declared inside of a method access local variables of this method?</p><p>It&#8217;s possible if these variables are final.</p><p>15. What can go wrong if you replace &#038;&#038; with &#038; in the following code:<br
/> String a=null; if (a!=null &#038;&#038; a.length()>10) {&#8230;}</p><p>A single ampersand here would lead to a NullPointerException.</p><p>16. What&#8217;s the main difference between a Vector and an ArrayList?</p><p>Java Vector class is internally synchronized and ArrayList is not synchronized.</p><p>17. Describe the wrapper classes in Java.</p><p>Wrapper class is wrapper around a primitive data type. An instance of a wrapper class contains, or wraps, a primitive value of the corresponding type.</p><p>Following table lists the primitive types and the corresponding wrapper classes:<br
/> Primitive Wrapper<br
/> boolean  &#8211; java.lang.Boolean<br
/> byte &#8211; java.lang.Byte<br
/> char &#8211; java.lang.Character<br
/> double &#8211; java.lang.Double<br
/> float &#8211; java.lang.Float<br
/> int &#8211; java.lang.Integer<br
/> long &#8211; java.lang.Long<br
/> short &#8211; java.lang.Short<br
/> void &#8211; java.lang.Void</p><p>18. How could Java classes direct program messages to the system console, but error messages, say to a file?</p><p>The class System has a variable out that represents the standard output, and the variable err that represents the standard error device. By default, they both point at the system console. This how the standard output could be re-directed:<br
/> Stream st = new Stream(new FileOutputStream(&#8220;output.txt&#8221;)); System.setErr(st); System.setOut(st);</p><p>19. How do you know if an explicit object casting is needed?</p><p>If you assign a superclass object to a variable of a subclass&#8217;s data type, you need to do explicit casting. For example:<br
/> Object a; Customer b; b = (Customer) a;</p><p>20. When you assign a subclass to a variable having a supeclass type, the casting is performed automatically. Can you write a Java class that could be used both as an applet as well as an application?</p><p>Yes. Add a main() method to the applet.</p><p>21. If a class is located in a package, what do you need to change in the OS environment to be able to use it?</p><p>You need to add a directory or a jar file that contains the package directories to the CLASSPATH environment variable. Let&#8217;s say a class Employee belongs to a package com.xyz.hr; and is located in the file c:\dev\com\xyz\hr\Employee.javIn this case, you&#8217;d need to add c:\dev to the variable CLASSPATH. If this class contains the method main(), you could test it from a command prompt window as follows:<br
/> c:\>java com.xyz.hr.Employee</p><p>22. What&#8217;s the difference between J2SDK 1.5 and J2SDK 5.0?</p><p>There&#8217;s no difference, Sun Microsystems just re-branded this version.</p><p>23. Does it matter in what order catch statements for FileNotFoundException and IOExceptipon are written?</p><p>Yes, it does. The FileNoFoundException is inherited from the IOException. Exception&#8217;s subclasses have to be caught first.</p><p>24. Name the containers which uses Border Layout as their default layout?</p><p>Containers which uses Border Layout as their default are: window, Frame and Dialog classes.</p><p>25. You are planning to do an indexed search in a list of objects. Which of the two Java collections should you use:<br
/> ArrayList or LinkedList?</p><p>ArrayList</p><p>26. When should the method invokeLater()be used?</p><p>This method is used to ensure that Swing components are updated through the event-dispatching thread.</p><p>27. How can a subclass call a method or a constructor defined in a superclass?</p><p>Use the following syntax: super.myMethod(); To call a constructor of the superclass, just write super(); in the first line of the subclass&#8217;s constructor.</p><p>28. What do you understand by Synchronization?</p><p>Synchronization is a process of controlling the access of shared resources by the multiple threads in such a manner that only one thread can access one resource at a time. In non synchronized multithreaded application, it is possible for one thread to modify a shared object while another thread is in the process of using or updating the object&#8217;s value. Synchronization prevents such type of data corruption.<br
/> E.g. Synchronizing a function:<br
/> public synchronized void Method1 () {<br
/> // Appropriate method-related code.<br
/> }<br
/> E.g. Synchronizing a block of code inside a function:<br
/> public myFunction (){<br
/> synchronized (this) {<br
/> // Synchronized code here.<br
/> }<br
/> }</p><p>29. What&#8217;s the difference between a queue and a stack?</p><p>Stacks works by last-in-first-out rule (LIFO), while queues use the FIFO rule</p><p>30. You can create an abstract class that contains only abstract methods. On the other hand, you can create an interface that declares the same methods. So can you use abstract classes instead of interfaces?</p><p>Sometimes. But your class may be a descendent of another class and in this case the interface is your only option.</p><p>31. If you&#8217;re overriding the method equals() of an object, which other method you might also consider?</p><p>hashCode()</p><p>32. What is Collection API?</p><p>The Collection API is a set of classes and interfaces that support operation on collections of objects. These classes and interfaces are more flexible, more powerful, and more regular than the vectors, arrays, and hashtables if effectively replaces.<br
/> Example of classes: HashSet, HashMap, ArrayList, LinkedList, TreeSet and TreeMap.<br
/> Example of interfaces: Collection, Set, List and Map.</p><p>33. How would you make a copy of an entire Java object with its state?</p><p>Have this class implement Cloneable interface and call its method clone().</p><p>34. How can you minimize the need of garbage collection and make the memory use more effective?</p><p>Use object pooling and weak object references.</p><p>35. There are two classes: A and B. The class B need to inform a class A when some important event has happened. What Java technique would you use to implement it?</p><p>If these classes are threads I&#8217;d consider notify() or notifyAll(). For regular classes you can use the Observer interface.</p><p>36. Explain the Encapsulation principle.</p><p>Encapsulation is a process of binding or wrapping the data and the codes that operates on the data into a single entity. This keeps the data safe from outside interface and misuse. One way to think about encapsulation is as a protective wrapper that prevents code and data from being arbitrarily accessed by other code defined outside the wrapper.</p><p>37. Explain the Inheritance principle.</p><p>Inheritance is the process by which one object acquires the properties of another object.</p><p>38. Explain the Polymorphism principle.</p><p>The meaning of Polymorphism is something like one name many forms. Polymorphism enables one entity to be used as as general category for different types of actions. The specific action is determined by the exact nature of the situation. The concept of polymorphism can be explained as &#8220;one interface, multiple methods&#8221;.<br
/> From a practical programming viewpoint, polymorphism exists in three distinct forms in Java:</p><p>* Method overloading<br
/> * Method overriding through inheritance<br
/> * Method overriding through the Java interface</p><p>39. Is Iterator a Class or Interface? What is its use?</p><p>Iterator is an interface which is used to step through the elements of a Collection.</p><p>40. Explain the user defined Exceptions?</p><p>User defined Exceptions are the separate Exception classes defined by the user for specific purposed. An user defined can created by simply sub-classing it to the Exception class. This allows custom exceptions to be generated (using throw) and caught in the same way as normal exceptions.<br
/> Example:</p><p>class myCustomException extends Exception {<br
/> / The class simply has to exist to be an exception<br
/> }</p><p>41. What is OOPS?</p><p>OOP is the common abbreviation for Object-Oriented Programming.<br
/> There are three main principals of oops which are called Polymorphism, Inheritance and Encapsulation.</p><p>39.  Read the following program:</p><p>public class test {<br
/> public static void main(String [] args) {<br
/> int x = 3;<br
/> int y = 1;<br
/> if (x = y)<br
/> System.out.println(&#8220;Not equal&#8221;);<br
/> else<br
/> System.out.println(&#8220;Equal&#8221;);<br
/> }<br
/> }</p><p>What is the result?<br
/> The output is “Equal”<br
/> B. The output in “Not Equal”<br
/> C. An error at &#8221; if (x = y)&#8221; causes compilation to fall.<br
/> D. The program executes but no output is show on console.<br
/> Answer: C<br
/> Answer: Transient variable can&#8217;t be serialize. For example if a variable is declared as transient in a Serializable class and the class is written to an ObjectStream, the value of the variable can&#8217;t be written to the stream instead when the class is retrieved from the ObjectStream the value of the variable becomes null.</p><p>*more <a
href="http://www.freejavaguide.com">here</a></p> ]]></content:encoded> <wfw:commentRss>http://www.freequestionbank.com/question/interview/java-interview-questions/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Short Java Notes</title><link>http://www.freequestionbank.com/tech-crunch/programming-languages/short-java-notes/</link> <comments>http://www.freequestionbank.com/tech-crunch/programming-languages/short-java-notes/#comments</comments> <pubDate>Tue, 24 Mar 2009 03:09:31 +0000</pubDate> <dc:creator>admin</dc:creator> <category><![CDATA[Languages]]></category> <category><![CDATA[java]]></category> <category><![CDATA[notes]]></category> <category><![CDATA[scjp]]></category> <category><![CDATA[tutorial]]></category><guid
isPermaLink="false">http://www.freequestionbank.com/?p=359</guid> <description><![CDATA[1. Source file&#8217;s elements (in order)
* Package declaration
* Import statements
...]]></description> <content:encoded><![CDATA[<p>1. Source file&#8217;s elements (in order)</p><p> * Package declaration<br
/> * Import statements<br
/> * Class definitions<br
/> 2. Importing packages doesn&#8217;t recursively import sub-packages.</p><p>3. Sub-packages are really different packages, happen to live within an enclosing package. Classes in sub-packages cannot access classes in enclosing package with default access.</p><p>4. Comments can appear anywhere. Can&#8217;t be nested. No matter what type of comments.</p><p>5. At most one public class definition per file. This class name should match the file name. If there are more than one public class definitions, compiler will accept the class with the file&#8217;s name and give an error at the line where the other class is defined.</p><p>6. It&#8217;s not required having a public class definition in a file. Strange, but true. J In this case, the file&#8217;s name should be different from the names of classes and interfaces (not public obviously).</p><p>7. Even an empty file is a valid source file.</p><p>8. An identifier must begin with a letter, dollar sign ($) or underscore (_). Subsequent characters may be letters, $, _ or digits.</p><p>9. An identifier cannot have a name of a Java keyword. Embedded keywords are OK. true, false and null are literals (not keywords), but they can&#8217;t be used as identifiers as well.</p><p>10. const and goto are reserved words, but not used.</p><p>11. Unicode characters can appear anywhere in the source code. The following code is valid.</p><p>ch\u0061r a = &#8216;a&#8217;;</p><p>char \u0062 = &#8216;b&#8217;;</p><p>char c = &#8216;\u0063&#8242;;<br
/> 13. All numeric data types are signed. char is the only unsigned integral type.</p><p>14. Object reference variables are initialized to null.</p><p>15. Octal literals begin with zero. Hex literals begin with 0X or 0x.</p><p>16. Char literals are single quoted characters or unicode values (begin with \u).</p><p>17. A number is by default an int literal, a decimal number is by default a double literal.</p><p>18. 1E-5d is a valid double literal, E2d is not (since it starts with a letter, compiler thinks that it&#8217;s an identifier)</p><p>19. Two types of variables.</p><p>a. Member variables</p><p> * Accessible anywhere in the class.<br
/> * Automatically initialized before invoking any constructor.<br
/> * Static variables are initialized at class load time.<br
/> * Can have the same name as the class.</p><p>b. Automatic variables method local</p><p>· Must be initialized explicitly. (Or, compiler will catch it.) Object references can be initialized to null to make the compiler happy. The following code won&#8217;t compile. Specify else part or initialize the local variable explicitly.</p><p>public String testMethod ( int a) {</p><p>String tmp;</p><p>if ( a > 0 ) tmp = &#8220;Positive&#8221;;</p><p>return tmp;</p><p>}</p><p>· Can have the same name as a member variable, resolution is based on scope.</p><p>20. Arrays are Java objects. If you create an array of 5 Strings, there will be 6 objects created.</p><p>21. Arrays should be</p><p> * Declared. (int[] a; String b[]; Object []c; Size should not be specified now)<br
/> * Allocated (constructed). ( a = new int[10]; c = new String[arraysize] )<br
/> * Initialized. for (int i = 0; i < a.length; a[i++] = 0)</p><p>22. The above three can be done in one step.</p><p>int a[] = { 1, 2, 3 }; (or )</p><p>int a[] = new int[] { 1, 2, 3 }; But never specify the size with the new statement.</p><p>23. Java arrays are static arrays. Size has to be specified at compile time. Array.length returns array's size. (Use Vectors for dynamic purposes).</p><p>24. Array size is never specified with the reference variable, it is always maintained with the array object. It is maintained in array.length, which is a final instance variable.</p><p>25. Anonymous arrays can be created and used like this: new int[] {1,2,3} or new int[10]</p><p>26. Arrays with zero elements can be created. args array to the main method will be a zero element array if no command parameters are specified. In this case args.length is 0.</p><p>27. Comma after the last initializer in array declaration is ignored.</p><p>int[] i = new int[2] { 5, 10}; // Wrong</p><p>int i[5] = { 1, 2, 3, 4, 5}; // Wrong</p><p>int[] i[] = {{}, new int[] {} }; // Correct</p><p>int i[][] = { {1,2}, new int[2] }; // Correct</p><p>int i[] = { 1, 2, 3, 4, } ; // Correct</p><p>28. Array indexes start with 0. Index is an int data type.</p><p>29. Square brackets can come after datatype or before/after variable name. White spaces are fine. Compiler just ignores them.</p><p>30. Arrays declared even as member variables also need to be allocated memory explicitly.</p><p>static int a[];</p><p>static int b[] = {1,2,3};</p><p>public static void main(String s[]) {</p><p>System.out.println(a[0]); // Throws a null pointer exception</p><p>System.out.println(b[0]); // This code runs fine</p><p>System.out.println(a); // Prints 'null'</p><p>System.out.println(b); // Prints a string which is returned by toString</p><p>}</p><p>31. Once declared and allocated (even for local arrays inside methods), array elements are automatically initialized to the default values.</p><p>32. If only declared (not constructed), member array variables default to null, but local array variables will not default to null.</p><p>33. Java doesn't support multidimensional arrays formally, but it supports arrays of arrays. From the specification - "The number of bracket pairs indicates the depth of array nesting." So this can perform as a multidimensional array. (no limit to levels of array nesting)</p><p>34. In order to be run by JVM, a class should have a main method with the following signature.</p><p>public static void main(String args[])</p><p>static public void main(String[] s)</p><p>35. args array's name is not important. args[0] is the first argument. args.length gives no. of arguments.</p><p>36. main method can be overloaded.</p><p>37. main method can be final.</p><p>38. A class with a different main signature or w/o main method will compile. But throws a runtime error.</p><p>39. A class without a main method can be run by JVM, if its ancestor class has a main method. (main is just a method and is inherited)</p><p>40. Primitives are passed by value.</p><p>41. Objects (references) are passed by reference. The object reference itself is passed by value. So, it can't be changed. But, the object can be changed via the reference.</p><p>42. Garbage collection is a mechanism for reclaiming memory from objects that are no longer in use, and making the memory available for new objects.</p><p>43. An object being no longer in use means that it can't be referenced by any 'active' part of the program.</p><p>44. Garbage collection runs in a low priority thread. It may kick in when memory is too low. No guarantee.</p><p>45. It's not possible to force garbage collection. Invoking System.gc may start garbage collection process.</p><p>46. The automatic garbage collection scheme guarantees that a reference to an object is always valid while the object is in use, i.e. the object will not be deleted leaving the reference "dangling".</p><p>47. There are no guarantees that the objects no longer in use will be garbage collected and their finalizers executed at all. gc might not even be run if the program execution does not warrant it. Thus any memory allocated during program execution might remain allocated after program termination, unless reclaimed by the OS or by other means.</p><p>48. There are also no guarantees on the order in which the objects will be garbage collected or on the order in which the finalizers are called. Therefore, the program should not make any decisions based on these assumptions.</p><p>49. An object is only eligible for garbage collection, if the only references to the object are from other objects that are also eligible for garbage collection. That is, an object can become eligible for garbage collection even if there are references pointing to the object, as long as the objects with the references are also eligible for garbage collection.</p><p>50. Circular references do not prevent objects from being garbage collected.</p><p>51. We can set the reference variables to null, hinting the gc to garbage collect the objects referred by the variables. Even if we do that, the object may not be gc-ed if it's attached to a listener. (Typical in case of AWT components) Remember to remove the listener first.</p><p>52. All objects have a finalize method. It is inherited from the Object class.</p><p>53. finalize method is used to release system resources other than memory. (such as file handles and network connections) The order in which finalize methods are called may not reflect the order in which objects are created. Don't rely on it. This is the signature of the finalize method.</p><p>protected void finalize() throws Throwable { }</p><p>In the descendents this method can be protected or public. Descendents can restrict the exception list that can be thrown by this method.</p><p>54. finalize is called only once for an object. If any exception is thrown in finalize, the object is still eligible for garbage collection (at the discretion of gc)</p><p>55. gc keeps track of unreachable objects and garbage-collects them, but an unreachable object can become reachable again by letting know other objects of its existence from its finalize method (when called by gc). This 'resurrection' can be done only once, since finalize is called only one for an object.</p><p>56. finalize can be called explicitly, but it does not garbage collect the object.</p><p>57. finalize can be overloaded, but only the method with original finalize signature will be called by gc.</p><p>58. finalize is not implicitly chained. A finalize method in sub-class should call finalize in super class explicitly as its last action for proper functioning. But compiler doesn't enforce this check.</p><p>59. System.runFinalization can be used to run the finalizers (which have not been executed before) for the objects eligible for garbage collection.<br
/> 1.        Modifiers are Java keywords that provide information to compiler about the nature of the code, data and classes.</p><p>2.        Access modifiers - public, protected, private</p><p>·         Only applied to class level variables. Method variables are visible only inside the method.</p><p>·         Can be applied to class itself (only to inner classes declared at class level, no such thing as protected or private top level class)</p><p>·         Can be applied to methods and constructors.</p><p>·         If a class is accessible, it doesn't mean, the members are also accessible. Members' accessibility determines what is accessible and what is not. But if the class is not accessible, the members are not accessible, even though they are declared public.</p><p>·         If no access modifier is specified, then the accessibility is default package visibility. All classes in the same package can access the feature. It's called as friendly access. But friendly is not a Java keyword. Same directory is same package in Java's consideration.</p><p>·         'private' means only the class can access it, not even sub-classes.  So, it'll cause access denial to a sub-class's own variable/method.</p><p>·         These modifiers dictate, which classes can access the features. An instance of a class can access the private features of another instance of the same class.<br
/> ·         'protected' means all classes in the same package (like default) and sub-classes in any package can access the features. But a subclass in another package can access the protected members in the super-class via only the references of subclass or its subclasses. A subclass in the same package doesn't have this restriction. This ensures that classes from other packages are accessing only the members that are part of their inheritance hierarchy.</p><p>·         Methods cannot be overridden to be more private. Only the direction shown in following figure is permitted from parent classes to sub-classes.</p><p>private à friendly (default) à protected à public</p><p> Parent classes                                                                   Sub-classes</p><p>3.        final</p><p>·         final features cannot be changed.</p><p>·         The final modifier applies to classes, methods, and variables.</p><p>·         final classes cannot be sub-classed.</p><p>·         You can declare a variable in any scope to be final.</p><p>·         You may, if necessary, defer initialization of a final local variable. Simply declare the local variable and initialize it later (for final instance variables. You must initialize them at the time of declaration or in constructor).</p><p>·         final variables cannot be changed (result in a compile-time error if  you do so )</p><p>·         final methods cannot be overridden.</p><p>·         Method arguments marked final are read-only. Compiler error, if trying to assign values to final arguments inside the method.</p><p>·         Member variables marked final are not initialized by default. They have to be explicitly assigned a value at declaration or in an initializer block. Static finals must be assigned to a value in a static initializer block, instance finals must be assigned a value in an instance initializer or in every constructor. Otherwise the compiler will complain.</p><p>·         A blank final is a final variable whose declaration lacks an initializer.</p><p>·         Final variables that are not assigned a value at the declaration and method arguments that are marked final are called blank final variables. They can be assigned a value at most once.</p><p>·         Local variables can be declared final as well.</p><p>·         If a final variable holds a reference to an object, then the state of the object may be changed by operations on the object, but the variable will always refer to the same object.</p><p>·         This applies also to arrays, because arrays are objects; if a final variable holds a reference to an array, then the components of the array may be changed by operations on the array, but the variable will always refer to the same array</p><p>·          A blank final instance variable must be definitely assigned  at the end of every constructor of the class in which it is declared; otherwise a compile-time error occurs.</p><p>·         A class can be declared final if its definition is complete and no subclasses are desired or required.</p><p>·         A compile-time error occurs if the name of a final class appears in the extends clause of another class declaration; this implies that a final class cannot have any subclasses.</p><p>·         A compile-time error occurs if a class is declared both final and abstract, because the implementation of such a class could never be completed.</p><p>·         Because a final class never has any subclasses, the methods of a final class are never overridden</p><p>4.        abstract</p><p>·         Can be applied to classes and methods.</p><p>·         For deferring implementation to sub-classes.</p><p>·         Opposite of final, final can't be sub-classed, abstract must be sub-classed.</p><p>·         A class should be declared abstract,</p><p>1.        if it has any abstract methods.</p><p>2.        if it doesn't provide implementation to any of the abstract methods it inherited</p><p>3.        if it doesn't provide implementation to any of the methods in an interface that it says implementing.</p><p>·         Just terminate the abstract method signature with a ';', curly braces will give a compiler error.</p><p>·         A class can be abstract even if it doesn't have any abstract methods.</p><p>5.        static</p><p>·         Can be applied to nested classes, methods, variables, free floating code-block (static initializer)</p><p>·         Static variables are initialized at class load time. A class has only one copy of these variables.</p><p>·         Static methods can access only static variables. (They have no this)</p><p>·         Access by class name is a recommended way to access static methods/variables.</p><p>·         Static initializer code is run at class load time.</p><p>·         Static methods may not be overridden to be non-static.</p><p>·         Non-static methods may not be overridden to be static.</p><p>·         Abstract methods may not be static.</p><p>·         Local variables cannot be declared as static.</p><p>·         Actually, static methods are not participating in the usual overriding mechanism of invoking the methods based on the class of the object at runtime. Static method binding is done at compile time, so the method to be invoked is determined by the type of reference variable rather than the actual type of the object it holds at runtime.</p><p>Let's say a sub-class has a static method which 'overrides' a static method in a parent class.  If you have a reference variable of parent class type and you assign a child class object to that variable and invoke the static method, the method invoked will be the parent class method, not the child class method.  The following code explains this.</p><p>public class StaticOverridingTest {</p><p> public static void main(String s[]) {</p><p> Child c = new Child();</p><p> c.doStuff(); // This will invoke Child.doStuff()</p><p> Parent p = new Parent();</p><p> p.doStuff(); // This will invoke Parent.doStuff()</p><p> p = c;</p><p> p.doStuff(); // This will invoke Parent.doStuff(), rather than Child.doStuff()</p><p> }</p><p>}</p><p>class Parent {</p><p> static int x = 100;</p><p> public static void doStuff() {</p><p> System.out.println("In Parent..doStuff");</p><p> System.out.println(x);</p><p> }</p><p>}</p><p>class Child extends Parent {</p><p> static int x = 200;</p><p> public static void doStuff() {</p><p> System.out.println("In Child..doStuff");</p><p> System.out.println(x);</p><p> }</p><p> }</p><p>6.        native</p><p>·         Can be applied to methods only. (static methods also)</p><p>·         Written in a non-Java language, compiled for a single machine target type.</p><p>·         Java classes use lot of native methods for performance and for accessing hardware Java is not aware of.</p><p>·         Native method signature should be terminated by a ';', curly braces will provide a compiler error.</p><p>·         native doesn't affect access qualifiers. Native methods can be private.</p><p>·         Can pass/return Java objects from native methods.</p><p>·         System.loadLibrary is used in static initializer code to load native libraries. If the library is not loaded when the static method is called, an UnsatisfiedLinkError is thrown.</p><p>7.        transient</p><p>·         Can be applied to class level variables only.(Local variables cannot be declared transient)</p><p>·         Transient variables may not be final or static.(But compiler allows the declaration, since it doesn't do any harm. Variables marked transient are never serialized. Static variables are not serialized anyway.)</p><p>·         Not stored as part of object's persistent state, i.e. not written out during serialization.</p><p>·         Can be used for security.</p><p>8.        synchronized</p><p>·         Can be applied to methods or parts of methods only.</p><p>·         Used to control access to critical code in multi-threaded programs.</p><p>9.        volatile</p><p>·         Can be applied to variables only.</p><p>·         Can be applied to static variables.</p><p>·         Cannot be applied to final variables.</p><p>·         Declaring a variable volatile indicates that it might be modified asynchronously, so that all threads will get the correct value of the variable.</p><p>·         Used in multi-processor environments.<br
/> Unary Numeric Promotion</p><p>Contexts:</p><p>·         Operand of the unary arithmetic operators + and -</p><p>·         Operand of the unary integer bit-wise complement operator ~</p><p>·         During array creation, for example new int[x], where the dimension expression x must evaluate to an int value.</p><p>·         Indexing array elements, for example table['a'], where the index expression must evaluate to an int value.</p><p>·         Individual operands of the shift operators.</p><p>Binary numeric promotion</p><p>Contexts:</p><p>·         Operands of arithmetic operators *, / , %, + and -</p><p>·         Operands of relational operators <, <= , > and >=</p><p>·         Numeric Operands of equality operators == and !=</p><p>·         Integer Operands of bit-wise operators &#038;, ^ and |</p><p>Conversion of Primitives<br
/> 1.        3 types of conversion &#8211; assignment conversion, method call conversion and arithmetic promotion</p><p>2.        boolean may not be converted to/from any non-boolean type.</p><p>3.        Widening conversions accepted. Narrowing conversions rejected.</p><p>4.        byte, short can&#8217;t be converted to char and vice versa.  ( but can be cast )</p><p>5.        Arithmetic promotion</p><p>5.1     Unary operators</p><p>·         if the operand is byte, short or char  {</p><p>convert it to int;</p><p> }</p><p> else {</p><p>do nothing; no conversion needed;</p><p>}</p><p>5.2     Binary operators</p><p>·         if one operand is double {</p><p>all double; convert the other operand to double;</p><p> }</p><p> else if one operand is float {</p><p>all float; convert the other operand to float;</p><p>}</p><p>else if one operand is long {</p><p>all long; convert the other operand to long;</p><p>}</p><p>else {</p><p>all int; convert all to int;</p><p>}</p><p>6.        When assigning a literal value to a variable, the range of the variable&#8217;s data type is checked against the value of the literal and assignment is allowed or compiler will produce an error.</p><p>char c = 3; // this will compile, even though a numeric literal is by default an int since the range of char will accept the value</p><p>int a = 3;</p><p>char d = a; // this won&#8217;t compile, since we&#8217;re assigning an int to char</p><p>char e = -1; // this also won&#8217;t compile, since the value is not in the range of char</p><p>float f = 1.3; // this won&#8217;t compile, even though the value is within float range. Here range is not  important, but precision is. 1.3 is by default a double, so a specific cast or f = 1.3f will work.</p><p>float f = 1/3; // this will compile, since RHS evaluates to an int.</p><p>Float f = 1.0 / 3.0; // this won&#8217;t compile, since RHS evaluates to a double.</p><p>7.        Also when assigning a final variable to a variable, even if the final variable&#8217;s data type is wider than the variable, if the value is within the range of the variable an implicit conversion is done.</p><p>byte b;</p><p>final int a = 10;</p><p>b = a; // Legal, since value of &#8216;a&#8217; is determinable and within range of b</p><p>final int x = a;</p><p>b = x; // Legal, since value of &#8216;x&#8217; is determinable and within range of b</p><p>int y;</p><p>final int z = y;</p><p>b = z; // Illegal, since value of &#8216;z&#8217; is not determinable</p><p>8.        Method call conversions always look for the exact data type or a wider one in the method signatures. They will not do narrowing conversions to resolve methods, instead we will get a compile error.</p><p>Here is the figure of allowable primitive conversion.</p><p>byte à short à int à long à float à double</p><p> ­</p><p> char</p><p>Casting of Primitives</p><p>9.        Needed with narrowing conversions. Use with care &#8211; radical information loss. Also can be used with widening conversions, to improve the clarity of the code.</p><p>10.     Can cast any non-boolean type to another non-boolean type.</p><p>11.     Cannot cast a boolean or to a boolean type.</p><p>Conversion of Object references</p><p>12.     Three types of reference variables to denote objects &#8211; class, interface or array type.</p><p>13.     Two kinds of objects can be created &#8211; class or array.</p><p>14.     Two types of conversion &#8211; assignment and method call.</p><p>15.     Permitted if the direction of the conversion is &#8216;up&#8217; the inheritance hierarchy. Means that types can be assigned/substituted to only super-types &#8211; super-classes or interfaces. Not the other way around, explicit casting is needed for that.</p><p>16.     Interfaces can be used as types when declaring variables, so they participate in the object reference conversion. But we cannot instantiate an interface, since it is abstract and doesn&#8217;t provide any implementation. These variables can be used to hold objects of classes that implement the interface. The reason for having interfaces as types may be, I think, several unrelated classes may implement the same interface and if there&#8217;s a need to deal with them collectively one way of treating them may be an array of the interface type that they implement.</p><p>17.     Primitive arrays can be converted to only the arrays of the same primitive type. They cannot be converted to another type of primitive array. Only object reference arrays can be converted / cast.</p><p>18.     Primitive arrays can be converted to an Object reference, but not to an Object[] reference. This is because all arrays (primitive arrays and Object[]) are extended from Object.</p><p>Casting of Object references</p><p>19.     Allows super-types to be assigned to subtypes. Extensive checks done both at compile and runtime. At compile time, class of the object may not be known, so at runtime if checks fail, a ClassCastException is thrown.</p><p>20.     Cast operator, instanceof operator and the == operator behave the same way in allowing references to be the operands of them. You cannot cast or apply instanceof or compare unrelated references, sibling references or any incompatible references.</p><p>Compile-time Rules</p><p>·         When old and new types are classes, one class must be the sub-class of the other.</p><p>·         When old and new types are arrays, both must contain reference types and it must be legal to cast between those types (primitive arrays cannot be cast, conversion possible only between same type of primitive arrays).</p><p>·         We can always cast between an interface and a non-final object.</p><p>Run-time rules</p><p>·         If new type is a class, the class of the expression being converted must be new type or extend new type.</p><p>·         If new type is an interface, the class of the expression being converted must implement the interface.</p><p>An Object reference can be converted to: (java.lang.Object)</p><p>·         an Object reference</p><p>·         a Cloneable interface reference, with casting, with runtime check</p><p>·         any class reference, with casting, with runtime check</p><p>·         any array referenece, with casting, with runtime check</p><p>·         any interface reference, with casting, with runtime check</p><p>A Class type reference can be converted to:</p><p>·         any super-class type reference, (including Object)</p><p>·         any sub-class type reference, with casting, with runtime check</p><p>·         an interface reference, if the class implements that interface</p><p>·         any interface reference, with casting, with runtime check (except if the class is final and doesn&#8217;t implement the interface)</p><p>An Interface reference can be converted to:</p><p>·         an Object reference</p><p>·         a super-interface reference</p><p>·         any interface/class reference with casting, with runtime check (except if the class is final and doesn&#8217;t implement the interface)</p><p>A Primitive Array reference can be converted to:</p><p>·         an Object reference</p><p>·         a Cloneable interface reference</p><p>·         a primitive array reference of the same type</p><p>An Object Array reference can be converted to:</p><p>·         an Object reference</p><p>·         a  Cloneable interface reference</p><p>·         a super-class Array reference, including an Object Array reference</p><p>·         any sub-class Array reference with casting, with runtime check<br
/> Unreachable statements produce a compile-time error.</p><p>while (false) { x = 3; } // won&#8217;t compile</p><p>for (;false;) { x =3; } // won&#8217;t compile</p><p>if (false) {x = 3; } // will compile, to provide the ability to conditionally compile the code.</p><p>·         Local variables already declared in an enclosing block, therefore visible in a nested block cannot be re-declared inside the nested block.</p><p>·         A local variable in a block may be re-declared in another local block, if the blocks are disjoint.</p><p>·         Method parameters cannot be re-declared.</p><p>1.        Loop constructs</p><p>·         3 constructs &#8211; for, while, do</p><p>·         All loops are controlled by a boolean expression.</p><p>·         In while and for, the test occurs at the top, so if the test fails at the first time, body of the loop might not be executed at all.</p><p>·         In do, test occurs at the bottom, so the body is executed at least once.</p><p>·         In for, we can declare multiple variables in the first part of the loop separated by commas, also we can have multiple statements in the third part separated by commas.</p><p>·         In the first section of for statement, we can have a list of declaration statements or a list of expression statements, but not both. We cannot mix them.</p><p>·         All expressions in the third section of for statement will always execute, even if the first expression makes the loop condition false. There is no short -circuit here.</p><p>2.        Selection Statements</p><p>·         if takes a boolean arguments. Parenthesis required. else part is optional. else if structure provides multiple selective branching.</p><p>·         switch takes an argument of byte, short, char or int.(assignment compatible to int)</p><p>·         case value should be a constant expression that can be evaluated at compile time.</p><p>·         Compiler checks each case value against the range of the switch expression&#8217;s data type.  The following code won&#8217;t compile.</p><p>byte b;</p><p>switch (b) {</p><p> case 200: // 200 not in range of byte</p><p> default:</p><p>}</p><p>·         We need to place a break statement in each case block to prevent the execution to fall through other case blocks. But this is not a part of switch statement and not enforced by the compiler.</p><p>·         We can have multiple case statements execute the same code. Just list them one by one.</p><p>·         default case can be placed anywhere. It&#8217;ll be executed only if none of the case values match.</p><p>·         switch can be nested. Nested case labels are independent, don&#8217;t clash with outer case labels.</p><p>·         Empty switch construct is a valid construct. But any statement within the switch block should come under a case label or the default case label.</p><p>3.        Branching statements</p><p>·         break statement can be used with any kind of loop or a switch statement or just a labeled block.</p><p>·         continue statement can be used with only a loop (any kind of loop).</p><p>·         Loops can have labels. We can use break and continue statements to branch out of multiple levels of nested loops using labels.</p><p>·         Names of the labels follow the same rules as the name of the variables.(Identifiers)</p><p>·         Labels can have the same name, as long as they don&#8217;t enclose one another.</p><p>·         There is no restriction against using the same identifier as a label and as the name of a package, class, interface, method, field, parameter, or local variable.</p><p>4.        Exception Handling</p><p>·         An exception is an event that occurs during the execution of a program that disrupts the normal flow of instructions.</p><p>·         There are 3 main advantages for exceptions:</p><p>1.        Separates error handling code from &#8220;regular&#8221; code</p><p>2.        Propagating errors up the call stack (without tedious programming)</p><p>3.        Grouping error types and error differentiation</p><p>·         An exception causes a jump to the end of try block. If the exception occurred in a method called from a try block, the called method is abandoned.</p><p>·         If there&#8217;s a catch block for the occurred exception or a parent class of the exception, the exception is now considered handled.</p><p>·         At least one &#8216;catch&#8217; block or one &#8216;finally&#8217; block must accompany a &#8216;try&#8217; statement. If all 3 blocks are present, the order is important. (try/catch/finally)</p><p>·         finally and catch can come only with try, they cannot appear on their own.</p><p>·         Regardless of whether or not an exception occurred or whether or not it was handled, if there is a finally block, it&#8217;ll be executed always. (Even if there is a return statement in try block).</p><p>·         System.exit() and error conditions are the only exceptions where finally block is not executed.</p><p>·         If there was no exception or the exception was handled, execution continues at the statement after the try/catch/finally blocks.</p><p>·         If the exception is not handled, the process repeats looking for next enclosing try block up the call hierarchy. If this search reaches the top level of the hierarchy (the point at which the thread was created), then the thread is killed and message stack trace is dumped to System.err.</p><p>·         Use throw new xxxException() to throw an exception. If the thrown object is null, a NullPointerException will be thrown at the handler.</p><p>·         If an exception handler re-throws an exception (throw in a catch block), same rules apply. Either you need to have a try/catch within the catch or specify the entire method as throwing the exception that&#8217;s being re-thrown in the catch block. Catch blocks at the same level will not handle the exceptions thrown in a catch block &#8211; it needs its own handlers.</p><p>·         The method fillInStackTrace() in Throwable class throws a Throwable object. It will be useful when re-throwing an exception or error.</p><p>·         The Java language requires that methods either catch or specify all checked exceptions that can be thrown within the scope of that method.</p><p>·         All objects of type java.lang.Exception are checked exceptions. (Except the classes under java.lang.RuntimeException) If any method that contains lines of code that might throw checked exceptions, compiler checks whether you&#8217;ve handled the exceptions or you&#8217;ve declared the methods as throwing the exceptions. Hence the name checked exceptions.</p><p>·         If there&#8217;s no code in try block that may throw exceptions specified in the catch blocks, compiler will produce an error. (This is not the case for super-class Exception)</p><p>·         Java.lang.RuntimeException and java.lang.Error need not be handled or declared.</p><p>·         An overriding method may not throw a checked exception unless the overridden method also throws that exception or a super-class of that exception. In other words, an overriding method may not throw checked exceptions that are not thrown by the overridden method. If we allow the overriding methods in sub-classes to throw more general exceptions than the overridden method in the parent class, then the compiler has no way of checking the exceptions the sub-class might throw. (If we declared a parent class variable and at runtime it refers to sub-class object) This violates the concept of checked exceptions and the sub-classes would be able to by-pass the enforced checks done by the compiler for checked exceptions. This should not be allowed.<br
/> Implementing OO relationships</p><p>·         &#8220;is a&#8221; relationship is implemented by inheritance (extends keyword)</p><p>·         &#8220;has a&#8221; relationship is implemented by providing the class with member variables.</p><p>Overloading and Overriding</p><p>·         Overloading is an example of polymorphism. (operational / parametric)</p><p>·         Overriding is an example of runtime polymorphism (inclusive)</p><p>·         A method can have the same name as another method in the same class, provided it forms either a valid overload or override</p><p>Overloading  :<br
/> Signature has to be different. Just a difference in return type is not enough.<br
/> Accessibility may vary freely.<br
/> Exception list may vary freely.<br
/> Just the name is reused. Methods are independent methods. Resolved at compile-time based on method signature.<br
/> Can call each other by providing appropriate argument list.<br
/> Methods can be static or non-static. Since the methods are independent, it doesn&#8217;t matter. But if two methods have the same signature, declaring one as static and another as non-static does not provide a valid overload. It&#8217;s a compile time error.<br
/> There&#8217;s no limit on number of overloaded methods a class can have.<br
/> Overriding :<br
/> Signature has to be the same. (including the return type)<br
/> Overriding methods cannot be more private than the overridden methods.<br
/> Overriding methods may not throw more checked exceptions than the overridden methods.<br
/> Related directly to sub-classing. Overrides the parent class method. Resolved at run-time based on type of the object.<br
/> Overriding method can call overridden method by super.methodName(), this can be used only to access the immediate super-class&#8217;s method. super.super won&#8217;t work. Also, a class outside the inheritance hierarchy can&#8217;t use this technique.<br
/> static methods don&#8217;t participate in overriding, since they are resolved at compile time based on the type of reference variable. A static method in a sub-class can&#8217;t use &#8217;super&#8217; (for the same reason that it can&#8217;t use &#8216;this&#8217; for) Remember that a static method can&#8217;t be overridden to be non-static and a non-static method can&#8217;t be overridden to be static. In other words, a static method and a non-static method cannot have the same name and signature (if signatures are different, it would have formed a valid overload)<br
/> Each parent class method may be overridden at most once in any sub-class. (That is, you cannot have two identical methods in the same class)</p><p>·         Variables can also be overridden, it&#8217;s known as shadowing  or hiding. But, member variable references are resolved at compile-time. So at the runtime, if the class of the object referred by a parent class reference variable, is in fact a sub-class having a shadowing member variable, only the parent class variable is accessed, since it&#8217;s already resolved at compile time based on the reference variable type. Only methods are resolved at run-time.<br
/> ·         Also, methods access variables only in context of the class of the object they belong to. If a sub-class method calls explicitly a super class method, the super class method always will access the super-class variable. Super class methods will not access the shadowing variables declared in subclasses because they don&#8217;t know about them. (When an object is created, instances of all its super-classes are also created.) But the method accessed will be again subject to dynamic lookup. It is always decided at runtime which implementation is called. (Only static methods are resolved at compile-time)<br
/> ·         With OO languages, the class of the object may not be known at compile-time (by virtue of inheritance). JVM from the start is designed to support OO. So, the JVM insures that the method called will be from the real class of the object (not with the variable type declared). This is accomplished by virtual method invocation (late binding). Compiler will form the argument list and produce one method invocation instruction &#8211; its job is over. The job of identifying and calling the proper target code is performed by JVM.</p><p>·         JVM knows about the variable&#8217;s real type at any time since when it allocates memory for an object, it also marks the type with it. Objects always know &#8216;who they are&#8217;. This is the basis of instanceof operator.</p><p>·         Sub-classes can use super keyword to access the shadowed variables in super-classes. This technique allows for accessing only the immediate super-class. super.super is not valid. But casting the &#8216;this&#8217; reference to classes up above the hierarchy will do the trick. By this way, variables in super-classes above any level can be accessed from a sub-class, since variables are resolved at compile time, when we cast the &#8216;this&#8217; reference to a super-super-class, the compiler binds the super-super-class variable. But this technique is not possible with methods since methods are resolved always at runtime, and the method gets called depends on the type of object, not the type of reference variable. So it is not at all possible to access a method in a super-super-class from a subclass.<br
/> ·         An inherited method, which was not abstract on the super-class, can be declared abstract in a sub-class (thereby making the sub-class abstract). There is no restriction.</p><p>·         In the same token, a subclass can be declared abstract regardless of whether the super-class was abstract or not.</p><p>·         Private members are not inherited, but they do exist in the sub-classes. Since the private methods are not inherited, they cannot be overridden. A method in a subclass with the same signature as a private method in the super-class is essentially a new method, independent from super-class, since the private method in the super-class is not visible in the sub-class.<br
/> ·         Constructors are not inherited as normal methods, they have to be defined in the class itself.</p><p>·         If you define no constructors at all, then the compiler provides a default constructor with no arguments. Even if, you define one constructor, this default is not provided.</p><p>·         We can&#8217;t compile a sub-class if the immediate super-class doesn&#8217;t have a no argument default constructor, and sub-class constructors are not calling super or this explicitly (and expect the compiler to insert an implicit super() call )</p><p>·         A constructor can call other overloaded constructors by &#8216;this (arguments)&#8217;. If you use this, it must be the first statement in the constructor. This construct can be used only from within a constructor.</p><p>·         A constructor can&#8217;t call the same constructor from within. Compiler will say &#8216; recursive constructor invocation&#8217;</p><p>·         A constructor can call the parent class constructor explicitly by using &#8217;super (arguments)&#8217;. If you do this, it must be first the statement in the constructor. This construct can be used only from within a constructor.</p><p>·         Obviously, we can&#8217;t use both this and super in the same constructor. If compiler sees a this or super, it won&#8217;t insert a default call to super().</p><p>·         Constructors can&#8217;t have a return type. A method with a class name, but with a return type is not considered a constructor, but just a method by compiler. Expect trick questions using this.</p><p>·         Constructor body can have an empty return statement. Though void cannot be specified with the constructor signature, empty return statement is acceptable.</p><p>·         Only modifiers that a constructor can have are the accessibility modifiers.</p><p>·         Constructors cannot be overridden, since they are not inherited.</p><p>·         Initializers are used in initialization of objects and classes and to define constants in interfaces. These initializers are :</p><p>1.       Static and Instance variable initializer expressions.</p><p>§         Literals and method calls to initialize variables.</p><p>§         Static variables can be initialized only by static method calls.</p><p>§         Cannot pass on the checked exceptions. Must catch and handle them.</p><p>2.       Static initializer blocks.</p><p>§         Used to initialize static variables and load native libraries.</p><p>§         Cannot pass on the checked exceptions. Must catch and handle them.</p><p>3.       Instance initializer blocks.</p><p>§         Used to factor out code that is common to all the constructors.</p><p>§         Also useful with anonymous classes since they cannot have constructors.</p><p>§         All constructors must declare the uncaught checked exceptions, if any.</p><p>§         Instance Initializers in anonymous classes can throw any exception.</p><p>·         In all the initializers, forward referencing of variables is not allowed. Forward referencing of methods is allowed.</p><p>·         Order of code execution (when creating an object) is a bit tricky.</p><p>1.        static variables initialization.</p><p>2.        static initializer block execution. (in the order of declaration, if multiple blocks found)</p><p>3.        constructor header ( super or this &#8211; implicit or explicit )</p><p>4.        instance variables initialization / instance initializer block(s) execution</p><p>5.        rest of the code in the constructor<br
/> Interfaces:</p><p>·         All methods in an interface are implicitly public, abstract, and never static.</p><p>·         All variables in an interface are implicitly static, public, final. They cannot be transient or volatile. A class can shadow the variables it inherits from an interface, with its own variables.</p><p>·         A top-level interface itself cannot be declared as static or final since it doesn&#8217;t make sense.</p><p>·         Declaring parameters to be final is at method&#8217;s discretion, this is not part of method signature.</p><p>·         Same case with final, synchronized, native. Classes can declare the methods to be final, synchronized or native whereas in an interface they cannot be specified like that. (These are implementation details, interface need not worry about this)</p><p>·         But classes cannot implement an interface method with a static method.</p><p>·         If an interface specifies an exception list for a method, then the class implementing the interface need not declare the method with the exception list. (Overriding methods can specify sub-set of overridden method&#8217;s exceptions, here none is a sub-set). But if the interface didn&#8217;t specify any exception list for a method, then the class cannot throw any exceptions.</p><p>·         All interface methods should have public accessibility when implemented in class.</p><p>·         Interfaces cannot be declared final, since they are implicitly abstract.</p><p>·         A class can implement two interfaces that have a method with the same signature or variables with the same name.</p><p>Inner Classes</p><p>·         A class can be declared in any scope. Classes defined inside of other classes are known as nested classes. There are four categories of nested classes.</p><p>1.        Top-level nested classes / interfaces</p><p>·         Declared as a class member with static modifier.</p><p>·         Just like other static features of a class. Can be accessed / instantiated without an instance of the outer class. Can access only static members of outer class. Can&#8217;t access instance variables or methods.</p><p>·         Very much like any-other package level class / interface. Provide an extension to packaging by the modified naming scheme at the top level.</p><p>·         Classes can declare both static and non-static members.</p><p>·         Any accessibility modifier can be specified.</p><p>·         Interfaces are implicitly static (static modifier also can be specified). They can have any accessibility modifier. There are no non-static inner, local or anonymous interfaces.</p><p>2.        Non-static inner classes</p><p>·         Declared as a class member without static.</p><p>·         An instance of a non-static inner class can exist only with an instance of its enclosing class. So it always has to be created within a context of an outer instance.</p><p>·         Just like other non-static features of a class. Can access all the features (even private) of the enclosing outer class. Have an implicit reference to the enclosing instance.</p><p>·         Cannot have any static members.</p><p>·         Can have any access modifier.</p><p>3.        Local classes</p><p>·         Defined inside a block (could be a method, a constructor, a local block, a static initializer or an instance initializer). Cannot be specified with static modifier.</p><p>·         Cannot have any access modifier (since they are effectively local to the block)</p><p>·         Cannot declare any static members.(Even declared in a static context)</p><p>·         Can access all the features of the enclosing class (because they are defined inside the method of the class) but can access only final variables defined inside the method (including method arguments). This is because the class can outlive the method, but the method local variables will go out of scope &#8211; in case of final variables, compiler makes a copy of those variables to be used by the class. (New meaning for final)</p><p>·         Since the names of local classes are not visible outside the local context, references of these classes cannot be declared outside. So their functionality could be accessed only via super-class references (either interfaces or classes). Objects of those class types are created inside methods and returned as super-class type references to the outside world. This is the reason that they can only access final variables within the local block. That way, the value of the variable can be always made available to the objects returned from the local context to outside world.</p><p>·         Cannot be specified with static modifier. But if they are declared inside a static context such as a static method or a static initializer, they become static classes. They can only access static members of the enclosing class and local final variables. But this doesn&#8217;t mean they cannot access any non-static features inherited from super classes. These features are their own, obtained via the inheritance hierarchy. They can be accessed normally with &#8216;this&#8217; or &#8217;super&#8217;.</p><p>4.        Anonymous classes</p><p>·         Anonymous classes are defined where they are constructed. They can be created wherever a reference expression can be used.</p><p>·         Anonymous classes cannot have explicit constructors. Instance initializers can be used to achieve the functionality of a constructor.</p><p>·         Typically used for creating objects on the fly.</p><p>·         Anonymous classes can implement an interface (implicit extension of Object) or explicitly extend a class. Cannot do both.</p><p>Syntax: new interface name() { } or new class name() { }</p><p>·         Keywords implements and extends are not used in anonymous classes.</p><p>·         Abstract classes can be specified in the creation of an anonymous class. The new class is a concrete class, which automatically extends the abstract class.</p><p>·         Discussion for local classes on static/non-static context, accessing enclosing variables, and declaring static variables also holds good for anonymous classes. In other words, anonymous classes cannot be specified with static, but based on the context, they could become static classes. In any case, anonymous classes are not allowed to declare static members. Based on the context, non-static/static features of outer classes are available to anonymous classes. Local final variables are always available to them.</p><p>·         One enclosing class can have multiple instances of inner classes.</p><p>·         Inner classes can have synchronous methods. But calling those methods obtains the lock for inner object only not the outer object.  If you need to synchronize an inner class method based on outer object, outer object lock must be obtained explicitly. Locks on inner object and outer object are independent.</p><p>·         Nested classes can extend any class or can implement any interface. No restrictions.</p><p>·         All nested classes (except anonymous classes) can be abstract or final.</p><p>·         Classes can be nested to any depth. Top-level static classes can be nested only within other static top-level classes or interfaces. Deeply nested classes also have access to all variables of the outer-most enclosing class (as well the immediate enclosing class&#8217;s)</p><p>·         Member inner classes can be forward referenced. Local inner classes cannot be.</p><p>·         An inner class variable can shadow an outer class variable. In this case, an outer class variable can be referred as (outerclassname.this.variablename).</p><p>·         Outer class variables are accessible within the inner class, but they are not inherited. They don&#8217;t become members of the inner class. This is different from inheritance. (Outer class cannot be referred using &#8217;super&#8217;, and outer class variables cannot be accessed using &#8216;this&#8217;)</p><p>·         An inner class variable can shadow an outer class variable. If the inner class is sub-classed within the same outer class, the variable has to be qualified explicitly in the sub-class. To fully qualify the variable, use classname.this.variablename. If we don&#8217;t correctly qualify the variable, a compiler error will occur. (Note that this does not happen in multiple levels of inheritance where an upper-most super-class&#8217;s variable is silently shadowed by the most recent super-class variable or in multiple levels of nested inner classes where an inner-most class&#8217;s variable silently shadows an outer-most class&#8217;s variable. Problem comes only when these two hierarchy chains (inheritance and containment) clash.)</p><p>·         If the inner class is sub-classed outside of the outer class (only possible with top-level nested classes) explicit qualification is not needed (it becomes regular class inheritance)</p><p>·         Java is fundamentally multi-threaded.</p><p>·         Every thread corresponds to an instance of java.lang.Thread class or a sub-class.</p><p>·         A thread becomes eligible to run, when its start() method is called. Thread scheduler co-ordinates between the threads and allows them to run.</p><p>·         When a thread begins execution, the scheduler calls its run method.</p><p>Signature of run method &#8211; public void run ()</p><p>·         When a thread returns from its run method (or stop method is called &#8211; deprecated in 1.2), its dead. It cannot be restarted, but its methods can be called. (it&#8217;s just an object no more in a running state)</p><p>·         If start is called again on a dead thread, IllegalThreadStateException is thrown.</p><p>·         When a thread is in running state, it may move out of that state for various reasons. When it becomes eligible for execution again, thread scheduler allows it to run.</p><p>·         There are two ways to implement threads.</p><p>1.        Extend Thread class</p><p>·         Create a new class, extending the Thread class.</p><p>·         Provide a public void run method, otherwise empty run in Thread class will be executed.</p><p>·         Create an instance of the new class.</p><p>·         Call start method on the instance (don&#8217;t call run &#8211; it will be executed on the same thread)</p><p>2.        Implement Runnable interface</p><p>·         Create a new class implementing the Runnable interface.</p><p>·         Provide a public void run method.</p><p>·         Create an instance of this class.</p><p>·         Create a Thread, passing the instance as a target &#8211; new Thread(object)</p><p>·         Target should implement Runnable, Thread class implements it, so it can be a target itself.</p><p>·         Call the start method on the Thread.</p><p>·         JVM creates one user thread for running a program. This thread is called main thread. The main method of the class is called from the main thread. It dies when the main method ends. If other user threads have been spawned from the main thread, program keeps running even if main thread dies. Basically a program runs until all the user threads (non-daemon threads) are dead.</p><p>·         A thread can be designated as a daemon thread by calling setDaemon(boolean) method. This method should be called before the thread is started, otherwise IllegalThreadStateException will be thrown.</p><p>·         A thread spawned by a daemon thread is a daemon thread.</p><p>·         Threads have priorities. Thread class have constants MAX_PRIORITY (10), MIN_PRIORITY (1), NORM_PRIORITY (5)</p><p>·         A newly created thread gets its priority from the creating thread. Normally it&#8217;ll be NORM_PRIORITY.</p><p>·         getPriority and setPriority are the methods to deal with priority of threads.</p><p>·         Java leaves the implementation of thread scheduling to JVM developers. Two types of scheduling can be done.</p><p>1.        Pre-emptive Scheduling.</p><p>Ways for a thread to leave running state -</p><p>·         It can cease to be ready to execute ( by calling a blocking i/o method)</p><p>·         It can get pre-empted by a high-priority thread, which becomes ready to execute.</p><p>·         It can explicitly call a thread-scheduling method such as wait or suspend.</p><p>·         Solaris JVM&#8217;s are pre-emptive.</p><p>·         Windows JVM&#8217;s were pre-emptive until Java 1.0.2</p><p>2.        Time-sliced or Round Robin Scheduling</p><p>·         A thread is only allowed to execute for a certain amount of time. After that, it has to contend for the CPU (virtual CPU, JVM) time with other threads.</p><p>·         This prevents a high-priority thread mono-policing the CPU.</p><p>·         The drawback with this scheduling is &#8211; it creates a non-deterministic system &#8211; at any point in time, you cannot tell which thread is running and how long it may continue to run.</p><p>·         Macintosh JVM&#8217;s</p><p>·         Windows JVM&#8217;s after Java 1.0.2</p><p>·         Different states of a thread:</p><p>1.        Yielding</p><p>·         Yield is a static method. Operates on current thread.</p><p>·         Moves the thread from running to ready state.</p><p>·         If there are no threads in ready state, the yielded thread may continue execution, otherwise it may have to compete with the other threads to run.</p><p>·         Run the threads that are doing time-consuming operations with a low priority and call yield periodically from those threads to avoid those threads locking up the CPU.</p><p>2.        Sleeping</p><p>·         Sleep is also a static method.</p><p>·         Sleeps for a certain amount of time. (passing time without doing anything and w/o using CPU)</p><p>·         Two overloaded versions &#8211; one with milliseconds, one with milliseconds and nanoseconds.</p><p>·         Throws an InterruptedException. (must be caught)</p><p>·         After the time expires, the sleeping thread goes to ready state. It may not execute immediately after the time expires. If there are other threads in ready state, it may have to compete with those threads to run. The correct statement is the sleeping thread would execute some time after the specified time period has elapsed.</p><p>·         If interrupt method is invoked on a sleeping thread, the thread moves to ready state. The next time it begins running, it executes the InterruptedException handler.</p><p>3.        Suspending</p><p>·         Suspend and resume are instance methods and are deprecated in 1.2</p><p>·         A thread that receives a suspend call, goes to suspended state and stays there until it receives a resume call on it.</p><p>·         A thread can suspend it itself, or another thread can suspend it.</p><p>·         But, a thread can be resumed only by another thread.</p><p>·         Calling resume on a thread that is not suspended has no effect.</p><p>·         Compiler won&#8217;t warn you if suspend and resume are successive statements, although the thread may not be able to be restarted.</p><p>4.        Blocking</p><p>·         Methods that are performing I/O have to wait for some occurrence in the outside world to happen before they can proceed. This behavior is blocking.</p><p>·         If a method needs to wait an indeterminable amount of time until some I/O takes place, then the thread should graciously step out of the CPU. All Java I/O methods behave this way.</p><p>·         A thread can also become blocked, if it failed to acquire the lock of a monitor.</p><p>5.        Waiting</p><p>·         wait, notify and notifyAll methods are not called on Thread, they&#8217;re called on Object. Because the object is the one which controls the threads in this case. It asks the threads to wait and then notifies when its state changes. It&#8217;s called a monitor.</p><p>·         Wait puts an executing thread into waiting state.(to the monitor&#8217;s waiting pool)</p><p>·         Notify moves one thread in the monitor&#8217;s waiting pool to ready state. We cannot control which thread is being notified. notifyAll is recommended.</p><p>·         NotifyAll moves all threads in the monitor&#8217;s waiting pool to ready.</p><p>·         These methods can only be called from synchronized code, or an IllegalMonitorStateException will be thrown. In other words, only the threads that obtained the object&#8217;s lock can call these methods.<br
/> Locks, Monitors and Synchronization</p><p>·         Every object has a lock (for every synchronized code block). At any moment, this lock is controlled by at most one thread.</p><p>·         A thread that wants to execute an object&#8217;s synchronized code must acquire the lock of the object. If it cannot acquire the lock, the thread goes into blocked state and comes to ready only when the object&#8217;s lock is available.</p><p>·         When a thread, which owns a lock, finishes executing the synchronized code, it gives up the lock.</p><p>·         Monitor (a.k.a Semaphore) is an object that can block and revive threads, an object that controls client threads. Asks the client threads to wait and notifies them when the time is right to continue, based on its state. In strict Java terminology, any object that has some synchronized code is a monitor.</p><p>·         2 ways to synchronize:</p><p>1.        Synchronize the entire method</p><p>·         Declare the method to be synchronized &#8211; very common practice.</p><p>·         Thread should obtain the object&#8217;s lock.</p><p>2.        Synchronize part of the method</p><p>·         Have to pass an arbitrary object which lock is to be obtained to execute the synchronized code block (part of a method).</p><p>·         We can specify &#8220;this&#8221; in place object, to obtain very brief locking &#8211; not very common.</p><p>·         wait &#8211; points to remember</p><p>§         calling thread gives up CPU</p><p>§         calling thread gives up the lock</p><p>§         calling thread goes to monitor&#8217;s waiting pool</p><p>§         wait also has a version with timeout in milliseconds. Use this if you&#8217;re not sure when the current thread will get notified, this avoids the thread being stuck in wait state forever.</p><p>·         notify &#8211; points to remember</p><p>§         one thread gets moved out of monitor&#8217;s waiting pool to ready state</p><p>§         notifyAll moves all the threads to ready state</p><p>§         Thread gets to execute must re-acquire the lock of the monitor before it can proceed.<br
/> ·         Points for complex models:</p><p>1.        Always check monitor&#8217;s state in a while loop, rather than in an if statement.</p><p>2.        Always call notifyAll, instead of notify.</p><p>·         Class locks control the static methods.</p><p>·         wait and sleep must be enclosed in a try/catch for InterruptedException.</p><p>·         A single thread can obtain multiple locks on multiple objects (or on the same object)</p><p>·         A thread owning the lock of an object can call other synchronous methods on the same object. (this is another lock) Other threads can&#8217;t do that. They should wait to get the lock.</p><p>·         Non-synchronous methods can be called at any time by any thread.</p><p>·         Synchronous methods are re-entrant. So they can be called recursively.</p><p>·         Synchronized methods can be overrided to be non-synchronous.  Synchronized behavior affects only the original class.</p><p>·         Locks on inner/outer objects are independent. Getting a lock on outer object doesn&#8217;t mean getting the lock on an inner object as well, that lock should be obtained separately.</p><p>·         wait and notify should be called from synchronized code. This ensures that while calling these methods the thread always has the lock on the object. If you have wait/notify in non-synchronized code compiler won&#8217;t catch this. At runtime, if the thread doesn&#8217;t have the lock while calling these methods, an IllegalMonitorStateException is thrown.</p><p>·         Deadlocks can occur easily. e.g, Thread A locked Object A and waiting to get a lock on Object B, but Thread B locked Object B and waiting to get a lock on Object A. They&#8217;ll be in this state forever.</p><p>·         It&#8217;s the programmer&#8217;s responsibility to avoid the deadlock. Always get the locks in the same order.</p><p>·         While &#8217;suspended&#8217;, the thread keeps the locks it obtained &#8211; so suspend is deprecated in 1.2</p><p>·         Use of stop is also deprecated; instead use a flag in run method. Compiler won&#8217;t warn you, if you have statements after a call to stop, even though they are not reachable.</p><p>*more <a
href="http://www.freejavaguide.com">here</a></p> ]]></content:encoded> <wfw:commentRss>http://www.freequestionbank.com/tech-crunch/programming-languages/short-java-notes/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Java/J2EE Programmer Practice Test</title><link>http://www.freequestionbank.com/tech-crunch/programming-languages/javaj2ee-programmer-practice-test/</link> <comments>http://www.freequestionbank.com/tech-crunch/programming-languages/javaj2ee-programmer-practice-test/#comments</comments> <pubDate>Tue, 24 Mar 2009 02:56:48 +0000</pubDate> <dc:creator>admin</dc:creator> <category><![CDATA[Languages]]></category> <category><![CDATA[Exam]]></category> <category><![CDATA[java]]></category> <category><![CDATA[Question]]></category> <category><![CDATA[scjp]]></category> <category><![CDATA[test]]></category><guid
isPermaLink="false">http://www.freequestionbank.com/?p=356</guid> <description><![CDATA[1. Which of the following are valid definitions of an application&#8217;s main( ) method?
a) public static void main();
b) public static ...]]></description> <content:encoded><![CDATA[<p>1. Which of the following are valid definitions of an application&#8217;s main( ) method?</p><p>a) public static void main();<br
/> b) public static void main( String args );<br
/> c) public static void main( String args[] );<br
/> d) public static void main( Graphics g );<br
/> e) public static boolean main( String args[] );<br
/> 2. If MyProg.java were compiled as an application and then run from the command line as:<br
/> java MyProg I like tests<br
/> what would be the value of args[ 1 ] inside the main( ) method?</p><p>a) MyProg<br
/> b) &#8220;I&#8221;<br
/> c) &#8220;like&#8221;<br
/> d) 3<br
/> e) 4<br
/> f) null until a value is assigned<br
/> 3. Which of the following are Java keywords?</p><p>a) array<br
/> b) boolean<br
/> c) Integer<br
/> d) protect<br
/> e) super<br
/> 4. After the declaration:<br
/> char[] c = new char[100];<br
/> what is the value of c[50]?</p><p>a) 50<br
/> b) 49<br
/> c) &#8216;\u0000&#8242;<br
/> d) &#8216;\u0020&#8242;<br
/> e) &#8221; &#8221;<br
/> f) cannot be determined<br
/> g) always null until a value is assigned</p><p>5. After the declaration:<br
/> int x;<br
/> the range of x is:</p><p>a) -231 to 231-1<br
/> b) -216 to 216 &#8211; 1<br
/> c) -232 to 232<br
/> d) -216 to 216<br
/> e) cannot be determined; it depends on the machine</p><p>6. Which identifiers are valid?</p><p>a) _xpoints<br
/> b) r2d2<br
/> c) bBb$<br
/> d) set-flow<br
/> e) thisisCrazy</p><p>7. Represent the number 6 as a hexadecimal literal.</p><p>8. Which of the following statements assigns &#8220;Hello Java&#8221; to the String variable s?</p><p>a) String s = &#8220;Hello Java&#8221;;<br
/> b) String s[] = &#8220;Hello Java&#8221;;<br
/> c) new String s = &#8220;Hello Java&#8221;;<br
/> d) String s = new String(&#8220;Hello Java&#8221;);</p><p>9. An integer, x has a binary value (using 1 byte) of 10011100. What is the binary value of z after these statements:<br
/> int y = 1 << 7;<br
/> int z = x & y;</p><p>a) 1000 0001<br
/> b) 1000 0000<br
/> c) 0000 0001<br
/> d) 1001 1101<br
/> e) 1001 1100</p><p>10. Which statements are accurate:</p><p>a) >> performs signed shift while >>> performs an unsigned shift.<br
/> b) >>> performs a signed shift while >> performs an unsigned shift.<br
/> c) << performs a signed shift while <<< performs an insigned shift.<br
/> d) <<< performs a signed shift while << performs an unsigned shift.</p><p>11. The statement ...<br
/> String s = "Hello" + "Java";<br
/> yields the same value for s as ...<br
/> String s = "Hello";<br
/> String s2= "Java";<br
/> s.concat( s2 );<br
/> True<br
/> False</p><p>12. If you compile and execute an application with the following code in its main() method:<br
/> String s = new String( "Computer" );</p><p>if( s == "Computer" )<br
/> System.out.println( "Equal A" );<br
/> if( s.equals( "Computer" ) )<br
/> System.out.println( "Equal B" );<br
/> a) It will not compile because the String class does not support the = = operator.<br
/> b) It will compile and run, but nothing is printed.<br
/> c) "Equal A" is the only thing that is printed.<br
/> d) "Equal B" is the only thing that is printed.<br
/> e) Both "Equal A" and "Equal B" are printed.</p><p>13. Consider the two statements:<br
/> 1. boolean passingScore = false &#038;&#038; grade == 70;<br
/> 2. boolean passingScore = false &#038; grade == 70;<br
/> The expression<br
/> grade == 70<br
/> is evaluated:</p><p>a) in both 1 and 2<br
/> b) in neither 1 nor 2<br
/> c) in 1 but not 2<br
/> d) in 2 but not 1<br
/> e) invalid because false should be FALSE</p><p>14. Given the variable declarations below:<br
/> byte myByte;<br
/> int myInt;<br
/> long myLong;<br
/> char myChar;<br
/> float myFloat;<br
/> double myDouble;<br
/> Which one of the following assignments would need an explicit cast?</p><p>a) myInt = myByte;<br
/> b) myInt = myLong;<br
/> c) myByte = 3;<br
/> d) myInt = myChar;<br
/> e) myFloat = myDouble;<br
/> f) myFloat = 3;<br
/> g) myDouble = 3.0;</p><p>15. Consider this class example:<br
/> class MyPoint<br
/> { void myMethod()<br
/> { int x, y;<br
/> x = 5; y = 3;<br
/> System.out.print( " ( " + x + ", " + y + " ) " );<br
/> switchCoords( x, y );<br
/> System.out.print( " ( " + x + ", " + y + " ) " );<br
/> }<br
/> void switchCoords( int x, int y )<br
/> { int temp;<br
/> temp = x;<br
/> x = y;<br
/> y = temp;<br
/> System.out.print( " ( " + x + ", " + y + " ) " );<br
/> }<br
/> }<br
/> What is printed to standard output if myMethod() is executed?</p><p>a) (5, 3) (5, 3) (5, 3)<br
/> b) (5, 3) (3, 5) (3, 5)<br
/> c) (5, 3) (3, 5) (5, 3)</p><p>16. To declare an array of 31 floating point numbers representing snowfall for each day of March in Gnome, Alaska, which declarations would be valid?</p><p>a) double snow[] = new double[31];<br
/> b) double snow[31] = new array[31];<br
/> c) double snow[31] = new array;<br
/> d) double[] snow = new double[31];</p><p>17. If arr[] contains only positive integer values, what does this function do?<br
/> public int guessWhat( int arr[] )<br
/> { int x= 0;<br
/> for( int i = 0; i < arr.length; i++ )<br
/> x = x < arr[i] ? arr[i] : x;<br
/> return x;<br
/> }<br
/> a) Returns the index of the highest element in the array<br
/> b) Returns true/false if there are any elements that repeat in the array<br
/> c) Returns how many even numbers are in the array<br
/> d) Returns the highest element in the array<br
/> e) Returns the number of question marks in the array</p><p>18. Consider the code below:<br
/> arr[0] = new int[4];<br
/> arr[1] = new int[3];<br
/> arr[2] = new int[2];<br
/> arr[3] = new int[1];<br
/> for( int n = 0; n < 4; n++ )<br
/> System.out.println( /* what goes here? */ );<br
/> Which statement below, when inserted as the body of the for loop, would print the number of values in each row?</p><p>a) arr[n].length();<br
/> b) arr.size;<br
/> c) arr.size -1;<br
/> d) arr[n][size];<br
/> e) arr[n].length;</p><p>19. If size = 4, triArray looks like:</p><p>int[][] makeArray( int size)<br
/> { int[][] triArray = new int[size] [];<br
/> int val=1;<br
/> for( int i = 0; i < triArray.length; i++ )<br
/> { triArray[i] = new int[i+1];<br
/> for( int j=0; j < triArray[i].length; j++ )<br
/> { triArray[i][j] = val++;<br
/> }<br
/> }<br
/> return triArray;<br
/> }</p><p>a)<br
/> 1 2 3 4<br
/> 5 6 7<br
/> 8 9<br
/> 10<br
/> b)<br
/> 1 4 9 16<br
/> c)<br
/> 1 2 3 4<br
/> d)<br
/> 1 2 3 4<br
/> 5 6 7 8<br
/> 9 10 11 12<br
/> 13 14 15 16<br
/> e)<br
/> 1<br
/> 2 3<br
/> 4 5 6<br
/> 7 8 9 10<br
/> 20. Which of the following are legal declarations of a two-dimensional array of integers?</p><p>a) int[5][5]a = new int[][];<br
/> b) int a = new int[5,5];<br
/> c) int[]a[] = new int[5][5];<br
/> d) int[][]a = new[5]int[5];</p><p>21. Which of the following are correct methods for initializing the array "dayhigh" with 7 values?</p><p>a) int dayhigh = { 24, 23, 24, 25, 25, 23, 21 };<br
/> b) int dayhigh[] = { 24, 23, 24, 25, 25, 23, 21 };<br
/> c) int[] dayhigh = { 24, 23, 24, 25, 25, 23, 21 };<br
/> d) int dayhigh [] = new int[24, 23, 24, 25, 25, 23, 21];<br
/> e) int dayhigh = new[24, 23, 24, 25, 25, 23, 21];</p><p>22. If you want subclasses to access, but not to override a superclass member method, what keyword should precede the name of the superclass method?</p><p>23. If you want a member variable to not be accessible outside the current class at all, what keyword should precede the name of the variable when declaring it?</p><p>24. Consider the code below:</p><p>public static void main( String args[] )<br
/> { int a = 5;<br
/> System.out.println( cube( a ) );<br
/> }<br
/> int cube( int theNum )<br
/> {<br
/> return theNum * theNum * theNum;<br
/> }</p><p>What will happen when you attempt to compile and run this code?</p><p>a) It will not compile because cube is already defined in the java.lang.Math class.<br
/> b) It will not compile because cube is not static.<br
/> c) It will compile, but throw an arithmetic exception.<br
/> d) It will run perfectly and print "125" to standard output.</p><p>25. Given the variables defined below:<br
/> int one = 1;<br
/> int two = 2;<br
/> char initial = '2';<br
/> boolean flag = true;<br
/> Which of the following are valid?</p><p>a) if( one ){}<br
/> b) if( one = two ){}<br
/> c) if( one == two ){}<br
/> d) if( flag ){}<br
/> e) switch( one ){}<br
/> f) switch( flag ){}<br
/> g) switch( initial ){}</p><p>26. If val = 1 in the code below:</p><p>switch( val )<br
/> { case 1: System.out.print( "P" );<br
/> case 2:<br
/> case 3: System.out.print( "Q" );<br
/> break;<br
/> case 4: System.out.print( "R" );<br
/> default: System.out.print( "S" );<br
/> }</p><p>Which values would be printed?</p><p>a) P<br
/> b) Q<br
/> c) R<br
/> d) S</p><p>27. Assume that val has been defined as an int for the code below:</p><p>if( val > 4 )<br
/> { System.out.println( &#8220;Test A&#8221; );<br
/> }<br
/> else if( val > 9 )<br
/> { System.out.println( &#8220;Test B&#8221; );<br
/> }<br
/> else System.out.println( &#8220;Test C&#8221; );</p><p>Which values of val will result in &#8220;Test C&#8221; being printed:<br
/> a) val < 0<br
/> b) val between 0 and 4<br
/> c) val between 4 and 9<br
/> d) val > 9<br
/> e) val = 0<br
/> f) no values for val will be satisfactory<br
/> 28. What exception might a wait() method throw?</p><p>29. For the code:</p><p>m = 0;<br
/> while( m++ < 2 )<br
/> System.out.println( m );</p><p>Which of the following are printed to standard output?</p><p>a) 0<br
/> b) 1<br
/> c) 2<br
/> d) 3<br
/> e) Nothing and an exception is thrown</p><p>30. Consider the code fragment below:</p><p>outer: for( int i = 1; i <3; i++ )<br
/> { inner: for( j = 1; j < 3; j++ )<br
/> { if( j==2 )<br
/> continue outer;<br
/> System.out.println( "i = " +i ", j = " + j );<br
/> }<br
/> }</p><p>Which of the following would be printed to standard output?</p><p>a) i = 1, j = 1<br
/> b) i = 1, j = 2<br
/> c) i = 1, j = 3<br
/> d) i = 2, j = 1<br
/> e) i = 2, j = 2<br
/> f) i = 2, j = 3<br
/> g) i = 3, j = 1<br
/> h) i = 3, j = 2</p><p>31. Consider the code below:<br
/> void myMethod()<br
/> { try<br
/> {<br
/> fragile();<br
/> }<br
/> catch( NullPointerException npex )<br
/> {<br
/> System.out.println( "NullPointerException thrown " );<br
/> }<br
/> catch( Exception ex )<br
/> {<br
/> System.out.println( "Exception thrown " );<br
/> }<br
/> finally<br
/> {<br
/> System.out.println( "Done with exceptions " );<br
/> }<br
/> System.out.println( "myMethod is done" );<br
/> }<br
/> What is printed to standard output if fragile() throws an IllegalArgumentException?</p><p>a) "NullPointerException thrown"<br
/> b) "Exception thrown"<br
/> c) "Done with exceptions"<br
/> d) "myMethod is done"<br
/> e) Nothing is printed</p><p>32. Consider the following code sample:<br
/> class Tree{}<br
/> class Pine extends Tree{}<br
/> class Oak extends Tree{}<br
/> public class Forest<br
/> { public static void main( String[] args )<br
/> { Tree tree = new Pine();</p><p>if( tree instanceof Pine )<br
/> System.out.println( "Pine" );</p><p>if( tree instanceof Tree )<br
/> System.out.println( "Tree" );</p><p>if( tree instanceof Oak )<br
/> System.out.println( "Oak" );</p><p>else System.out.println( "Oops" );<br
/> }<br
/> }<br
/> Select all choices that will be printed:</p><p>a) Pine<br
/> b) Tree<br
/> c) Forest<br
/> d) Oops<br
/> e) (nothing printed).</p><p>33. Consider the classes defined below:<br
/> import java.io.*;<br
/> class Super<br
/> {<br
/> int methodOne( int a, long b ) throws IOException<br
/> { // code that performs some calculations<br
/> }<br
/> float methodTwo( char a, int b )<br
/> { // code that performs other calculations<br
/> }<br
/> }<br
/> public class Sub extends Super<br
/> {</p><p>}<br
/> Which of the following are legal method declarations to add to the class Sub? Assume that each method is the only one being added.<br
/> a) public static void main( String args[] ){}<br
/> b) float methodTwo(){}<br
/> c) long methodOne( int c, long d ){}<br
/> d) int methodOne( int c, long d ) throws ArithmeticException{}<br
/> e) int methodOne( int c, long d ) throws FileNotFoundException{}<br
/> 34. Assume that Sub1 and Sub2 are both subclasses of class Super.<br
/> Given the declarations:</p><p>Super super = new Super();<br
/> Sub1 sub1 = new Sub1();<br
/> Sub2 sub2 = new Sub2();</p><p>Which statement best describes the result of attempting to compile and execute the following statement:</p><p>super = sub1;</p><p>a) Compiles and definitely legal at runtime<br
/> b) Does not compile<br
/> c) Compiles and may be illegal at runtime<br
/> 35. For the following code:<br
/> class Super<br
/> { int index = 5;<br
/> public void printVal()<br
/> { System.out.println( "Super" );<br
/> }<br
/> }<br
/> class Sub extends Super<br
/> { int index = 2;<br
/> public void printVal()<br
/> { System.out.println( "Sub" );<br
/> }<br
/> }<br
/> public class Runner<br
/> { public static void main( String argv[] )<br
/> { Super sup = new Sub();<br
/> System.out.print( sup.index + "," );<br
/> sup.printVal();<br
/> }<br
/> }<br
/> What will be printed to standard output?</p><p>a) The code will not compile.<br
/> b) The code compiles and "5, Super" is printed to standard output.<br
/> c) The code compiles and "5, Sub" is printed to standard output.<br
/> d) The code compiles and "2, Super" is printed to standard output.<br
/> e) The code compiles and "2, Sub" is printed to standard output.<br
/> f) The code compiles, but throws an exception.</p><p>36. How many objects are eligible for garbage collection once execution has reached the line labeled Line A?</p><p>String name;<br
/> String newName = "Nick";<br
/> newName = "Jason";<br
/> name = "Frieda";</p><p>String newestName = name;</p><p>name = null;<br
/> //Line A</p><p>a) 0<br
/> b) 1<br
/> c) 2<br
/> d) 3<br
/> e) 4</p><p>37. Which of the following statements about Java's garbage collection are true?</p><p>a) The garbage collector can be invoked explicitly using a Runtime object.<br
/> b) The finalize method is always called before an object is garbage collected.<br
/> c) Any class that includes a finalize method should invoke its superclass' finalize method.<br
/> d) Garbage collection behavior is very predictable.</p><p>38. What line of code would begin execution of a thread named myThread?</p><p>39. Which methods are required to implement the interface Runnable.</p><p>a) wait()<br
/> b) run()<br
/> c) stop()<br
/> d) update()<br
/> e) resume()</p><p>40. What class defines the wait() method?</p><p>41. For what reasons might a thread stop execution?</p><p>a) A thread with higher priority began execution.<br
/> b) The thread's wait() method was invoked.<br
/> c) The thread invoked its yield() method.<br
/> d) The thread's pause() method was invoked.<br
/> e) The thread's sleep() method was invoked.</p><p>42. Which method below can change a String object, s ?</p><p>a) equals( s )<br
/> b) substring( s )<br
/> c) concat( s )<br
/> d) toUpperCase( s )<br
/> e) none of the above will change s</p><p>43. If s1 is declared as:</p><p>String s1 = "phenobarbital";</p><p>What will be the value of s2 after the following line of code:<br
/> String s2 = s1.substring( 3, 5 );<br
/> 1.<br
/> a) null<br
/> b) "eno"<br
/> c) "enoba"<br
/> d) "no"</p><p>44. What method(s) from the java.lang.Math class might method() be if the statement</p><p>method( -4.4 ) == -4;</p><p>is true.</p><p>a) round()<br
/> b) min()<br
/> c) trunc()<br
/> d) abs()<br
/> e) floor()<br
/> f) ceil()</p><p>45. Which methods does java.lang.Math include for trigonometric computations?</p><p>a) sin()<br
/> b) cos()<br
/> c) tan()<br
/> d) aSin()<br
/> e) aCos()<br
/> f) aTan()<br
/> g) toDegree()</p><p>46. This piece of code:</p><p>TextArea ta = new TextArea( 10, 3 );</p><p>Produces (select all correct statements):</p><p>a) a TextArea with 10 rows and up to 3 columns<br
/> b) a TextArea with a variable number of columns not less than 10 and 3 rows<br
/> c) a TextArea that may not contain more than 30 characters<br
/> d) a TextArea that can be edited</p><p>47. In the list below, which subclass(es) of Component cannot be directly instantiated:</p><p>a) Panel<br
/> b) Dialog<br
/> c) Container<br
/> d) Frame</p><p>48. Of the five Component methods listed below, only one is also a method of the class MenuItem. Which one?</p><p>a) setVisible( boolean b )<br
/> b) setEnabled( boolean b )<br
/> c) getSize()<br
/> d) setForeground( Color c )<br
/> e) setBackground( Color c )</p><p>49. If a font with variable width is used to construct the string text for a column, the initial size of the column is:</p><p>a) determined by the number of characters in the string, multiplied by the width of a character in this font<br
/> b) determined by the number of characters in the string, multiplied by the average width of a character in this font<br
/> c) exclusively determined by the number of characters in the string<br
/> d) undetermined</p><p>50. Which of the following methods from the java.awt.Graphics class would be used to draw the outline of a rectangle with a single method call?</p><p>a) fillRect()<br
/> b) drawRect()<br
/> c) fillPolygon()<br
/> d) drawPolygon()<br
/> e) drawLine()</p><p>51. The Container methods add( Component comp ) and add( String name, Component comp ) will throw an IllegalArgumentException if comp is a:</p><p>a) button<br
/> b) list<br
/> c) window<br
/> d) textarea<br
/> e) container that contains this container</p><p>52. Of the following AWT classes, which one(s) are responsible for implementing the components layout?</p><p>a) LayoutManager<br
/> b) GridBagLayout<br
/> c) ActionListener<br
/> d) WindowAdapter<br
/> e) FlowLayout</p><p>53. A component that should resize vertically but not horizontally should be placed in a:</p><p>a) BorderLayout in the North or South location<br
/> b) FlowLayout as the first component<br
/> c) BorderLayout in the East or West location<br
/> d) BorderLayout in the Center location<br
/> e) GridLayout</p><p>54. What type of object is the parameter for all methods of the MouseListener interface?</p><p>55. Which of the following statements about event handling in JDK 1.1 and later are true?</p><p>a) A class can implement multiple listener interfaces<br
/> b) If a class implements a listener interface, it only has to overload the methods it uses<br
/> c) All of the MouseMotionAdapter class methods have a void return type.</p><p>56. Which of the following describe the sequence of method calls that result in a component being redrawn?</p><p>a) invoke paint() directly<br
/> b) invoke update which calls paint()<br
/> c) invoke repaint() which invokes update(), which in turn invokes paint()<br
/> d) invoke repaint() which invokes paint directly</p><p>57. Which of these is a correct fragment within the web-app element of deployment descriptor. Select the two correct answer.<br
/> A.<error-page> <error-code>404</error-code> <location>/error.jsp</location> </error-page><br
/> B.<error-page> <exception-type>mypackage.MyException</exception-type> <error-code>404</error-code> <location>/error.jsp</location> </error-page><br
/> C.<error-page> <exception-type>mypackage.MyException</exception-type> <error-code>404</error-code> </error-page><br
/> D.<error-page> <exception-type>mypackage.MyException</exception-type> <location>/error.jsp</location> </error-page><br
/> 58. A bean with a property color is loaded using the following statement<br
/> <jsp:usebean id="fruit" class="Fruit"/><br
/> Which of the following statements may be used to set the of color property of the bean. Select the one correct answer.<br
/> 1. <jsp:setColor id="fruit" property="color" value="white"/><br
/> 2. <jsp:setColor name="fruit" property="color" value="white"/><br
/> 3.<jsp:setValue name="fruit" property="color" value="white"/><br
/> 4.<jsp:setProperty name="fruit" property="color" value="white"><br
/> 5.<jsp:setProperty name="fruit" property="color" value="white"/><br
/> 6.<jsp:setProperty id="fruit" property="color" value="white"><br
/> 59. What gets printed when the following JSP code is invoked in a browser. Select the one correct answer.<br
/> <%= if(Math.random() < 0.5){ %><br
/> hello<br
/> <%= } else { %><br
/> hi<br
/> <%= } %><br
/> a.The browser will print either hello or hi based upon the return value of random.<br
/> b.The string hello will always get printed.<br
/> c.The string hi will always get printed.<br
/> d.The JSP file will not compile.<br
/> 60. Given the following web application deployment descriptor:<br
/> <web-app><br
/> <servlet><br
/> <servlet-name>myServlet</servlet-name><br
/> <servlet-class>MyServlet</servlet-class><br
/> &#8230;<br
/> </servlet><br
/> <servlet-mapping><br
/> <servlet-name>myServlet</servlet-name><br
/> <url-pattern>*.jsp</url-pattern><br
/> </servlet-mapping></p><p>which statements are true?</p><p>1) servlet-mapping element should be inside servlet element<br
/> 2) url-pattern can&#8217;t be defined that way.<br
/> 3) if you make the http call: http://host/Hello.jsp the servlet container will execute MyServlet.<br
/> 4) It would work with any extension excepting jsp,html,htm<br
/> 61.Name the class that includes the getSession method that is used to get the HttpSession object.<br
/> A.HttpServletRequest<br
/> B.HttpServletResponse<br
/> C.SessionContext<br
/> D.SessionConfig<br
/> 62. What will be the result of running the following jsp file taking into account that the Web server has just been started and this is the first page loaded by the server?<br
/><html><body><br
/> <%= request.getSession(false).getId() %><br
/></body></html><br
/> 1)It won&#8217;t compile<br
/> 2)It will print the session id.<br
/> 3)It will produce a NullPointerException as the getSession(false) method&#8217;s call returns null, cause no session had been created.<br
/> 4)It will produce an empty page.</p><p>63. The page directive is used to convey information about the page to JSP container. Which of these are legal syntax of page directive. Select the two correct statement<br
/> A.<% page info="test page" %><br
/> B.<%@ page info="test page" session="false"%><br
/> C.<%@ page session="true" %><br
/> D.<%@ page isErrorPage="errorPage.jsp" %><br
/> E.<%@ page isThreadSafe=true %><br
/> 64. Which of the following are methods of the Cookie Class?<br
/> 1) setComment<br
/> 2) getVersion<br
/> 3) setMaxAge<br
/> 4) getSecure.</p><p>*more <a
href="http://www.freejavaguide.com">here</a></p> ]]></content:encoded> <wfw:commentRss>http://www.freequestionbank.com/tech-crunch/programming-languages/javaj2ee-programmer-practice-test/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> </channel> </rss>
<!-- This site's performance optimized by W3 Total Cache. Dramatically improve the speed and reliability of your blog!

Learn more about our WordPress Plugins: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk (user agent is rejected)
Database Caching 5/13 queries in 0.199 seconds using disk

Served from: p3slh049.shr.phx3.secureserver.net @ 2010-09-07 19:17:06 -->