Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6608239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:35:19+00:00 2026-05-25T19:35:19+00:00

I am looking at example in the example in Walter Savitch book Java Introduction

  • 0

I am looking at example in the example in Walter Savitch book “Java Introduction”

// This method does not do what we want it to do.
public static void openFile(String fileName,
    PrintWriter stream) throws FileNotFoundException
{
    stream = new PrintWriter(fileName);
}

PrintWriter toFile = null;
try
{
    openFile("data.txt", toFile);
}

Author gives explanation, which does not make any sense, as to why toFile = null after try

Thanks !

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T19:35:19+00:00Added an answer on May 25, 2026 at 7:35 pm

    You need to read that section of the book more deeply. (I’m sure that it actually DOES make sense … but you just haven’t understood it yet.)

    It is clear that the author is actually trying to illustrate an very important aspect of Java … how parameters are passed.

    Specifically, he is trying to illustrate that the two stream identifiers are for different variables, and that the assignment inside the method

    stream = new PrintWriter(fileName);
    

    does NOT effect the stream variable declared just before the try. The value that is assigned to the stream variable inside the method gets lost.

    This illustrates that Java uses “pass by value” as its parameter passing mechanism. (If you need to get a value back from a method call, the simple way to do it is to return it.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

looking at this example of the jquery ui slider http://jqueryui.com/demos/slider/#steps i want to be
I am looking at an example online that contains this code in objective-c -(void)dealloc
Looking for an example or documentation links as to how to implement a method
I am looking for an example which does a file upload with a progress
I'm looking for an example, how to implement a longpoling mechanism in java. I
I am looking for an example that I can solve using Finite Element Method
I was looking at example code from the O'Reilly book on Ruby on Rails
I was looking at Example 2 on this msdn page about Thread synchronization with
Looking at an example on image upload with JQuery here: http://www.zurb.com/playground/ajax_upload Using this example
I am looking for example Java code that can construct an XML document that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.