Really need ur answer and advice


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: Really need ur answer and advice

  1. #1
    Join Date
    Oct 2002
    Posts
    2

    Really need ur answer and advice

    Hie!! I am just a new learner of Java... I have some qustion that i would like to ask u guys
    Probably this is just some stupid question but pls help me ..Thanks alot

    1) May I know why are objects such as JTextField being declared as "final"?? What are the use of it?? what are the consequences of doing so?

    2) I am not really clear about the topic of "Files and Streams" after reading the book named Deitel & Deitel Java How to Program.... becoz i dun think the book give sufficient information on this subject. Can any 1 recommend me a book or some other source so that i can master this topic??

    Thanks alot!!!

  2. #2
    Join Date
    Oct 2002
    Posts
    66
    Ok, I am pretty new at Java. Started it a year ago when I started my Computer Science course in Uni and did some work for Sony in the Summer. I've not had much practice at GUI coding but have programmed since I was about 11 or 12 (about 7 or 8 years). So forgive me if this is incorrect anyway.

    1) I do not believe that you have to declare a JTextField as a constant (final). Looking at an example piece of coursework (I got 6/7) my declaration is:

    private JTextField txtKey;

    And is later referred to using:

    txtKey = new JTextField("1");

    2) Again, on the topic of files and streams, I'm not EXACTLY sure of this, but I'll do my best. I believe that the reason that you must open a file and then send it into a stream before using the data is because the stream will input or output the data in pieces. This is something to do with if you have large pieces of data, then it ensures that it will be transferred correctly. I've just finished writing some of this stuff for my coursework:

    Code:
    	private static Vector fileReader(String fileName) {
    		Vector output = new Vector();
    
    		try {
    			FileReader file = new FileReader(fileName);
    			BufferedReader reader = new BufferedReader(file);
    
    			String stringLine;
    
    			while((stringLine = reader.readLine()) != null) {
    				output.add(stringLine);
    				stringLine = new String();
    			}
    
    			reader.close();
    
    			return output;
    		} catch(Exception e) {
    			System.out.println("-- Decryption.fileReader() -> " + e);
    			return output;
    		}
    	}
    
    	private static void fileWriter(String fileName, Vector input) {
    		try {
    			FileWriter file = new FileWriter(fileName);
    			PrintWriter writer = new PrintWriter(file);
    
    			System.out.println(input.size());
    
    			Enumeration enumerate = input.elements();
    			while (enumerate.hasMoreElements()) {
    				writer.println((String) enumerate.nextElement());
    			}
    
    			writer.close();
    		} catch(Exception e) {
    			System.out.println("-- Decryption.fileWriter() -> " + e);
    		}
    	}
    That will let you used the following to open a file and copy it to a different file using:

    fileWriter("first.txt", fileReader("second.txt"));

    Obviously, that has little use. So my program will manipulate the data in between. In case you're interested I'm writing a decryption program.

    Hope this helps!
    Meethoss

  3. #3
    Join Date
    Oct 2002
    Posts
    2
    Thanks for ur help pal!!!! I appreciate ur answer!!

  4. #4
    Join Date
    Oct 2002
    Posts
    66
    That's no problem at all
    Meethoss

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center