<p><strong>PHP has a <a href="http://php.net/var_dump" rel="noreferrer">var_dump()</a> function which outputs the internal contents of an object, showing an object's type and content.</strong></p>

<p>For example:</p>

<pre><code>class Person {
  private $firstName;
  private $lastName;

  public function __construct($firstName, $lastName) {
    $this-&gt;firstName = $firstName;
    $this-&gt;lastName = $lastName;
  }
}

$person = new Person('Jon', 'Smith');
var_dump($person);
</code></pre>

<p>will output:</p>

<pre><code>object(Person)#1 (2) {
  ["firstName:private"]=&gt;
  string(3) "Jon"
  ["lastName:private"]=&gt;
  string(5) "Smith"
}
</code></pre>

<p><strong>What is the equivalent in Java that will do the same?</strong></p>

It is not quite as baked-in in Java, so you don't get this for free.
It is done with convention rather than language constructs.  In all data transfer classes (and maybe even
in all classes you write...
), you should implement a sensible
```
toString
```
method.  So here you need to override
```
toString()
```
in your
```
Person
```
class and return the desired state.
There are
utilities available
that help with writing a good toString method, or most IDEs have an automatic
```
toString()
```
writing shortcut.