Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Regarding equating objects in Java

  1. #1
    Junior Member
    Join Date
    Feb 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Regarding equating objects in Java

    PrintWriter pw = response.getWriter();

    What actually we are doing here ?

    How can a object of PrintWriter class can be equated to a method called by response object of HttpServletResponse class ?

    Also I do not understand how different objects of different class are equated to each other ?

    For Example,

    import java.sql.*

    public class JDBCSample {

    public static void main( String args[]) {

    String connectionURL = "jdbc:postgresql://localhost:5432/movies;user=java;password=samples";
    // Change the connection string according to your db, ip, username and password

    try {

    // Load the Driver class.
    Class.forName("org.postgresql.Driver");
    // If you are using any other database then load the right driver here.

    //Create the connection using the static getConnection method
    Connection con = DriverManager.getConnection (connectionURL);
    //Create a Statement class to execute the SQL statement
    Statement stmt = con.createStatement();

    //Execute the SQL statement and get the results in a Resultset
    ResultSet rs = stmd.executeQuery("select moviename, releasedate from movies");

    // Iterate through the ResultSet, displaying two values
    // for each row using the getString method

    while (rs.next())
    System.out.println("Name= " + rs.getString("moviename") + " Date= " + rs.getString("releasedate");
    }
    catch (SQLException e) {
    e.printStackTrace();
    }
    catch (Exception e) {
    e.printStackTrace();
    }
    finally {
    // Close the connection
    con.close();
    }
    }
    }

    I have highlighted the problematic statement.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Regarding equating objects in Java

    PrintWriter pw = response.getWriter();

    What actually we are doing here ?
    The getWriter() method returns a reference to a PrinteWriter object that is assigned to the pw variable.

    how different objects of different class are equated to each other ?
    Read the API doc for the method to see what it returns.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. [Question] Objects instantiated within objects.
    By Xerosigma in forum Object Oriented Programming
    Replies: 6
    Last Post: April 25th, 2012, 10:53 AM
  2. New to Java: Arry of Objects
    By Jack Hammered in forum Collections and Generics
    Replies: 8
    Last Post: January 5th, 2012, 07:17 AM
  3. how to merge java objects with effective dates
    By java4ulok in forum What's Wrong With My Code?
    Replies: 4
    Last Post: June 10th, 2011, 01:24 PM
  4. java question on objects
    By joe98 in forum Threads
    Replies: 2
    Last Post: April 12th, 2011, 03:54 PM
  5. Java Sockets, Bytes / Objects
    By AdamD in forum Java Networking
    Replies: 1
    Last Post: January 31st, 2011, 03:25 PM