Hemza
asked

Expert
Kelish Rai answered
You're right that in JavaScript, there's not much difference between using single quotes (' ') and double quotes (" "), as both are used to define strings.
But in Java, there's an important distinction:
Single quotes are used for single characters — this data type is called
char.Double quotes are used for strings, which can contain multiple characters.
Here's an example:
// Single character using single quotes
char letter = 'A';
// A string of characters using double quotes
String word = "Hello";If you try to store multiple characters inside single quotes like this:
char letter = 'Hello'; // This will cause an errorJava will throw an error because char can only hold a single character, not a sequence.
In short,
charis meant for a single character (like'A','b','5', or'@').Stringis meant for text that can have one or many characters (like"Hello","123","Good morning").
Java
This question was asked as part of the Learn Java Basics course.





