Java - what is the difference between String and text in programming?

1 points
Asked by:

I am learning programming, I picked java.
I know my question might sounds novice and weird, but anyway I ask what I don't understand.
Is String a line of text in file, or what is it in general?
How can I explain myself what is string in java?
I know it is data type and it represents text.
Can someone try to explain it in the easiest way possible with some easy examples.
How to understand it? And why do I need it?
Thank you

1 answer
6 points
Answered by:

You have 2 basic data types in programming:
- numbers
- letters

It is like if you want to talk with someone with messages over hangouts. You need to use letters and numbers to communicate with someone. It is the same in programming. If you want to dislay some message to the user you need to store this message in String data type.

You can type:

  • 123
  • I like java

123 - number type (integer)
I like java - those all letters are called String in all programming languages.

Code example:

public class SimpleProgram {

    public static void main(String[] args) {
        String messageToUser = "Hello, my name is Max, I learn Java.";


Output of this simple program:

Hello, my name is Max, I learn Java.

Entire sentence in English contains letters. So we can use this to explain what is String in easy English words. String is a sentence of words, or ever 1 character we call it String also. I don't want to explain it in harder way.

Just play for a while with java simple main and basic tutorials and you will get it under 5 days :D. I promise. If not just drop next question with resources you learn from or book you use. I can help and explain more.

String is a list of characters.

A character is 1 letter or 1 digit.

You can try to write down on the paper what you understand from this post and what you don't understand and create new question.

I really encourage you to do that.

Cheers and just keep going. 👍

0 comments Add comment
Native Advertising
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂