English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

the features of java are mentioned as
strongly typed and no unsafe constructs

will any of you please tell me what does that mean?

2007-02-08 19:31:14 · 2 answers · asked by Moony 2 in Computers & Internet Programming & Design

2 answers

Strongly Typed:
Similar to what the other answerer said, but different.
If you declare a variable as an int, the variable will always be an int. If you try to put a String in this variable, the compiler should report this as an error and not allow compilation of your code.
In the same way, if you make a variable a String, you cannot assign to it any other type of variable, like a double.

The Typed part means the variable TYPE, not type as in typing on the keyboard.

No Unsafe Constructs:
In c and c++ and earlier languages you can write a piece of data in memory at any place. This can cause you operating system (os) to stop working if you just wrote the piece of data over some piece of code the os needs. You os will not understand the data you just wrote and will either stop, or give an infamous 'blue screen [of death]'.
There are other ways that a lazy, or inexperienced programmer can manipulate programs [or pieces of memory] that the program they are controlling does not own. Once again, this could overwrite a piece of the os code, code from another open program, or even the code for the program itself. All of this will result in unknown behaviour, as the inputs are not was is expected.

Memory management is also a known 'black spot' for inexperienced, or lazy programmers. In c, c++ and earlier languages, you have to allocate the required memory that your program will use. Some languages allow this memory to be allocated dynamically [when the program needs it], whereas some languages require you to allocate all the memory the program will use when it is running.

Sometimes, the memory is not deallocated, and results in what is known as 'memory leak'. The memory is still held by the program and is not free for other programs to use, even though your program is no longer running.

Therefore, Java has done away with pointers and memory management. These are the main things [as everyone says] that [can] cause trouble.

Another thing that you can do in c and c++ is to reference an array not only by the 'variable[number]' way, but by the 'number[variable]' way. This is/was a cause of misunderstandings, and Java only allows the 'variable[number]' way of referencing an array.

2007-02-10 20:15:11 · answer #1 · answered by Mark aka jack573 7 · 0 0

Strongly typed, then take Visual Basic as comparison: you can declare a variable x in both languages, but with Java you had to declare beforehand x is used only in holding text, with VB you can dispense this requirement, a result of that, x can hold "1" both as text and as 1 as a number, this small difference probably is not going to kill anything as of yet, but consider x in Java can hold only "text" that's all. While in VB x can be used to hold "text" or even something more complicated, like a program reference, in which totally different manipulation functions are supposed to apply to it. Then there's no way in VB to clear what x is suppose to be nor what action can be applied. With Java there is no such issue because x is only explicitly told to hold "text".

That's sorta an unsafe construct, but another issue is targeted squarely at how C/C++ works, union, pointer arithmetic, bits, optional syntax all gotta go.

2007-02-09 04:04:18 · answer #2 · answered by Andy T 7 · 0 0

fedest.com, questions and answers