aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes velmurugan notes (arrays) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "velmurugan notes (arrays)" Watch "velmurugan notes (arrays)" New topic
Author

velmurugan notes (arrays)

kamal jaisingh
Ranch Hand

Joined: Feb 23, 2001
Posts: 39
i read in velmurugan notes abt arrays ,
tht when an array of 5 Strings is created , total 6 objects
r created.
i am a little confused on this point.
is it tht 5 String objects and 1 array object is created , ie
6 objects???
can anyone xplain is this right , or theres somthin else to
this

regards
Kamal
Wong KK
Ranch Hand

Joined: Jan 15, 2001
Posts: 52
Yes, you are right.
e.g.
String[] a = {"abc", "cde"};
Then 3 objects are created.
kamal jaisingh
Ranch Hand

Joined: Feb 23, 2001
Posts: 39
thx a lot for ur prompt reply
i got it
regards
KAmal
Indika Perera
Greenhorn

Joined: Feb 28, 2001
Posts: 8
hi, another doubt from same set of Notes.
Following is from Chapter 15 of Velmurugan's notes.
* Reader contains these methods for reading characters and arrays of characters:
abstract int read() throws IOException
int read(char cbuf[]) throws IOException
int read(char cbuf[], int offset, int length) throws IOException
InputStream defines the same methods but for reading bytes and arrays of bytes:
abstract int read() throws IOException
int read(byte cbuf[]) throws IOException
int read(byte cbuf[], int offset, int length) throws IOException
* Writer and OutputStream are similarly parallel. Writer defines these methods for writing characters and arrays of characters:
abstract int write(int c) throws IOException
int write(char cbuf[])throws IOException
int write(char cbuf[], int offset, int length) throws IOException
And OutputStream defines the same methods but for bytes:
abstract int write(int c) throws IOException
int write(byte cbuf[]) throws IOException
int write(byte cbuf[], int offset, int length) throws IOException

What I notice is , int read() in Reader is not abstract as per Java 1.2 source code, but int read (cbut[], offset, length) is abstract. Similarly for writer int write(int) not abstract but int write (cbuf[], offset, length)is.
Can somebody please clear my doubt.
niraj singh
Ranch Hand

Joined: Feb 07, 2001
Posts: 36
Hi
The Reader class is a superclass of the BufferedReader and other such classes. The read(char[] cbuff...) method is abstract in the Reader class, as it is just a template to be defined in a subclass where a buffer is implemented. The method is not abstract in the BufferedReader class. Same applies for InputStream and Writer classes.
Indika Perera
Greenhorn

Joined: Feb 28, 2001
Posts: 8
Hi Niraj,
Thanks for the response. I agree with what you're saying.
But, my doubts are whether, read() in Reader and write(int c) in Writer are abstract, as mentioned in above set of notes. I noticed that this is not correct, while going through java source code.
vkswamy venkatachalam
Greenhorn

Joined: Feb 18, 2001
Posts: 21
Hi,Indika
Reader is a public Abstract class for reading character streams. The only methods that a subclass must implement are read(char[], int, int) and close().
int read()
Read a single character.
int read(char[] cbuf)
Read characters into an array.
abstract int read(char[] cbuf, int off, int len)
Read characters into a portion of an array.
Writer is public abstract class which extends Object
for writing to character streams. The only methods that a subclass must implement are write(char[], int, int), flush(), and close().
void write(char[] cbuf)
Write an array of characters.
abstract void write(char[] cbuf, int off, int len)
Write a portion of an array of characters.
void write(int c)
Write a single character.
void write(String str)
Write a string.
void write(String str, int off, int len)
Write a portion of a string.
In short,read(char[] cbuf, int off, int len) in abstract Reader class and write(char[] cbuf, int off, int len) is absract in abstract writer class.Hope this will clear .
with regds,
vkswami.


vkswami
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: velmurugan notes (arrays)
 
Similar Threads
An object to hold several arrays
An array question
how many object created
Arrays in Java
How many objects created for array init