• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Henry Wong
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Joe Ess
  • salvin francis

velmurugan notes (arrays)

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you are right.
e.g.
String[] a = {"abc", "cde"};
Then 3 objects are created.
 
kamal jaisingh
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thx a lot for ur prompt reply
i got it
regards
KAmal
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Without deviation from the norm, progress is not possible - Zappa. Tiny ad:
Sauce Labs - World's Largest Continuous Testing Cloud for Websites and Mobile Apps
https://coderanch.com/t/722574/Sauce-Labs-World-Largest-Continuous
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!