- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is Java String literal?
Strings, which are widely used in Java programming, are a sequence of characters. In Java programming language, strings are treated as objects. The Java platform provides the String class to create and manipulate strings.
You can also create a String directly as −
String greeting = "Hello world!";
A string literal should be enclosed in double quotes. Whenever it encounters a string literal in your code, the compiler creates a String object with its value in this case, "Hello world!'.
Example
public class StringDemo { public static void main(String args[]) { String str = "Hello world!"; System.out.println( str ); } }
Output
Hello world!
- Related Articles
- What is a string literal in C++?
- What is the difference between a String object and a String literal in Java?
- Why String literal is stored in String Constant Pool in Java?
- Is null a literal in Java?
- String Literal Vs String Object in C#
- Raw string literal in C++
- Raw string literal in C++ program
- What is 0 (zero) - A decimal literal or An octal literal in C++
- Hexadecimal integer literal in Java
- What is a function literal in JavaScript?
- How to define multiline String Literal in C#?
- What is Java String Class?
- How to use template string literal in ECMAScript 6?
- Hexadecimal literal of type long in Java
- Pattern LITERAL field in Java with examples

Advertisements