Balasubramanyam Kallavi

Greenhorn
+ Follow
since Sep 22, 2000
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Balasubramanyam Kallavi

Hi Atin,
Let us first consider your question on why IO is required at all.
Input Output (IO) is basically communication between a computer and its users, its storage devices or other computers through networks. Every programming language provides some way of enabling programs to use IO facilities of the underlying platform in all the above flavors.
One most important use of IO is to enable storage of data that is processed in programs. Storage of data in variables and arrays is temporary, the data is lost when the local variables go out of scope.
Java provides a framework for data IO called "streams".A stream is an abstraction that either produces or consumes information. To bring-in data from some external source we use input streams. To send out data to some external source we use output streams. Note here that we have just been talking about sending-out and bringing-in data to or from some 'source'. The source can be any datasource like a file,socket,memory etc. That is the advantage Java IO streams, we need not be concerned too much on what kind of data sources we are working upon but concentrate on how we do the data transfer.
The first step in making our way through the maze of Java IO streams is to to understand how they are organized. You will find the "Lesson: Reading and Writing (but no 'rithmetic)" [Trail: Essential Java Classes] of Sun's Java Tutorial very useful for this purpose. You need to give atleast 3 rounds of studying this tutorial to begin recognizing the excellent way these streams are organized.
Once you have done that, if you have any further queries on specific methods in Java IO or any question is too tricky, please post it to this forum and any of the participants would be able to help you.
Hope this helps you get started with Java IO.
Best wishes,
Balu
Hi Umang,
Note that declaring a variable as 'transient' does not prevent it from being written. The idea behind declaring a variable as 'transient' is to prevent it's 'object state' from being saved. The values of the variables in an object comprises its state. Consider the example of transient variable definition given in your code:
private transient String s = "Hope I can ever be persistant!";
Now the object state of the object denoted by the variable 's' is the string value "Hope I can ever be persistant!". When we write this object through serialization, this value (object state) is not saved. So when you try to retrieve the object state again, we will not get the same value.
This expains the reason why Answer# 4 is incorrect.
Best wishes,
Balu
Hi Umang,
We never added any control components to the container. Please refer the code below with explanatory comments. As you would notice, in the original code, a call to setLayout() has been made followed by validate(), since there are no components added to the container, no buttons were displayed.
Best wishes,
Balu
Modified Code:
-------------
import java.awt.*;
public class TestFrame extends Frame
{
Button bNorth = new Button("North");
Button bSouth = new Button("South");
Button bEast = new Button("East");
Button bWest = new Button("West");
Button bCenter = new Button("Center");
public TestFrame()
{
setLayout(new FlowLayout());
add(bNorth);
add(bSouth);
add(bWest);
add(bEast);
add(bCenter);

setLayout(new BorderLayout());
add(bNorth, BorderLayout.NORTH); // We need to add some components after setting desired layout
// for the containers
add(bSouth, BorderLayout.SOUTH);
add(bWest, BorderLayout.WEST);
add(bEast, BorderLayout.EAST);
add(bCenter, BorderLayout.CENTER);
validate();// AWT uses validate to cause a container to lay out its subcomponents
// again after the components it contains have been added to or modified.
setSize(300,300);
setVisible(true);
}
public static void main(String args[])
{
TestFrame tf = new TestFrame();
}
}
Hi Sarim,
You may try the link given in Maha Anna's website (http://www.javaranch.com/maha/_Mock_Exams/_mock_exams.html). It is working for me:
http://www.appliedreasoni ng.com/javaCert/JavaCert ification.html
Best wishes,
Balu
Hi Sarim,
Please find replies mentioned against each of your queries mentioned below:
1. applets
2. applet tags
[Answer]We do not find these terms explicitly mentioned in the exam objectives but it is better to be aware of the basics. Suggest you to go through Pages.16-18 from the book "A programmer's guide to Java Certification" authored by Khalid A.Mughal and Rolf W.Rasmussen, Addison-Wesley for discussion on main elements of an applet. Pages.488-490 [Sections 16.1-16.2],
Pages.493-496 of the same book discussing further details about applet life cycle is also advisable.

3. command line codes besides javac and java, dealing with jar files
[Answer]Again, this does not find a mention in the exam objectives, but if you feel that it might be prudent to know the command line options, just type jar with an empty parameter on the command line and take a look at the options once or twice.
4. listener attributes from Java 1.0.2 where if a listener returns false events are passed up the heirarcy (do we need to know how this works ?
[Answer]Just read once and try to see the difference between the event delegation models. We cannot rule out the possibility of a question on this but not knowing about it may not hinder the chances of success in the exam either.
5. methods of collection interface and classes, do we really need to know a lot of these and how they work, since i have never really come across questions dealing with them and there seem to be quite a lot !
[Answer]Believe me, this was quite baffling to me also on the first round of study, but once you study the topic 2-3 times, you will learn to appreciate the common characteristics of all the classes in the Collections Framework, knowing common methods in the Collections Framework can help you a lot. Try going through the tutorial on Collections Framework at:
http://www.jguru.com/jguru/courses/collections/
For a detailed listing of the exam objectives please refer Sun's website at http://suned.sun.com/USA/certification/progobj.html gives a detailed listing of the exam objectives.
Best wishes,
Balu
Hi Tom,
Form Feed is the character used to start a new page on a printer. This is done by "feeding" a new page (or "form") through the printer.
Carriage Return is the character which causes the cursor to move to the left margin, often used with line feed to start a new line of output.
I am trying to either locate or write an example code for illustrating 'Form Feed' and I will try posting the code for that when it is a vailable. Meanwhile, the following example code for illustrating 'Carriage Return' may be useful for you.
Best wishes,
Balu
Example Program:
================
public class EscSeq
{
public static void main(String args[])
{
System.out.println("FirstLine");
System.out.println("\r");// Carriage return is the equivalent of hitting
// 'return' on your keyboard,
System.out.println("SecondLine");
}
}
Hi Sonal,
Please refer JLS 2.0 section 3.10.4 on Character Literals:
"Because Unicode escapes are processed very early, it is not correct to write '\u000a' for a character literal whose value is linefeed (LF); the Unicode escape \u000a is transformed into an actual linefeed in translation step 1 (�3.3) and the linefeed becomes a LineTerminator in step 2 (�3.4), and so the character literal is not valid in step 3. Instead, one should use the escape sequence '\n' (�3.10.6). Similarly, it is not correct to write '\u000d' for a character literal whose value is carriage return (CR). Instead, use '\r'."
Hope this clarifies your query.
Best wishes,
Balu
Hi Mugdha,
In line# 5 of your code, an explicit cast has been made from short to byte:
byte b = (byte)s;
If you comment the above line and simply specify:
byte b = s;
You will get the following compilation error:
X.java:5: Incompatible type for declaration. Explicit cast needed to convert short to byte.
Hope this clarifies your query.
Regards,
Balu
Note: Implicit narrowing primitive conversions on assignment can only occur in cases where the source is an int constant expression whose value can be determined to be in the range of the destination type at compile time; the destination type can be either byte, short or char type.
Hi Umang,
The JVM distinguishes threads as 2 types, daemon threads and non-daemon threads.
Daemon thread is one that is subordinate to the thread which created it. Daemon threads are described in various ways as 'attendant', 'helper' or 'background' threads.
A daemon thread cannot do anything on its own unless used by another non-daemon (user thread). Bill Venners explains the difference between the 2 types of threads clearly in his book "Inside the Java Virtual Machine":
"Inside the Java Virtual Machine, threads come in two flaovors: daemon and non-daemon. A daemon thread is ordinarily used by the virtual machine itself, such as a thread that performs garbage collection. The application, however, can mark any threads it creates as daemon threads. The initial thread of an application - the one that begins at main() - is a non-daemon thread. A Java application continues to execute (the virtual machine instance continues to live) as long as any non-daemon threads are still running. When all non-daemon threads of a Java application terminate, the virtual machine instance will exit. If pemitted by the security manager, the application can also cause its own demise by invoking the exit() method of class Runtime or System".
To set a thread as 'daemon' type, we call the setDaemon() method before calling the thread's start() method. Changing the status of a thread already started throws IllegalThreadStateException. The setDaemon() method in turn calls the checkAccess() method to verify if the currently running thread has permission to modify this thread.
The start() method of Thread class can be used for starting the daemon thread.
Hope this clarifies your query.
Best wishes,
Balu

Hi Sarim,
Clarifications to your queries on File IO are mentioned below.
[Query]if a file already exists on our hard disk what is the result of the following ?
1. creating that file using just File
[Clarification]We cannot create a file with just a 'File' object. The File class just provides us a handle to obtain some platform independent representation of a pathname and its components.
For creating a new empty file, use the boolean createNewFile() method as illustrated in the CreateFile.java example program given at the end of this reply.
2. creating that file using FileOutputStream
[Clarification]FileOutputStream is used for writing data as a byte array to a file. Contents of the existing file is overwritten.
3. creating the file using FileWriter
[Clarification]FileWriter is a convenience class for writing data as a character array to a file. Contents of the existing file is overwritten.
please explain:
a) any exceptions that may be thrown, comp. errors\
[Clarifications]All the exceptions thrown by File IO operations are subclasses of java.io.IOException. Since IOException is a checked exception, we need to explicitly declare it in a 'throws' clause in the method header or enclose our code in a 'try-catch' construct. Otherwise there would be a compilation error.
b) if new contents are appended, or overwritten(ie the previous contents of file are erased)
[Clarification] Clarified above.
Best wishes,
Balu
Example Program
---------------
import java.io.*;
public class CreateFile
{
public static void main(String args[])
{
try
{
File f1 = new File("TextFile1.txt"); //creates a new file instance
File f2 = new File("TextFile2.txt"); //creates a new file instance

System.out.println("Created a new empty file TextFile1.txt "+f1.createNewFile());
System.out.println("Created a new empty file TextFile2.txt "+f1.createNewFile());
// createNewFile creates a new file and returns 'true' if the file
// is not existing. If the specified file is already existing, this
// method returns false and does not create any file. That means that
// the existing file (if any) remains untouched.

FileOutputStream fos = new FileOutputStream(f1);// FileOutputStream is a byte stream.
byte b[] = {1,2,3,4,5};
fos.write(b); // results in overwriting the original contents of the file
// with some bytes.
fos.close();

FileWriter fw = new FileWriter(f2);
char ch[] = {'a','b','c','d'};
fw.write(ch);//FileWriter is a character stream
fw.close();

}
catch(IOException ioe)
{
System.out.println("Exception while writing to TextFile.txt "+ioe);
}
}
}
Hi Marthi,
An overview and FAQ about what is new in the new SCJP test pattern is given at:
http://suned.sun.com/USA/certification/java_news_faq.html
Cheers,
Balu
Hi,
The following excerpts from Section# 8.6.7 of the Java Language Specification explains us about the signature of the default constructor:
If a class contains no constructor declarations, then a default constructor that takes no parameters is automatically provided:
1.If the class being declared is the primordial class Object, then the default constructor has an empty body.
2. Otherwise, the default constructor takes no parameters and simply invokes the superclass constructor with no arguments.
3. If the class is declared public, then the default constructor is implicitly given the access modifier public (�6.6); otherwise, the default constructor has the default access implied by no access modifier.
Hope this answers your query.
Cheers,
Balu
Hi,
Chapter 14 of the Thinking In Java book gives an excellent coverage on Threads.
You can download a free electronic copy of the book from www.bruceeckel.com.
Cheers,
Balu
Hi:
I think the answer for your question is 'b' (After line 8). Immediately after line# 8, the 'anObj' reference has been assigned 'null', making the 'anObj' eligible for garbage collection.
Cheers,
Balu
Hi Anil:
Visited the site mentioned by you and found it very interesting and useful.
Could you please send me your tutorial to me. My mail address is kallavib@hotmail.com.
Cheers,
Balu