Announcement

Collapse
No announcement yet.

Java or Javascript?

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Java or Javascript?

    Before asking this question, I want to just clarify the differences between java and javascript as far as I know.

    Java
    Spoiler:
    • every variable must be clarified by what type of variable it is (Integer, String, etc.)
    • Methods, Arrays, etc. are very picky on what type of object they will take as parameters.
    • Variables must be categorized using the words public, static, private, final, etc.
    • A variable cannot be accessed by another class unless it is static.
    • Static variables cannot be manipulated by other classes
    • Functions can return values, but the value it returns has to be a certain type of variable (the type you declared it as) For example:
      Code:
      public boolean test() {
      return 1;
      }
      would not be possible. It would have to be:
      Code:
      public int test() {
      return 1;
      }

    That's all that I know for sure, but there is probably a lot more.

    Javascript
    Spoiler:
    • Variables do not have to be specified by type. In fact, one variable can transfer from an integer to a string with ease.
    • Since variables do not have specific types, functions, arrays, and other things can take any parameter at any time without causing an error (it might crash upon running, but it doesn't cause an error immediately.)
    • Variables do not have to be categorized at all and they can still be accessed and edited from anywhere in your programs.
    • Functions can return any value at any time. since variables do not have to be specified, you could have a function return a string or an integer within the same group of code. For example:
      Code:
      var test = function() {
          if(isTest) {
          return 1;
          }
          else {
          return "could not perform test";
          }
      }

      As far as I know, that is impossible in Java.
    • Javascript uses files instead of classes, interfaces, etc., which makes it much simpler to use.

    That's all that I know for sure, but there is probably a lot more.


    So, which one do you like best? Open the spoiler to see my preference
    Spoiler:

    Pros
    I like Javascript better due to simplicity. I don't have to categorize my variables, I don't have to set a specific type for my variable, and I don't have to worry about value interferences.

    For example, I was doing some minecraft modding, and I wanted to put blocks into an array for a method to use. The method took the object type "Block", so I made the array type "Block". But when I added the blocks into the array, an error came that said: "Cannot convert from Block to Blocks". I then changed the array type "Blocks", and another error said: "Cannot convert from Blocks to Block". Changing the array type to "Object" fixed the array, but when trying to put it into a method, it didn't work because the method required an object type "Block" instead of "Object". So I had to work around that typing about 3 times the amount of code that was needed, all because of that array.
    Cons
    Due to this simplicity, though, your code can get disorganized faster, and it doesn't catch as many errors.

    For example, I had a simple program that would subtract the player's health by a projectile's damage, but the player's health kept coming out as "NaN". It turns out that I had misspelled projectileDamage inside of the projectile object, so the projectile damage was returning "Undefined" because that variable technically didn't exist. And since you cannot subtract a number by "undefined", the player's health got set to "NaN", and the player immediately died. Java would have caught an error like that.
    The bloonchipper is the best.
    http://forums.ninjakiwi.com/forum/ju...7143#post77143

    My profile picture
    http://i.imgur.com/z7wCGHX.jpg
Working...
X