is Java dynamically or statically typed language or both?

M

Michael Redlich

Hi puzzlecracker:
Is it different from c++ in this regard?

Java is statically typed because dynamically typed languages (such as
JavaScript and Visual Basic) allow you to write code like this:

var fred = "Fred";
//...
fred = 3.5;

This would obviously be illegal in Java and C++.

More details can be found at http://en.wikipedia.org/wiki/Data_type

Hope this helps...

Mike.
 
P

puzzlecracker

Michael said:
Hi puzzlecracker:


Java is statically typed because dynamically typed languages (such as
JavaScript and Visual Basic) allow you to write code like this:

var fred = "Fred";
//...
fred = 3.5;

This would obviously be illegal in Java and C++.

More details can be found at http://en.wikipedia.org/wiki/Data_type

Hope this helps...

Mike.


Thanks... that does it


Would an automatic registering of delegates make a language
dynamically typed?
 
E

egao1980

Java is strongly typed with some hole near collections (patched with
generics in java 5.0) but It is possible to write "dynamically
typed"-like code in Java - declare all variables as Object and use
reflection to call methods an do other things around ^_^ (similar to
Smalltalk but ugly in syntax)
 
M

Michael Redlich

Hi "egao1980":

Java is strongly typed with some hole near collections (patched with
generics in java 5.0) but It is possible to write "dynamically
typed"-like code in Java - declare all variables as Object and use
reflection to call methods an do other things around ^_^ (similar to
Smalltalk but ugly in syntax)

I hear what you're saying, but I still think there is a big difference
between declaring variables as type Object and variables in dynamically
typed (scripting) languages.

Type Object is still just that, a type. As you probably already know,
a cast is usually required to change over to a more specific type (like
iterating through a collection before Generics). Reflection, of
course, also deals with specific class types.

On the other hand, variables declared in a scripting language can be
dynamically assigned to another data type (like the example I gave
earlier in this thread) without the need for casting. But, one has to
wonder how all that magic happens in the background.

So, you bring up an interesting point.

Here's something for all of us to ponder for the new year...

Happy New Year!

Mike.

--- ACGNJ Java Users Group (http://www.javasig.org/)
 
M

Michael Redlich

Hi puzzlecracker:
Thanks... that does it


Would an automatic registering of delegates make a language
dynamically typed?

Can I assume that you are referring to C#?

I haven't made the plunge into the whole .NET thing, but I am aware of
the 'delegate' keyword. I did some surfing, and found the following
from Microsoft's MSDN page:

"A delegate declaration defines a reference type that can be used to
encapsulate a method with a specific signature. A delegate instance
encapsulates a static or an instance method. Delegates are roughly
similar to function pointers in C++; however, delegates are type-safe
and secure."

More details can be found at:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csref/html/vcrefTheDelegateType.asp

Hope this helps...

Happy New Year!

Mike.

--- ACGNJ Java Users Group (http://www.javasig.org/)
 
P

puzzlecracker

Michael said:
Hi puzzlecracker:


Can I assume that you are referring to C#?

I haven't made the plunge into the whole .NET thing, but I am aware of
the 'delegate' keyword. I did some surfing, and found the following
from Microsoft's MSDN page:

"A delegate declaration defines a reference type that can be used to
encapsulate a method with a specific signature. A delegate instance
encapsulates a static or an instance method. Delegates are roughly
similar to function pointers in C++; however, delegates are type-safe
and secure."

More details can be found at:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csref/html/vcrefTheDelegateType.asp

Hope this helps...

Happy New Year!

Mike.

--- ACGNJ Java Users Group (http://www.javasig.org/)


C# has but it also an implementation detail usually in adapter
pattern: you create a delegate which can be used to manipulate adaptee.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top