From the course: Programming Foundations: Fundamentals

Unlock this course with a free trial

Join today to access over 25,300 courses taught by industry experts.

Variables across languages

Variables across languages

- Depending on the programming language that you're working with, variables can behave in different ways. Some languages require that you define your variables and their types before you can use them, like Java, C#, and C++. For example, if we want to store the name of a cookie in Java, we would have to first declare that it's going to be of type string and then give our variable a name, cookie. When we run this code, we get sugar as our output. Since we've defined our variable as type string, we can't then later decide to set this variable to a different type. Let's say an integer. When we compile our program, we'll receive an error because Java is a strict programming language. It doesn't allow you to reassign data types in this way. But if we were to compare this to a more relaxed language like Python, we don't need to declare a variable's type before using it. Here, we declare the variable and use it at the same…

Contents