![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: May 2006
Posts: 3
Rep Power: 0
![]() |
Hello
This question might seem foolish, but I've been asked at an interview this and didn't know what to say I told them the part with the garbage collector but I didn't actually answer the question.So does anyone knows the answer? Thanks Ciprian |
|
|
|
|
|
#2 |
|
Newbie
Join Date: May 2006
Posts: 28
Rep Power: 0
![]() |
If I had to guess, it might be because they are different languages... wouldnt need any new languages if they were all the same would we?
|
|
|
|
|
|
#3 |
|
The Oblivious One
Join Date: May 2005
Location: Ontario, Canada
Posts: 648
Rep Power: 4
![]() |
The answer that I would provide is that Java encourages safety in operation. It will not let you do damage to the system. The use of pointers in C allows the programmer to get right down to the memory of computer, and therefore, if used incorrectly, the programmer might accidently cause problems (for example, calling free() on a previously free()ed pointer. )
Though, I think that would be an educated guess :p.
__________________
Dr. Zoidberg: [ecstatic] I'm going to a movie... with FRIENDS! |
|
|
|
|
|
#4 |
|
Professional Programmer
Join Date: Jan 2006
Location: Ontario, Canada
Posts: 380
Rep Power: 3
![]() |
I would have also said the garbage collecting.
__________________
I am Addicted to Linux! |
|
|
|
|
|
#5 |
|
Battle Programmer
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 770
Rep Power: 3
![]() |
Garbage collecting can be done in C. You can make your own GC and have it manage at least deletion, if not allocation. It's just not built into the language, nor is it guaranteed on the system you run on. Java, on the other hand, runs through the JVM, so I'm assuming that the GC takes advantage of that.
|
|
|
|
|
|
#6 |
|
Hobbyist Programmer
Join Date: Apr 2006
Posts: 136
Rep Power: 0
![]() |
It's a common misconception that Java has no pointers. It's not exactly true. Java has pointers, they're just not explicit. Every object is a reference to a location making it a pointer... you just can't manipulate the pointers directly.
Which approach is better.. explicit or not? Well, that very much depends on the context and scope of the application. I'm sure everyone who ever went through learning C will however agree that non-explicit pointers are sure as hell easier to comprehend for someone who is just learning programming. Here's why it's a pointer.. say you have two Strings s and t String message = "hi"; String text = "hello"; These are two separate objects in two different locations. text = message; Now text and message both reference the same location hence referencing the same object. That is a behavior of a pointer. |
|
|
|
|
|
#7 |
|
Newbie
Join Date: May 2006
Posts: 3
Rep Power: 0
![]() |
Thanks for your answers, guys. That's what I've told them myself, that Java was design to be safer and to manage the resources by itself. Like this you don't have to worry about erasing pointers, freeing the memory, about the so much dreaded memory leaks, so on and so forth. Not to mention the buffer overflow exploits. But apparently it's not enough. They were expecting another answer . An obvious answer, as they said. Any idea what the hell they were talking about? Since I came, I keep thinking about their question
![]() |
|
|
|
|
|
#8 |
|
Battle Programmer
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 770
Rep Power: 3
![]() |
Well, the memory management shouldn't be part of the answer. Memory management can be done in C. What Toro said might be part of it. Objects in Java have some pointer-ish behavior. The "erasing pointers, freeing the memory, about the so much dreaded memory leaks, so on and so forth" sounds like saying the same thing over and over. I don't know what they would have been expecting, though.
|
|
|
|
|
|
#9 |
|
Newbie
Join Date: May 2006
Posts: 3
Rep Power: 0
![]() |
Ok, again thanks for your answers.
|
|
|
|
|
|
#10 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
It's not really about what you can do with C, but what you can't do with Java. In Java, you can't, for example, increment a reference or change the memory address it's pointing to - it points to one thing, and that's it. Again, this is to do with safety - if the pointer's always pointing to something, you can't screw up.
Hopefully. :p |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|