0

I know that JVM is written in c++ but my primary question is java being good language probably better than c and c++, what is the necessity of writing it in c++. Any specific reason? just to want to know it might help others while facing interview at least. please dont debate as this forum doesnt support. Please give me solid reasons. thank you.

Rajesh Acharya
  • 214
  • 2
  • 10
  • 3
    How can you pull yourself out of a swamp? You need some tool to help. Also you need some program to execute the bytecode... – Uwe Plonus Jun 28 '13 at 07:11
  • so you mean to say java is no longer independent language, it depends on c++ to execute its byte code? – Rajesh Acharya Jun 28 '13 at 07:14
  • "what is the necessity of writing it in c++" c++ was one of the programming languages that existed when writing the jvm – Marco Forberg Jun 28 '13 at 07:14
  • 3
    this post is full of opinions. – UmNyobe Jun 28 '13 at 07:14
  • @UmNyobe that's why i raised the appropriate flag ;) – Marco Forberg Jun 28 '13 at 07:15
  • but it can be upgraded to java is not it??when java was getting developed c++ was used to develop jvm but now java is well developed cant it use java itself to develop jvm atleast now? – Rajesh Acharya Jun 28 '13 at 07:15
  • why reinvent the wheel just for the sake of doing it with another tool? – Marco Forberg Jun 28 '13 at 07:16
  • not a good question to ask here. – drarkayl Jun 28 '13 at 07:16
  • Some low level things just need bootstrapping... would you write a graphics driver in c#? – vikingsteve Jun 28 '13 at 07:17
  • No all i am asking because when I tell my friends proudly that i am java developer what if they say "without our c++ you people cant run the program" i feel its shame.. sun has to change the c++ to java.. – Rajesh Acharya Jun 28 '13 at 07:18
  • i dont consider that this is bad question not because i posted it, because most of us good in posting their problem while they come across coding but very few people worry about its architecture.. – Rajesh Acharya Jun 28 '13 at 07:19
  • 1
    While this question has many opinions in its subtext, the fundamental question is quite objective. I do not think this deserves to be closed – Karthik T Jun 28 '13 at 07:21
  • 1
    The problem is: there is no problem – Marco Forberg Jun 28 '13 at 07:21
  • @RajeshAcharya you can use any language that can be compiled to the target system to create a VM with it. You could also use Assembler. C++ was only chosen arbitarily. – Uwe Plonus Jun 28 '13 at 07:22
  • Thank you karthik. I am not here to post some crap questions to stackoverflow and waste the space of it..i just want to know the truth. – Rajesh Acharya Jun 28 '13 at 07:22
  • 1
    to get back to your original question: Java is run in a jvm. If you wanted to write that jvm in Java you would need to have a jvm to actually run the jvm... oh wait... – Marco Forberg Jun 28 '13 at 07:24
  • 1
    @RajeshAcharya interesting mirror of your question http://stackoverflow.com/questions/2279229/how-can-a-jvm-be-written-in-java – Karthik T Jun 28 '13 at 07:24
  • why someone down voted my question?give me reason. this is the first question i posted in this website – Rajesh Acharya Jun 28 '13 at 07:25
  • 2
    @RajeshAcharya As you can see in the message below the comments section. We prefer questions and answers which are objective and not opinionated. Statements like "Java is better than C++ " tend do inspire a lot of debates and arguements and are as such discouraged here – Karthik T Jun 28 '13 at 07:31
  • thats true bro..but i am not degrading c++ here, since this is java section and i am being java developer i want my language to be a independent one. I dont like it to be depending on other language. it really hurts me to see the down voting for my first question on first day of my life with stackoverflow – Rajesh Acharya Jun 28 '13 at 08:40
  • @RajeshAcharya I understand, it can be discouraging, and the people behind this site are trying to fix that. But you just need to understand that this is a question/answer site and not a forum, thus we prefer questions with a clear cut answer, and not just pure discussions/debates. I do maintain that your question does have substance in it, but you can understand I think what prompted the original reaction to close it. I have voted to reopen it, though I wouldnt want to raise your hopes too much. It would be nice though if you could reword the question to be more objective. – Karthik T Jun 28 '13 at 10:02
  • @KarthikT i edited it to some extent. thank you alteast u understood my intention....but my aim is to have not even single down voting was just collapsed..anyway no bad feelings.. – Rajesh Acharya Jun 28 '13 at 10:17
  • @RajeshAcharya `please dont debate as this forum doesnt support. Please give me solid reasons` is no rewording of the question, nor does it help to prevent those things. Also your intention to ask this question is your shame because of your friend? In the end you have to write to the creators of the JVM and ask why they have chosen C++ over anything else. Your question will only attract answers like "LOL C++ IS SOO MUCH FASTER THAN JAVA ROFL" (apparently that's the discussion you had with your friend), which is not a good fit for stackoverflow. – Thomas Jungblut Jun 28 '13 at 10:36
  • nice...i understand...thank you stackoverflow...may be this forum is not for ppl who wants to learn. – Rajesh Acharya Jun 28 '13 at 11:26

2 Answers2

7

Java code needs the JVM to execute. However C++ is compiled into machine code, so it is executed more or less by the hardware.

Thus you can see that to write the JVM using java, would mean that you need a JVM to run the JVM... hence not possible..

This is the same with most if not all interpreted languages. They are written in C / C++. Typically C since that was more stable when the language was taking shape (e.g perl), and also because it is seen as being more light weight and faster (?) than C++.

Karthik T
  • 31,456
  • 5
  • 68
  • 87
  • this was straight answer..very nice explanation..especially this line was good enough to convince me.. "you need a JVM to run the JVM... ". thank you bro. – Rajesh Acharya Jun 28 '13 at 12:00
3

When going from the design of a language X to the implementation, one thing is sure : you don't have access to language X tools because they don't exists yet. You need to use language Y.Now once you have language X running you can say you completely switch implementation from Y to X. But there is a cost : You are written a new software which should behave exactly like an old one. If the benefits outweighs the costs, then it can be a viable option.

UmNyobe
  • 22,539
  • 9
  • 61
  • 90