Here Document in Java

Posted on 2009-07-05
Last Modified: 2012-05-07

Regarding the "here document,"  I was wondering if there was an equivalent way to do this in a high-level language like Java? I haven't been successful finding anything as of yet. I have included an example of a Perl script here document below:

print <<EOHeader;

You will be prompted for your name and other information. Please give complete answers to each question. To return to the menu without making an entry type q [Enter].


This output everything between the EOHeader tags without having to use four or five print commands.

Thank you.
Question by:shogun5
LVL 16

Accepted Solution

Peter Kwan earned 500 total points
ID: 24783218
Java does not support such syntax. However, you may use StringBuffer as an alternative way like this:

StringBuffer sb = new StringBuffer();

sb.append("\n").append("You will be prompted for your name and other information. Please give complete answers to each question. To return to the menu without making an entry type q [Enter].").append("\n");


Open in new window


Author Closing Comment

ID: 31599972
Thank you!

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
maven archtype selection in eclipse 1 53
upcasting down casting object remains same but refernece changes 8 60
countHi challenge 25 101
mapAB Challlenge 35 128
There is an easy way, in .NET, to centralize the treatment of all unexpected errors. First of all, instead of launching the application directly in a Form, you need first to write a Sub called Main, in a module. Then, set the Startup Object to th…
Windows Script Host (WSH) has been part of Windows since Windows NT4. Windows Script Host provides architecture for building dynamic scripts that consist of a core object model, scripting hosts, and scripting engines. The key components of Window…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

863 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

Need Help in Real-Time?

Connect with top rated Experts

28 Experts available now in Live!

Get 1:1 Help Now