#!/bin/sh
cat << "EOF"
Here is some text, embedded
"right in the middle"
of my Bourne shell script.
EOF
Having been a standard feature in the Unix shells for decades, this language structure is supported in many newer languages, such as Ruby. Python, PHP and Perl. But not Java. In Java, this program would look like:System.out.println("Here is some text, embedded\n" +
" \"right in the middle\"\n" +
"of my Java program.\n");
As you can see, the quoting and escaping required to reproduce this text is pretty ugly.Wouldn't it be nice if we could do this kind of thing in Java too? It would be great for things like XML and Unit Tests. How did we get to 2010 without having this as a standard language feature? Has it ever come up in a JSR? I haven't had much luck in digging up any information (the term "here document" is remarkably hard to search on.) If you know something about this, please leave a comment.

C# has support for string literals (see here: msdn.microsoft.com/en-us/library/aa691090%28VS.71%29.aspx).
ReplyDeleteSo, it shouldn't be a big deal to port into Java.
These literals work mostly OK apart from when you have double-quote characters. Then you have to escape them as "".
So, your example above would become:
Console.Out.WriteLine(@"Here is some text, embedded
""right in the middle""
of my C# program.
");
When I bought my computer and I didn´t know how to use java graphics, so I decided looking for information in a webside and I found an useful information that helped me a lot.. Now I am interested in to do the best investment and I found a webside very useful and interesting called costa rica investment opportunities , I think it´s a very wonderful site.
ReplyDeleteI'm writing a program that needs to glue together chunks of pre-specified HTML, with the way it glues them together depending on a state variable. If Java had a JSP (Java Server Pages) compiler that could translate JSP notation to Java, then I could write each chunk as a separate JSP file, compile it to a class or method, and refer to that in my glueing code. That would be almost as good as here-documents: perhaps better, because the glueing code wouldn't get clogged up with large pieces of verbatim text.
ReplyDeleteSo I suggest that a stand-alone JSP-to-Java compiler would be a good substitute for Java here-documents.
I am not really sure about the original content of the post.
ReplyDeleteIt would be great for things like XML and Unit Tests.
ReplyDeleteActually I have very poor knowledge about it but I can say this blog is really good and awesome.
ReplyDeleteThis is a handy way of embedded string literals that would normally have to be escaped right...
ReplyDeleteXML and Unit test are seriously taken in its own way..It would be better if you give the best effort.
ReplyDeleteThis is a handy way of embedded string literals, HCG Blue Drops, the Faster and Natural way to lose weight...
ReplyDeleteThanks for the amazing article here. I was searching for something like that for quite a long time and at last I have found it here. Your blog is better than others because of useful and meaningful posts. Keep posting them in the future too, I will be waiting for thatWe have many brand
ReplyDeletenatural supplements
thanks for the code . It will work for me in another way . thanks for share.
ReplyDeleteIt would be great for things like XML and Unit Tests.
ReplyDeleteIt would be great for things like XML and Unit Tests. How did we get to 2010 without having this as a standard language feature?
ReplyDeleteThis language structure is supported in many newer languages, such as Ruby. Python, PHP and Perl.
ReplyDeleteThis is great for sharing this parts o JAVA programming
ReplyDelete