<?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>JavaBeat &#187; OCAJP</title>
	<atom:link href="http://www.javabeat.net/category/ocajp/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.javabeat.net</link>
	<description>Java Technology News</description>
	<lastBuildDate>Fri, 24 May 2013 01:32:07 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>OCAJP 7 Mock Exam Questions (Java Basics)</title>
		<link>http://www.javabeat.net/2013/02/ocajp-mock-exam-questions-java-basics/</link>
		<comments>http://www.javabeat.net/2013/02/ocajp-mock-exam-questions-java-basics/#comments</comments>
		<pubDate>Sun, 17 Feb 2013 14:51:58 +0000</pubDate>
		<dc:creator>krishnas</dc:creator>
				<category><![CDATA[OCAJP]]></category>

		<guid isPermaLink="false">http://www.javabeat.net/?p=5895</guid>
		<description><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><p>Q 1 : Which of the following are keywords in Java programming language a) public b) static c) void d) main e) scope Q 2 : Consider the code In the above code which of the following define local variables: a) i, j only. b) sum only. c) i, j and sum. d) There are [...]</p>]]></description>
				<content:encoded><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><div class="wpInsert wpInsertInPostAd wpInsertLeft" style="float: left; margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Rect */
google_ad_slot = "9976259118";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><a id="dd_start"></a><p><strong>Q 1 : Which of the following are keywords in Java programming language</strong></p>
<ul>
<li>a) public</li>
<li>b) static</li>
<li>c) void</li>
<li>d) main</li>
<li>e) scope</li>
</ul>
<p><strong><strong>Q 2 :</strong> Consider the code </strong></p>
<pre class="brush: java; title: ; notranslate">
private static void printTotal(int i, int j) {
int sum = i + j;
System.out.println(&quot;This program performs addition &quot; +
&quot;using two numbers supplied.&quot;);
System.out.println(&quot;The two numbers and the sum: &quot; +
i + &quot; + &quot; + j + &quot; = &quot; + sum);
}
</pre>
<p>In the above code which of the following define local variables:</p>
<ul>
<li>a) i, j only.</li>
<li>b) sum only.</li>
<li>c) i, j and sum.</li>
<li>d) There are no local variables.</li>
</ul>
<p><strong><strong>Q 3 : Which of the following are correct regarding Java variables </strong></strong></p>
<ul>
<li>a) The default value for boolean variable is: true.</li>
<li>b) A literal and a variable are the same.</li>
<li>c) This is a valid variable declaration: int _52 = 52;</li>
<li>d) This is a valid instance variable declaration: int i, j = 10;</li>
</ul>
<p><strong><strong>Q 4 :</strong></strong> Consider the code:</p>
<pre class="brush: java; title: ; notranslate">
// This program prints text and an integer number.
public class YearPrinter {
public static void main(String [] args) {
int year= 2013;
System.out.println(&quot;This year is: &quot; + year);
}
}
</pre>
<p>Which of the following are correct of the above code:</p>
<ul>
<li>a) &#8220;year&#8221; is a numeric variable.</li>
<li>b) &#8216;System.out.println(&#8220;This year is: &#8221; + year);&#8217; is a statement.</li>
<li>c) &#8220;YearPrinter&#8221; is the name of a class.</li>
<li>d) &#8220;main&#8221; is the name of a method.</li>
<li>e) &#8220;//&#8221; is used to write a comment within a class.</li>
</ul>
<p><strong><strong>Q 5 :</strong></strong> <strong>Which of the following code snippets correctly show statement &#8220;blocks&#8221;</strong></p>
<p>a.</p>
<pre class="brush: java; title: ; notranslate">
public int calculate(int a, int b) {
int c = a + b;
System.out.println(&quot;a+b = &quot; + c);
return c;
}
</pre>
<p>b.</p>
<pre class="brush: java; title: ; notranslate">
String a = &quot;Java&quot;;
String b = &quot;programming&quot;;
String c = &quot;Java programming&quot;;
if (c.equals(a + b)) {
System.out.println(&quot;Java programming&quot;); // prints Java programming
}
</pre>
<p>c.</p>
<pre class="brush: java; title: ; notranslate">
{
Object object = null;
}
</pre>
<p>d.</p>
<pre class="brush: java; title: ; notranslate">
Integer i = null;
try {
i = new Integer(&quot;56&quot;);
}
catch(NumberFormatException nfe) {
nfe.printStackTrace();
}
</pre>
<p><strong><strong>Q 6 : To create a Java application which of the following are required<br />
</strong></strong></p>
<ul>
<li>a) A source code file.</li>
<li>b) Java programming language compiler.</li>
<li>c) A text editor or an IDE.</li>
<li>d) The Java application launcer.</li>
</ul>
<p><strong><strong>Q 7 : Consider the code<br />
</strong></strong></p>
<pre class="brush: java; title: ; notranslate">
public class YearPrinter {
public static void main(String [] args) {
new YearPrinter().printIt();
}
private void printIt() {
int year= 2013;
System.out.println(&quot;This year is: &quot; + year);
}

}
</pre>
<p>Which one of the following is correct after the above is compiled and run:</p>
<ul>
<li>a) There is a compile time error.</li>
<li>b) The program prints &#8220;The year is: 2013&#8243;.</li>
<li>c) There is a runtime error.</li>
</ul>
<p><strong><strong>Q 8 : Consider the code<br />
</strong></strong></p>
<pre class="brush: java; title: ; notranslate">
package mypackage;

public class ClassA {
public static void main(String [] args) {
new ClassA().doThis();
}
public void doThis() {
System.out.println(&quot;Running the ClassA class.&quot;);
}
}
</pre>
<p>Assume that the ClassA.java is in the current directory. And, all the Java commands are run from the current directory. Which of the following are correct:</p><div class="wpInsert wpInsertInPostAd wpInsertMiddle" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Middle-Med-Rect */
google_ad_slot = "7805667846";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
<ul>
<li>a) The command &#8220;javac -d . ClassA.java&#8221; at command prompt creates a directory called mypackage, and ClassA.class file within that directory.</li>
<li>b) The above class can be run at the command prompt using the command &#8220;java mypackage.ClassA&#8221;.</li>
<li>c) The above class can be run at the command prompt using the command &#8220;java ClassA&#8221;.</li>
<li>d) The above class can be run at the command prompt using the command &#8220;java ClassA.class&#8221;.</li>
</ul>
<p><strong><strong>Q 9 : The package and import statements must be specified before a class definition within a class file </strong></strong></p>
<p>True or false:<strong><strong><br />
</strong></strong></p>
<p><strong><strong>Q 10 : Consider the following two Java classes<br />
</strong></strong></p>
<pre class="brush: java; title: ; notranslate">
ProgramA.java:

import java.util.ArrayList;
public class ProgramA {

public static void main (String [] rrr) {
ArrayList&lt;String&gt; list1 = new ArrayList&lt;String&gt;();
list1.add(&quot;element 1&quot;);
System.out.println(&quot;An element is added to the array list.&quot;);
}
}

ProgramB.java:

public class ProgramB {

public static void main (String [] args) {
java.util.ArrayList&lt;String&gt; list = new java.util.ArrayList&lt;String&gt;();
list.add(&quot;element 1&quot;);
System.out.println(&quot;An element is added to the array list.&quot;);
}
}
</pre>
<p>Which of the following are correct of the above two classes:</p>
<ul>
<li>a) Both ProgramA and ProgramB compile, run and print &#8220;An element is added to the arraylist .&#8221;.</li>
<li>b) Only ProgramA compiles, runs and prints &#8220;An element is added to the arraylist .&#8221;.</li>
<li>c) Only ProgramB compiles, runs and print &#8220;An element is added to the arraylist .&#8221;.</li>
<li>d) Both ProgramA and ProgramB fail to compile and run.</li>
</ul>
<h2 style="text-align: center;"><span style="text-decoration: underline;"><span style="color: #000080;"><strong>OCAJP Mock Exam Answers</strong></span></span></h2>
<p><span style="color: #000080;">The following are the answers for the above questions. these questions are created based on the real questions on the exam. If you find any incorrect or clarifications on the answers, please write it in the comments section.</span></p>
<blockquote><p><span style="color: #000080;"><strong>If you are interested in receiving 300 mock questions for OCAJP 7 from JavaBeat, please call +91 9740134466</strong></span></p></blockquote>
<p>1.  a, b and c are correct.<br />
d and e are incorrect.<br />
d: main is the name of a method. This is the method a Java program is launched from.<br />
e: scope is not a keyword.</p>
<p>2. c is correct.<br />
a, b and d are incorrect.<br />
c: The variables defined within a method are local variables. This includes the method parameters i and j in the above code.</p>
<p>3. c and d are correct.<br />
a and b are incorrect.<br />
a: The default value for boolean variable is &#8220;false&#8221;.<br />
b: Literals and variables are not the same. A literal is a value assigned to a variable. There are two types of literals; String and primitive type. An example of a String literal is &#8220;This is a String literal&#8221;. And, an example of a primitive literal is 52.<br />
d: The variable i is initialized to 0, and j is initialized to 10.</p>
<p>4. a, b, c, d and e are all correct.<br />
5. a, b, c and d are correct.<br />
A block is a group of statements of code defined within curly braces (&#8220;{ }&#8221;).<br />
6. a, b, c and d are correct.<br />
All are required. &#8220;Javac&#8221; is the Java compiler, and &#8220;java&#8221; is the application launcher required to compile the source code and run the application, respectively. A text editor may be used to create a Java application (for example, MyApp) in a source code file with the name like &#8220;MyApp.java&#8221;.<br />
7. b is correct.<br />
a and c are incorrect.</p>
<p>8. a and b are correct.<br />
c and d are incorrect.</p>
<p>a: &#8220;-d&#8221; option used with &#8220;javac&#8221; specifies the destination of the class file. &#8220;.&#8221; is used to specify the current directory. The class file is created as  mypackage/ClassA.class in the current directory.<br />
b: The program runs and prints &#8220;Running the ClassA class.&#8221;.<br />
c: Throws runtime exception. The class name is wrong.<br />
d: Prints Error: Could not find or load main class ClassA.class. The extension &#8220;.class&#8221; is not to be specified when a Java class is run.</p>
<p>9. True.<br />
The package statement must be the first statement in a class file, followed by import statements. Both package and import statements are optional. There can be only one package statement, and zero or more import statements. There can be comments specified before a package statement.</p>
<p>10. a is correct.<br />
b, c and d are incorrect.<br />
a: ArrayList class is defined in the java.util package of Java programming language API. In ProgramA, the import statement makes the ArrayList class available within the class. In ProgramB the ArrayList class is used with a fully qualified name, java.util.ArrayList.</p>
<div class='dd_outer'><div class='dd_inner'><div id='dd_ajax_float'><div class='dd_button_v'><script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><fb:like href="http%3A%2F%2Fwww.javabeat.net%2F2013%2F02%2Focajp-mock-exam-questions-java-basics%2F" send="false" show_faces="false"  layout="box_count" width="50"  ></fb:like></div><div style='clear:left'></div><div class='dd_button_v'><script type='text/javascript' src='https://apis.google.com/js/plusone.js'></script><g:plusone size='tall' href='http://www.javabeat.net/2013/02/ocajp-mock-exam-questions-java-basics/'></g:plusone></div><div style='clear:left'></div><div class='dd_button_v'><a href="http://twitter.com/share" class="twitter-share-button" data-url="http://www.javabeat.net/2013/02/ocajp-mock-exam-questions-java-basics/" data-count="vertical" data-text="OCAJP 7 Mock Exam Questions (Java Basics)" data-via="javabeat" ></a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div><div style='clear:left'></div><div class='dd_button_extra_v'><script type="text/javascript">jQuery(document).load(function(){ stLight.options({publisher:'bab47279-62c9-46af-addc-79fd1fe8fee0'}); });</script><div class="st_email_custom"><span id='dd_email_text'>email</span></div></div><div style='clear:left'></div><div class='dd_button_extra_v'><div id='dd_print_button'><span id='dd_print_text'><a href='javascript:window:print()'>print</a></span></div></div><div style='clear:left'></div></div></div></div><script type="text/javascript">var dd_offset_from_content = 44; var dd_top_offset_from_content = 0;</script><script type="text/javascript" src="http://www.javabeat.net/wp-content/plugins/digg-digg//js/diggdigg-floating-bar.js?ver=5.3.0"></script><div class="wpInsert wpInsertInPostAd wpInsertBelow" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* JB-Footer-LU 468x15 */
google_ad_slot = "8789107210";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>]]></content:encoded>
			<wfw:commentRss>http://www.javabeat.net/2013/02/ocajp-mock-exam-questions-java-basics/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
