Can I use java

Is it possible to use java programming to make a game in unity. If not then please add this feature.

No, but C# is syntactically very similar to Java. If you already know Java, you pretty much already know C# - it’s just a matter of learning it’s standard libraries.

4 Likes

No Java in Unity! Just a few speed bumps you will encounter learning C# from Java:

  • C# doesn’t have or need primitive type wrappers like Integer and Boolean. A List in C# is not only possible, but the backing array will actually be an int[ ] without boxing.
  • C# has Classes which behave a lot like Java classes, but it also has structs, which do not. Structs act more like primitive types in Java: they are pass-by-value and you can use them without calling a constructor.
  • Primitive types (called simple types in C#) are full fledged objects, meaning you can call methods on them. For example this is valid: string s = 2.ToString();
  • Maps are called Dictionaries!
  • Iterators are called Enumerators!
  • Interfaces use a kind of “Hungarian notation” by convention, where “I” is prepended to the interface name. For example: ICollection or IList.
  • TitleCase is the convention used for methods and properties instead of camelCase.
  • C# has a fleshed out property system. No more Getters/Setters
  • C#'s inheritance rules are a little different. In order to extend a method it has to be marked virtual first.
  • There is an override keyword instead of an @ Override annotation
  • Annotations use [AttributeSyntax] instead of @Annotation and are called “Attributes”
  • C# has goodies that were only more recently added to Java such as the “var” keyword
  • Packages are more or less replaced by Namespaces
  • Modules are more or less replaced by assemblies
  • No Diamond operator… but var keyword is there!
  • Streams API → LINQ
  • Maven → NuGet
  • Lots of other goodies: Extension Methods, Operator Overloading, Delegates, Events, Tuple types, null-coalescing operators, nullable types, out and ref parameters, etc…
2 Likes

What’s up with that? C# is part of the C++ family, which calls them hashmaps, or just maps. Python calls it a Dictionary. It’s almost as if C# picks terms to confuse people on purpose.

1 Like

While we are at it, I would prefer to program Unity in Fortran. How long will this take?

Just kidding. Some years ago Unity had UnityScript and Boo as scripting languages too. They had different feature sets and were a nightmare to maintain. So focussing on ONE programming/scripting language was a wise choice. So you can either learn C#, which should not be that hard, or you just stay with Java. No harm done with either choice.

I don’t think you understand the scope of this request.

1 Like

This simply won’t happen. Unity only somewhat recently finished removing every other language aside from C#. If you need to use Java for some odd reason then you need to choose a different game engine.

Java’s Map isn’t sorted which would make it a direct equivalent for C#'s Dictionary, but C++'s Map is sorted so the actual equivalent for it is C#'s SortedDictionary. I’d love to know the reasoning behind everyone’s choice of naming scheme but I suspect it’s just a case of getting a senior engineer that liked one approach more than the other.

Everything folks above wrote is correct: C# is what you want, and it is NOT hard to learn if you are actually versant in Java.

Source: I have used java and C# and I can assert this with confidence.

Also, friends don’t let friends use java.

Friends also don’t let friends use XML.

1 Like

But it comes down to Dictionary vs. Map as the base word, and Map was the natural choice. Calling it Dictionary is being weird on purpose.

But those terms work out well. C++ philosophy is to use the proper technical term if you can, and use the shorter word for the most common. So Map for the tree version, and HashMap for the hash-table one. Everyone knows trees are sorted. C# is about fun words and lack of technical detail, so Dictionary and SortedDictionary. C#'ers enjoy finding secrets, like how the one with the longer name is better in many cases. Meanwhile Python is just Dictionary, since in the time it takes to decide which one, your Python program could be all finshed.

I love Python. It’s dictionaries… all the way down…