How to use toString Method in Java Tutorial using NetBeans

how to use tostring method in java tutorial

How to use toString Method in Java Tutorial using NetBeans

This tutorial is all about How to use how to use tostring method Tutorial using Net beans.In this tutorial you will learn how to use toString method in java, toString method in java is very useful when it comes to converting, and it allows you to convert int to string. It can also be use in date format.

If you want to represent any object as a string, toString() method comes into existence.

The toString() method returns the string representation of the object.

If you print any object, java compiler internally invokes the toString() method on the object. So overriding the toString() method, returns the desired output, it can be the state of an object etc. depends on your implementation.

Please follow all the steps below to complete this tutorial.


How to use toString Method in Java Tutorial using NetBeans steps


Create your project by clicking file at the top of your project and then click new project, you can name your project whatever you want. After that you create a class by right clicking the source packages and new java class. You can name your class whatever you want.

Then copy paste the code below


public class ToStringDemo {


private int month;

private int day;

private int year;


public  ToStringDemo(int m , int d , int y){

month = m;

day = y;

year = y;


System.out.printf(“My birthday is %s\n”,this);



public String toString () {

return String.format (“%d/%d/%d”, month, day, year);


public static void main (String [] args) {

ToStringDemo object = new ToStringDemo (2, 22, 1996);






Then you’re done. Run your project and see if it works.

About How To Use toString Method In Java

Project Name: How To Use toString Method
Language/s Used: JAVA
Database: None
Type: Desktop Application
Updates: 0
How To Use To String Method In Java– Project Information

For questions or any other concerns or thesis/capstone creation with documentation, you can contact me through the following:

E-Mail: [email protected]


Contact No.: +639098911050

Ryan A. Salem

BSIT Graduate, soon to be MIT.

Java Developer / System Developer

Related topic(s) that you make like:

1.) Clear Textfield element in java
2.) How to use Keyword Static in Java using Netbeans IDE



Leave a Comment