Manju Swamy

Greenhorn
+ Follow
since Mar 03, 2000
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Manju Swamy

Quote from the book


Only the &, |, and ^ logical operators can be combined with =, producing &=, |=, and ^= operators. Naturally, the left operand must be a boolean primitive variable.


This is definitely an error statement. The modified statement could be


Only the &, |, and ^ logical or binary operators can be combined with =, producing &=, |=, and ^= operators. The left operand can be any primitive variable.


You can E-mail this information to the author at mailto:examcram@lanw.com, so that it will show up in the errata.
Here is the link for the latest version (Version 2.0) of Jxam. Questions are now in a text file rather then MS Access database. Also the new version has 200 questions.
If you don't want to download the new version, here is the quote from the author.


The source code contains 1 debug class, the dbconvert class. This is used for extracting the questions out of a text file, and serializing them into a file called questions.db. This class is can be easily modified to extract all the questions from the database and save as text for reviewing purposes.



Hope this helps.
Here is the code out put:

I am using winnt java from SUN version 1.2.2.
Here is how you can find the java version.
C:\>java -version
java version "1.2.2"
Classic VM (build JDK-1.2.2-001, native threads, symcjit)
What platform / java version are you using?
Here are the quotes from JLS:


An integer literal may be expressed in decimal (base 10), hexadecimal (base 16), or octal (base 8):
An integer literal is of type long if it is suffixed with an ASCII letter L or l (ell); otherwise it is of type int (�4.2.1).


int i = 0x81;
The value of Ox81 in decimal system is 129.
The binary representation is 0000 0000 0000 0000 0000 0000 1000 0001
byte b = (byte) i;
When the value is casted to byte the last 8 bits are stored in the variable b.
The binary representation is 1000 0001 (the most significant bit is the sign bit).
Now value of b in decimal system is -127.
System.out.println("value of b >> 2 in Decimal: " + b >> 2);


Following are the quote from Mughal and Rasmussen book:
Since char, byte and short operands are promoted to either int or long, the result of applying these bitwise operators is always either an int or a long value.


Additional reading on Shift Operators from JLS.
Now the byte b variable is promoted to int.
The binary representation is 1111 1111 1111 1111 1111 1111 1000 0001
The decimal value is still -127.
The Hex representation is ffffff81
After the shit operation >> (shift right with sigh bit) the return value is int in this case.
The binary representation is 1111 1111 1111 1111 1111 1111 1110 0000
The decimal value is -32.
The Hex representation is ffffffe0
Hence the answer.



Another one related to that is question 25: give the result of 0x1 << 36<br /> The answer says it uses 36 mod 31 to get 0x1 << 5, I thought it was modulo 32? Anyway I am not sure how to test this, when I try and run something like this, I get an error saying "left shift exceeds size of the type being shifted"<br />
<br />

<br /> You are right on this one. You can verify by running the following code and reading the above mention JLS on Shift Operators.<br /> Note: Moderators this can be moved Mock Exam Errata.<br />
[This message has been edited by Manju Swamy (edited April 26, 2000).]
Here are some corrections/comments to the Maha
reply.
You can create an empty file (example EmptyClass.java) with no code and compile, it works!!!. It will not create any class files, since no class definition. Hey What is the use??? Noting. But adds the completeness to definition of Java program skeleton.
You can have only one package statement per Java source file.

You will get the following error message:
<pre>
F:\Java\EmptyClass.java:2: Class or interface declaration expected.
package xyz;
^
1 error
</pre>
If you comment out any one of the package statement, it complies fine.
You does not need to have import statement always.
You does not required to have class in a Java source file, but does not make any sense when you have no class definition. I will complete agree with you on 'maximum one public class per Java source'.
You can not declare the class to both abstract and final. You might already know it, but overlooked at it while posting. It should abstract or final. Here is an example.
extends is optional in the class declaration. If noting is specified it extends from Object class.
implements is optional in the class declaration.
When no constructors are specified for a class, at the compile time Java compiler inserts a default constructor for the class.
You can have 0 or more instance and/or static methods.
Note: My changes are in green color.
<pre>


//comments can come anywhere
package ... ( 0 to 1 statement )
import ... (0 ... n statements)
class ....( 0 ... n classes but maximum 1 public class )

Inside pacakge-level class
--------------------------
(public/default) abstract/final <ClassName> extends <OtherClassName> implements <InterfaceType1>, <InterfaceType2>, ... {
class variables declaration and initialization

instance variables declaration and initialization
inner class declaration (both static and non-static)
inner interface (both static and non static)

//static floating block
static {
}

//instance floating block
{

}
//constructors (0 ... n constructors)
class level (static) methods (0 ... n methods)
instance level (without static keyword) (0 ... n methods)

}


</pre>
Any comments are most welcome.

[This message has been edited by Manju Swamy (edited April 18, 2000).]
If you are really interested in same output as the first one, here is the solution:
Since j is a static variable you can use the class name prefix for the variable.
<pre>
public class Application2 {
static int j=2;
static protected void changeJ(int j) {
Application2.j+=1;
System.out.println("in method " + Application2.j);
}
static public void main(String[] args) {
System.out.println("before method " + j);
changeJ(j);
System.out.println("after method " + j);
}
}
</pre>
24 years ago
I agree with the mags answer.
The correct answer is
e. compilation succeeds. No exception is thrown during execution
To answer your second part of the question:
Now, if we change s1 as a String instead of StringBuffer, it throws a NullPointerException. Strange! Why is it behaving like this?
The String class overrides the equals() method. Here is the description for equals() method from Sun's Java 2 API documentation.
Compares this string to the specified object. The result is true if and only if the argument is not null and is a String object that represents the same sequence of characters as this object.
It will be a good idea to download the API reference document from Java Documentation download page or browse online at JavaTM 2 Platform, Standard Edition, v1.2.2 API Specification.

When both s and s1 reference variable declarations to String, at (1) equals() method returns true. At (2) the s1 will have null value means it is not referring to anything. At (3), when you call equals method on s1 that's where you get null pointer exception. How can you call a method on a null refferecne variable?

[This message has been edited by Manju Swamy (edited March 22, 2000).]

Could you please state you question clearly.

  • Did you had error while compiling? It compiles perfectly fine for me.
  • Are you expecting the this("hi") to print hi in the constructor? You need to refresh your constructor chaining concepts.
  • Do you have all these classes in one single source file?


  • In case you have all these classes are in one single file like Emp.java or Mgr.java, when try to compile and run from the IDE, since main() method is not defined in Mgr or Emp classes you will get a runtime error.
    In case you have successfully compiled the classes then try running StaticEmp1 class from the command prompt.



    [This message has been edited by Manju Swamy (edited March 17, 2000).]
24 years ago
Here is the code to print the array. Any time you see values similar to this
[[[Ljava.lang.String;@f35792c0 (it is not garbage), it is the String representation of the Object
(Arrays are objects in Java). All objects are inherited from Object class. The Object
class has toString() method. When you try to print the object in the
System.out.println() method, it will explicitly call object's toString() method.
The reason for loops are enclosed in the nested try...catch block is to catch the NullPointerException
and print the null values.

Go thorough the program output and analyze. Let us know if you need any further clarifications.

[This message has been edited by Manju Swamy (edited March 16, 2000).]

You can do your initialization in an instance initializer block.

[This message has been edited by Manju Swamy (edited March 15, 2000).]
[This message has been edited by Manju Swamy (edited March 15, 2000).]
[This message has been edited by Manju Swamy (edited March 15, 2000).]
24 years ago


Here is the errata for the Programmer Guide to Java Certification book by Khalid A. Mughal and Rolf W. Rasumussen.

The following lines are the extract from the author's errata page.
<h3>Page 126, 4.10 Other Modifiers for Members, <code>transient</code> Variables</h3>

"the <code>transient</code> modifier cannot be specified" should be "the <code>transient</code>
modifier should not be specified".

Exception hierarchy
<PRE>
+--java.lang.Exception
|
+--java.io.IOException
|
+--java.io.FileNotFoundException
</PRE>
Here are some of the possible choices:
1. You can enclose the call to some() method in try ... catch block.

2. Change the some2() method declaration to throw IOException inaddtion to FileNotFoundException.

3. Change the some2() method declaration to throw IOException only, since it is parent class of FileNotFoundException.

Hope this helps.
Also you are getting confused with Super class name and super keyword.
Careful reading always helps !!!
[This message has been edited by Manju Swamy (edited March 03, 2000).]
Here is an improvised version. This does not have a card number digits limitation. Also when use isDigit() function it reruns true for various other language (like Indian, Arabic, etc.) numbers. Then the whole logic would fail.

[This message has been edited by Manju Swamy (edited March 03, 2000).]
[This message has been edited by Manju Swamy (edited March 03, 2000).]
24 years ago