Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


a question to girionis

Posted on 2003-03-12
Medium Priority
Last Modified: 2011-08-18

hi i have a client server application.
in the server side i have two buttons(3 textfileds), and on the client side have just 4 textfileds
to recive data from server.

the problem is that i can't get the data on the other side by pressing the check button(second one)!!!

here is the code from the server program:

public void actionPerformed(ActionEvent e) {
   if(e.getSource() == send){ // send is a button
       if(e.getSource() ==  check){ //check is a button

the first 3 lines sent (when send button pressed) should be displayed in three textfields(result1,result2,result3) and its working well.
the forth line sent (when the check button pressed) should be displayed in the checkResult in the client GUI which is not working.

here is the client codes witch display those lines:

 s = new Socket("", 1024);
 br = new BufferedReader(new InputStreamReader(s.getInputStream()));
       ps = new PrintWriter(s.getOutputStream(), true);      
       line = new String(); // Line to be read from the server
       line2 = new String(); // another Line to be read from the server
       line3 = new String();// another Line to be read from the server

// While there is more data coming... // this is working well when send button pressed!
while ( (line = br.readLine()) != null &&
(line2 = br.readLine()) != null &&
(line3 = br.readLine()) != null)
    // putting the incomming line from the
    // server into the result fields.
  line4 = new String(); // here is the problem why it can't display data into checkResult field when the check button pressed?!!
   while ( (line4 = br.readLine()) != null){


catch(IOException iExc){}

hope its clear.

Question by:Sharabi
  • 2
LVL 35

Accepted Solution

girionis earned 75 total points
ID: 8126876
 Are you sure that the value you assign at line4 is not null?

  And a performance tip for you. When you initialize Strings always do it with String line = ""; and not String line = new String(); since the latter for each time you do it it creates a new String and consumes memory, while the former as many times as you do it it assigns the same meory location (so you save memory) :-). So the following:

  String line1 = new String();
  String line2 = new String();
  String line3 = new String();

  will consume 3 different memory locations while the following:

  String line1 = "";
  String line2 = "";
  String line3 = "";

  will only consume one memory location and all three instances of String (lien1, line2, line3) will point to the same.
LVL 35

Expert Comment

ID: 8127132
 So what was the problem?

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses
Course of the Month15 days, 21 hours left to enroll

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question