• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • Carey Brown
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • fred rosenberger
  • salvin francis

How come Java doesn't need 'prototype' like JS does?

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I understand every major OOP principle in Java, so I thought that learning JS would be piece of cake. But then I came across term called prototype in JS which troubles me. Can someone tell me how Java doesn't need prototypes unlike JS? What are prototypes replaced by in Java and how can I picture it from Java's perspective so I can understand it better in JS?
 
Marshal
Posts: 73257
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You wouldn't use English skills as a guide to learning Japanese, You would learn Japanese anew. Similarly, forget all about Java® when learning JS; the similarlity between the names is misleading.
Even the name JS is not quite correct; nobody ever uses the correct name for the language, which is ECMAScript. You haven't heard that name because nobody says ECMAScript.
 
author & internet detective
Posts: 40677
827
Eclipse IDE VI Editor Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Java has type safety and doesn't let you add methods at runtime so prototype doesn't apply. You aren't going to be able to understand it from a Java perspective.
 
Sheriff
Posts: 67553
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JavaScript's prototype is its means to effect inheritance. Java has classes. It's like asking why a steam engine doesn't need gasoline - different mechanisms to achieve a similar goal.
'
"But wait!" you say "JavaScript now has classes!" Well, sort of -- it's all just syntactic sugar on top of the `prototype` mechanisms.

 
Bear Bibeault
Sheriff
Posts: 67553
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And to Campbell's point: yes, knowing Java is a detriment towards learning JavaScript properly -- especially modern JS.
 
Campbell Ritchie
Marshal
Posts: 73257
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:. . . why a steam engine doesn't need gasoline . . .

Nice to see you again, Bear
Nice analogy. Can I be naughty and change it to, “why a steam engine doesn't have spark plugs.” Or even, “why a petrol (=gasoline) engine doesn't have a boiler.”
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic