r/learnjava • • May 10 '21

Can one create a video game in Java only?

What I mean is: can one create a video game or graphic application without the use of external software like SceneBuilder, or libraries like JavaFX?

I’ve seen a guy recreate Minecraft using only coding in C, and I feel like, if you know enough of any powerful language like Java, you can do anything you want, at your own customs, without the need of pre-existing tools, and it may be easier once you are at that level.

57 Upvotes

42 comments sorted by

84

u/DigitalTorture May 10 '21

Minecraft was written in java, so yeah you can.

12

u/yurzav May 10 '21

Only java?

19

u/DigitalTorture May 10 '21

I cant honestly say for sure.

Edit: it was programmed in pure java at first.

5

u/carrdinal-dnb May 11 '21

It was written in Java using OpenGL wrapper libraries

2

u/JacobJMountain May 11 '21

IIRC it used LWJGL

-31

u/elyca98 May 10 '21

Well yeah, but it would answer my question if I knew Notch didn’t use any external tool. Which he probably didn’t.

19

u/ColetBrunel May 10 '21

Actually, he used a thirdparty gaming lib. Which is made in C, not Java.

Still, it's possible to use Java-only, but cumbersome and unlikely to amount to good framerates. If you were to make a professional game, no way you'll get decent framerates. At least, before JavaFX and I imagine there was little incentive to provide something for that with JavaFX.

1

u/elyca98 May 10 '21

Oh, may I ask another question then? How do you manage a decent framerate in a video game? Does using different languages for the whole project help, so they don't step on each other?

10

u/Fletsky May 10 '21

Well it's not about using one language or more.

There are many factors, that can impact the software performance.
- The computational complexity, of used algoritms is one of main factors, whatever language you will use.
- Using lower level languages like C/C++, that give you a lot more control over code, system and hardware, that allows using certain "cheats" and optimizations. They also doesn't need the JVM that Java uses, and it also saves some resources.

You can develop your own, engine, and necesary libraries in Java only, but I would argue, that it is better aproach, even if you know what are you doing.

The libraries included in Java, are usualy optimized by a lot of programmers, and they are adapted to fit certain tasks. I'm not saying that single programmer cannot write something better, it's just hard to do and unlikly.

It is indeed great exercise to write things from scratch, but for real world applications it is usualy not the best aproach.

3

u/JasburyCS May 10 '21

I’ll add on to other answers.

You want performance to be as deterministic as possible. One barrier to this is garbage collection. Garbage collection takes enough time to run that it’s noticeable in high performance situations like graphics frame rates. This is one of many reasons why graphics libraries prefer C++ over languages like Java

1

u/hugthemachines May 11 '21

There are many games made in Unity, though. Aren't they using GC?

1

u/JasburyCS May 11 '21

The answer to that gets a little complicated.

Unity’s game engine is still C++ as well. Game objects and scripts are written by users in C# and can be utilized by the C++ engine. C# alone is garbage collected but C++ is not. Unity does a lot of memory management tricks and techniques to make everything as efficient as possible.

2

u/ColetBrunel May 10 '21 edited May 10 '21

You make use of the graphics cards. Nowadays graphics cards' microprocessors are worse monsters than main computer microprocessors are.

Java doesn't provide an API that enables to make use of the graphics cards in any meaningful way.

Which leads us to another aspect of your question I guess: Java, by nature, and it's more its assets than a flaw of it, is a very locked in technology. In Java only, you cannot do anything that Java provided APIs doesn't allow you do to.

Java is fully capable as a Turing Machine, but a modern computer is about a lot more than just computing an output sequence of data from an input sequence of data. To do anything useful with a computer, you need to communicate with its devices. With its operating system too. And Java doesn't provide any syntax to do that. The only way you could do it, would be through APIs provided with Java, which do it with parts that aren't in Java.

Other languages don't provide any syntax for that either, with the exception of assembly. But, some of them like C, can link fairly with assembly. Like they code functions and call functions in a way that works very well with assembly.

As for assembly, its principle is to use the micrpoprocessor's instructions. Some of these instructions allow to trigger communication with the devices or the system.

That's how it's out of reach from programming languages as they don't have a syntax that enable these triggers, but languages that link well with assembly, are fairly close to have access to these triggers. But Java, that works as a completely fictional machine, is very locked from such accesses, and can only use these things through the bridges offered by the JVM.

1

u/nutrecht May 11 '21

Does using different languages for the whole project help, so they don't step on each other?

That makes no sense whatsoever. So no.

0

u/jjrobinson-github May 10 '21

to get good framerates you likely need to code against a 3d library that handles the low level (C) implementation against common graphics hardware (directX etc). No one does a purely graphical X in one language for this reason.

27

u/AHistoricalFigure May 10 '21

You certainly could, but it would be a lot of work and there are much easier options. Because if you're not willing to use other people's tools or libraries you're going to have to build your own.

If you want to get into games development my suggestion would be to jump into the Unity Junior Programmer class offered for free through Unity Learn. The Java > C# transition is one of the easiest in programming.

9

u/elyca98 May 10 '21

Then I prefer to stay in Java for a time and be confident enough to do the jump. Thanks.

7

u/kiwidog8 May 10 '21

If you're asking if it can be done, well, literally everything running on a computer, phone, or game console (which are all computers) is just code underneath, so of course you can. Once you get more experience programming you start to realize that all programming languages are quite similar, the only reason why different languages exist is because they fill different niches (syntactically, stylistically, being more geared to one type of program, or have a focus on being easy to use and understand, etc.) but they all have the capacity to do the exact same things, it's just a matter of picking the language that does that one thing better or meets your needs as a developer. For most general purpose languages there are no limits, if you can imagine it, you can build it.

Now if you're asking if you should attempt to write a video game from scratch without using third party libraries and tools, then no, unless you're doing it strictly to learn/educate yourself. In the real world the majority of developers never build something without the use of libraries and tools without a good reason to. Don't reinvent the wheel and all of that, you know?

3

u/elyca98 May 10 '21

Thank you so much. This has made my third eye quiver a bit. Specially that last part.

16

u/[deleted] May 10 '21

RuneScape private servers are written pretty much solely in Java, so yeah. To it’s core, it’s client-server-cache work and all you do is map out the streams with the headers and make sure your packets are being used

-14

u/mikezyisra May 10 '21

Emulators dont count i think

7

u/[deleted] May 10 '21

It’s not an emulator.

7

u/HecknChonker May 10 '21

Java AWT (Abstract Windowing Toolkit) lets you create a canvas that you can draw shapes or images to.

I haven't used it myself since college when I did a few projects like tetris, and it worked well. I don't know how well it supports 3d or if it allows you to utilize a GPU.

https://docs.oracle.com/javase/7/docs/api/java/awt/package-summary.html

6

u/recursiveG May 10 '21

Libgdx is the most popular Java game engine I believe.

1

u/Acid-free_Paper May 11 '21

It's just a framework, not an engine.

3

u/smm_h May 11 '21

What's the difference in your opinion

2

u/carrdinal-dnb May 11 '21

I’d say engines are more fully featured freeing the developer up to focus on creating their game, whereas a framework is more a set of tools you can configure to get what you want but you’ll probably spend more time fiddling around with things.

3

u/Gustafssonz May 10 '21

Starsector, prob one of the best games I have ever played are written in Java.

1

u/[deleted] May 11 '21

That's very true. I love it!

3

u/snot3353 May 10 '21

Yes, there are plenty of established and high quality game frameworks in almost every language. If Java is the language you’re most comfortable with then go check out LibGDX.

3

u/MHREone May 11 '21

I had to make a game only with javafx for uni. It was a horrible experience. Don't do it.

5

u/Dexteroid May 10 '21 edited May 10 '21

You can but why would you want to ?

Edit: I don't want to deter you from learning something but my point is that there are better tools available for game Dev. Example : c# and unity.

4

u/extraicy May 10 '21

Old school RuneScape is a Java game

2

u/strikefreedompilot May 10 '21

My friend made a playable good looking (for that time period) streetfighter and tetris type clones 20 years ago.

2

u/makingthematrix May 11 '21

Take a look at FXGL, video game engine built on top of JavaFX: https://github.com/AlmasB/FXGL

And libGDX, another game engine: https://libgdx.com/

2

u/[deleted] May 11 '21 edited May 11 '21

This is a link to ThinMatrix's game dev log on YouTube (it's 125 videos). This is start to finish, ground up development of Equilinox which is currently on Steam.

Everything was built with Java, so yes, it is possible, and he shows you how.

2

u/nutrecht May 11 '21

People are answering your question but not the questio behind the question.

You should not avoid using external libraries when you're programming in Java. Sure it has a learning curve, but you need to get over it anyway.

For simple 2D games (start with stuff like tick tack toe or minesweeper) you can just use 'plain' Java + Swing. If you want to do 3D stuff you're going to end up using an external library, like for example Minecraft does.

1

u/mplaczek99 May 11 '21

It'll be hell, but in theory, its possible

1

u/[deleted] May 11 '21

If you want to learn making games using Java here are the channels TheCherno, NewBoston on YouTube. These are the channels I'm learning java game programming from.

6

u/AutoModerator May 11 '21

Please, don't recommend/use thenewboston.

They are a discouraged resource as they teach questionable practice. They don't adhere to commonly accepted standards, such as the Java Code Conventions, use horrible variable naming ("bucky" is under no circumstances a proper variable name), and in general don't teach proper practices, plus their "just do it now, I'll explain why later" approach is really bad.

Derek Banas covers about the same ground, but in much better quality.

If you're looking for an in-depth, comprehensive, high quality, free Java course, use the MOOC Object Oriented Programming with Java from the University of Helsinki and maybe Java for Complete Beginners by John Purcell as secondary resource.

I am a bot and this message was triggered by you mentioning thenewboston. Please do not respond to this comment as I will not be able to reply.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

3

u/[deleted] May 11 '21

Good bot

0

u/asterik-x May 11 '21

Yes!! Whenever , im on vacations to Java, i do create a couple of video games in Java only. I do not cross the boundary of the island till i have coded all the game.