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 6963341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:46:38+00:00 2026-05-27T15:46:38+00:00

My output is [B@b42cbf with no errors. It should be a string that says

  • 0

My output is “[B@b42cbf” with no errors.

It should be a string that says “Server Check”.

How do I fix my code to put out the string rather than the address?

My code to print the object has been changed several times, but is now as follows.

System.out.println(packet.getMessage().toString());

My packet class is as follows.

import java.io.Serializable;

public class Packet implements Serializable {

    final public short MESSAGE = 0;
    final public short COMMAND = 1;

    private String _ip;
    private short _type;
    private String _source;
    private String _destination;
    private byte[] _message;


    public Packet(String ip, short type, String source, String destination,
            byte[] message) {
        this._ip = ip;
        this._type = type;
        this._source = source;
        this._destination = destination;
        this._message = message;
    }

    public String getIP() {
        return this._ip;
    }

    public Short getType() {
        return this._type;
    }

    public String getSource() {
        return this._source;
    }

    public String getDestination() {
        return this._destination;
    }

    public byte[] getMessage() {
        return this._message;
    }
}

I Send the packet though an ObjectOutputStream and recieve it in an ObjectInputStream. The object is covereted to a packet with (Packet). You can see how this works as follows.

public void sendPacket(Packet packet) throws NoConnection {
        if (this._isConnected) {
            try {
                this._oos.writeObject(packet);
                this._oos.flush();  // Makes packet send
            } catch (Exception e) {
                e.printStackTrace();
                this._isConnected = false;
                throw new NoConnection("No notification of disconnection...");
            }
        } else {
            throw new NoConnection("No connection...");
        }
    }

Here is the listener.

@Override
    public void run() {
        try {
            this._ois = new ObjectInputStream(this._socket.getInputStream());
            Packet packet = (Packet) this._ois.readObject();
            this._listener.addPacket(packet);
        } catch(Exception e) {
            e.printStackTrace();
        }
    }
  • 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-27T15:46:39+00:00Added an answer on May 27, 2026 at 3:46 pm

    [B@b42cbf is what you get when you print a byte array, i.e. binary data.

    To get a String from that, you need to know the encoding, and then you can do:

    String messageStr = new String(packet.getMessage(), "UTF-8");
    

    Of course, that only works if that data is actually printable data.

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

Sidebar

Related Questions

Output 1 2 null 2 Code class Program { static void Main(String[] args) {
The output from the following code is incorrect. It should only output the leaves
The output from the code that follows is: java.vendor Sun Microsystems Inc. java.version 1.6.0_26
The output we get when printing C++ sources from Eclipse is rather ugly. Is
My output windows is full of The thread 0xe48 has exited with code 0
//output is 01234 00000 but the output should be or what I want it
Getting output with Java is pretty easy as you can make use of System.out.print
The output from the following code is 123 because substring takes from beginIndex to
The output of this code looks pretty much identical in FF, Chrome and Safari
The output from a SQL Server trace in profiler contains the columns CPU and

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.