This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

strongly type ?  RSS feed

 
Chris Wox
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Java programming language is a strongly typed language ?

what does it mean ? can someone please clarify ?
 
krishna nav
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

In javascript u can create variables using "var"

ex: var a;

here variable "a" can hold char,int,float,etc so many types.

but in Java u need to declare type of variable before using it
& also u cannot directly assign variable of one type into another, u need to do casting.

 
Vijay Jagannathan
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out http://en.wikipedia.org/wiki/Programming_language

strong vs. weak typing

This distinction refers to the behavior of the language when values are operated on. In a strongly typed language, operations must match the types of the values operated on (addition must be performed on numbers, for example). In weakly typed languages operations might be made on values which are inappropriate.

Cheers.
 
Sanjaya Sugiarto
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Example of typical weak-type language is PHP (also many other script languages):

$variable_one="hallo";
$variable_two=10;
$variable_three=$variable_two+"15";
$variable_four=$variable_one+"20";
echo $variable_three; //will result 25, the string "15" will be automatically casted to integer
echo $variable_four; //will result 20, the interpreter is confused how to handle the string "hallo"

As you can see the weak-type language has its advantages and disadvantages:
Advantages:
1. easier for beginner
2. faster to develop

Disadvantages:
1. nightmare to debug (especially if it is a large app)
2. give more tolerance for failure or wrong understanding (which could lead to serious security issues)
3. Can be a source of memory/performance hog

This big tolerance for failure which could lead to disaster is also an argument why many say JEE or .Net(C#) is much more scalable than PHP or some other weak-type script languages.
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then there was the C programmer who thought that "strong typing" was when you pounded the keyboard
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by krishna nav:
Hi,

In javascript u can create variables using "var"

ex: var a;

here variable "a" can hold char,int,float,etc so many types.

but in Java u need to declare type of variable before using it
& also u cannot directly assign variable of one type into another, u need to do casting.


That's actually an example of *static* versus *dynamic* typing. JavaScript is dynamically typed, but I think also strongly typed, isn't it?
 
Daniel Lucas
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I think of java being a strongly typed language, I think of the fact that I have to type exactly what I want it to do; I can't leave anything up to the compiler to change on its own.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Daniel Lucas:
When I think of java being a strongly typed language, I think of the fact that I have to type exactly what I want it to do; I can't leave anything up to the compiler to change on its own.


Then you are actually thinking of the wrong thing.

Strong typing just refers to the fact that an object has a type, and that you get a runtime error when you are trying to do something with an object that its type doesn't support.

Static typing means that variables have types, too, and that you get a compile time error when you are trying to do something on a variable that its type doesn't support.

Manifest typing means that you have to actually explicitely declare the type of each variable.

Java is both strongly, statically and manifestly typed.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!