Escape Characters in Java

public class Main {
public static void main(String[] args) {
String alex = new String ("My name is Alex. I'm 20!");
}
}
public class Main {
public static void main(String[] args) {
String myFavoriteBook = new String ("My favorite book is "Twilight" by Stephanie Meyer");
}
}
public static void main(String[] args) {
String myFavoriteBook = new String ("My favorite book is \"Twilight\" by Stephanie Meyer");
System.out.println(myFavoriteBook);
}
}
public class Main {
public static void main(String[] args) {
String workFiles= new String ("My work files are in D:\Work Projects\java");
System.out.println(workFiles);
}
}
public class Main {   public static void main(String[] args) {       String workFiles= new String ("My work files are in D:\\Work Projects\\java");
System.out.println(workFiles);
}
}
  • \t - tab.
  • \b - backspace (a step backward in the text or deletion of a single character).
  • \n - new line.
  • \r - carriage return. ()
  • \f - form feed.
  • \' single quote.
  • \" double quote.
  • \\ backslash.
public class Main {
public static void main(String[] args) {
String byron = new String ("She walks in beauty, like the night, \nOf cloudless climes and starry skies\nAnd all that's best of dark and bright\nMeet in her aspect and her eyes...");
System.out.println(byron);
}
}

Escape Unicode characters

public class Main {
public static void main(String[] args) {
System.out.println("\"Escaping characters\", \u00A9 2020 KajalRawal");
}
}
And that about sums it up! Now you know enough about escaping characters to use this great tool in your work :)

--

--

--

Programming isn’t about what you know; it’s about what you can figure out.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

RESTful API

FileMaker Help: A Worthwhile Read

Laravel View Composer duplicating SQL queries for every view bind. How it runs once?

Options to Animate in Flutter

One restaurant that has always done it right is Bareburger. If you don’t live in

Debunking 5 Myths About Coding

AZURE KUBERNETES SERVICES(AKS)

OpenHack 2019 👨‍💻: 48hrs Collaborative hackathon Summary

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Kajal Rawal

Kajal Rawal

Programming isn’t about what you know; it’s about what you can figure out.

More from Medium

Basics of Java

Encapsulation in Java

Introduction to Java Basics

JAVA OOPS and IO