What exactly is public class?

Hey, Im fairly new and Im wondering what the public class that starts a program is. The tutorial for Java was understandable but it didnt explain what exactly is public class. Public class is used in every program and it doesnt start without it. Ive also see random. (something) that may be similar to public class? Is public class simply just what your file is named?

1 Like

public class basically has two parts;

public meaning anyone on a system or network can access the file (private is also an option, but for beginners use public)

class meaning the type of file java needs for the computer to understand the code. Basically the code you write is stored in a .java file. In the browser something called a compiler is built into the “run” button. In other IDE’s or text editors you can download often times they have you compile the code first (which effictively saves it as a .java wherever on your computer) and then you can run it.

When you run the compiler (not the program), Java takes the code and turns it into a .class file. Which contains a bunch of gibberish you can’t understand. Then something called the Java Virtual Machine (or JVM) takes the .class file and reads it to the computer so it can understand what you wrote.

This occurs when you run it.

So a class is essentially a special file type that Java uses. You can type anything after “class” and it will use that as your class name.

Hope this helps. If it’s a bit too advanced just message me directly.