Welcome to the Treehouse Community
Looking to learn something new?
David Smith10,577 Points
In Java's variable declaration deep dive.
When declaring a variable in Java you declare the type before the variable name however in a language like Python or Ruby you would simply declare the name and then put something inside of it.
My questions are, why do we do this in Java? and what advantages/disadvantages does it have to declare the type first?
Steven Parker215,939 Points
Java is an example of a statically-typed language, in which type checking is done at compile-time; whereas Python is a dynamically-typed language in which type checking is done at run-time.
Advantages commonly cited of statically-typed languages:
- Better code completion.
- Better performance (more opportunities for compiler optimizations).
- Easier for IDE's to provide hints and documentation while you code.
- It’s easier for the IDE to find where things are declared and referenced in the code.
- It's easier to work with relational databases and other systems which also rely on static types .
- It can help reduce the likelihood of some kinds of errors.