Differences between Java and LuaU Programming Languages

I would like to know what the differences are between Java and Roblox Lua.

I wanted to know this because I am learning Java right now for my robotics club as I will have to be the head of software soon because our experienced lead is leaving.

I know that there are some things that you can do in Java that you can’t do in Luau, and vice versa, but just tell me what you can if you have experience in both languages.

Also, if this is in the wrong category please inform me.

2 Likes

Why can’t you just search this online?

I would like to know from people with experience.

I son’t have too much experience in Java, so take my words with less seriousness.

The main difference is classes. Roblox comes with prebuilt classes, and already uses OOP. Lua is also meant to be lightweight, while Java was meant to be a more functional language. On the other hand, Lua allows for more readable code, and is easier for a beginner to pick up.

Hope this helped!

3 Likes

I’d switch those around, no way I’d describe Lua as using OOP and Java as being functional. Java is all about classes and objects, and the only objects you have in Roblox are the ones Roblox has made for you. Anything else, and you need to make your own OOP system. Lua doesn’t have that built in.

3 Likes

Sorry, I meant Luau. The heritage and object system is OOP, is it not?

Yes that doesn’t have anything to do with Luau. Luau doesn’t implement OOP.

Lua has no native object oriented support although metamethods and other similar tools are able to simulate OOP, hence why the paradigm is “technically” supported.

Here’s an example.

If I wanted to make a class in Java:

public class Foo {

   String name = "Bar";
   int amount = 5; 

}

Vs in Lua:

local Foo = {}
Foo.__index = Foo

function Foo.new()
   local self = setmetatable({
      name = "Bar";
      amount = 5;
   },Foo)
   return self
end
1 Like

Well there is a big difference between java and lua. Roblox has a built classes that is called by us, but in general Lua is again just a light weight High Level Language. Which means that Lua cannot run with any OS. But on the other hand Java is a stand-lone language. It used to program games, program bots, and more. On syntax, I would say java is better because it more “customizable” you can extend classes, create a constructor, and more.

As a small java programmer myself, there is a huge difference.

Lua = Easy to read and write. (for some)
Java = Kind of difficult to read and write. (for some)

There are also differences in how things are written. For instance, you need a local to define a variable in Lua, while in Python you don’t.

Java is compiled and static, while Lua is interpreted and dynamic (unless you are using luau with type-checking, then it is static too). Lua is multiparadigm so you can program in any way you want (for example, I personally avoid OOP in Lua), meanwhile, Java forces you to use OOP. Lua is extremely lightweight and fast while java is ridiculously big, full of libraries and features you never use.

They both are good languages for they propose, Java is mostly used for enterprise software and android apps, and Lua is mostly used as a quick way to implement a scripting tool in everything. Practically, there’s nothing you can’t do in Lua that you can in Java and vice versa, technically there obviously are, but if you know the nature of programming (and the way that your language works) that is the least of your problems.

Also, I don’t think one is easier than other, both require a lot of time to master. In fact, I picked up Lua after years of using Java, and at first sight it looked to me as a bunch of incomprehensible locals and ipairs, so also I don’t think one is easier to read than the other.

That’s not right, Java compiles bytecode in a JAR, you then need the JVM to run it. In fact, Lua apps are way more easy to distribute as standalone since the thing only weights a couple thousand kilobytes, meanwhile my JDK8 weight around 200MB.

4 Likes

Like I said I meant Roblox. The other statements were true about Lua, but yeah, I know it doesn’t come by default with OOP.

Java is a compiled language, Lua is an interpreted scripting language built for embedding into other applications. Java is a statically typed language, Lus uses dynamic typing. Lua is very simple and light-weight, Java is more complex. Array indices in Lua start with 1, not with 0 as in Java .

1 Like

If you’re talking about writing the code itself and the syntax, the differences are the OOP as others said,
1. For every variable or function (method in class), you have to define what type it is or what type it returns, you can’t just write local or etc.
You can also use Object for most of the things instead of the type but I won’t suggest that.
2. For normal arrays, you have to define the length and you can’t change it, but there are other solutions for that, they also start with 0 and not 1
3. You can’t make dictionaries (“Make the index a string”) AFAIK.
And the code only runs in the Main method.
4. You also can’t create functions in other functions.
5. Instead of ends you use {}
6. Every action (if not a container like functions etc.) ends with a semicolon ;
7. Comments start with // and not –
8. You can also decide what variables and functions you want to make available from other classes. The standart today AFAIK is instead of making the variables accessible, you add getters and setters (method that set the variable’s value or get it) in order for clients or others to not see how the class is originally built and the variables themselves are private (can only use them in the class itself).
Examples:
Sum up 2 and 4:
Lua:

function sum(num1,num2)
    return num1+num2
end)
local result = sum(2,4)
print(result ) --print

About the same code in Java:

package comparison;


public class Comparison {

    public static void main(String[] args) { //Only what's inside here will actually run
        int sum = sum(2,4);
        System.out.println(sum); //print
    }
    public static int sum(int num1, int num2) {
        return num1+num2;
    }
}

Also as others above me said, Java’s syntax is usually longer (e.g. instead of print(), System.out.println())

As someone who started with Java years ago, I want to make some notes:

True, but we almost always use Lists, arrays are mostly used for lower-level stuff like buffers of just static collections.

Not true, Java has plenty of Map classes Map (Java Platform SE 8 )

1 Like

Oh, I never heard of that, thanks for letting me know :slightly_smiling_face: . I started only about a year ago.

1 Like

@ZelqDev @rodeldev Java is as much of a compiled language as LuaU is. They both run a VM which executes precompiled bytecode, so this distinction is wrong.

@Ashp116 Lua is also platform independent since it runs in a VM just like Java.

I know and I’ve myself shipped entire commercial (standalone) games with precompiled Lua bytecode. I think I didn’t make it clear, but I made that distinction based on the normal use (cause nearly all Lua projects I found are distributed as source code, meanwhile Java is only (commercially) distributed as jars), and also based on the Roblox and LuaU nature, which (at least from the user perspective) it is distributed as source code, then compiled at runtime.

I have some doubts 1. what’s difference between LuaU and Lua? 2. Is Java and JavaScript same?
In your opinion what languages should I learn?

1 Like

Luau is derived from Lua. It was made to be easy to work with for developers using it for scripting on the roblox platform.

Java and JavaScript are not the same at all, despite the name. Java is an object-oriented programming language used in programming many different applications. JavaScript is what makes most websites on the internet interactive. Google it to learn more.

2 Likes