I know this is an old question, but I think this question is important in order to clarify something. Let's look at these definitions:
Java is a class-based, general-purpose programming language, object-oriented, and designed to have as few implementation dependencies as possible.
C is a universal imperative computer programming language that supports structured programming, the scope of lexical variables and recursion, and a static type system prevents unintended operations.
Python is an interpreted, high-level, general-purpose programming language. It supports several programming paradigms, including procedural, object-oriented, and functional programming.
What is a programming paradigm?
Well, is it a programming style or just thinking about software development. This concept does not apply to a specific language, but to a method of programming, a methodology.
Now let's dive into the programming paradigms we found in the following definitions:
Python supports procedural programming (PP). PP is a programming paradigm based on structured programming based on the concept of a procedure call. PP is also known as embedded programming, which uses a top-down approach. Thus, this paradigm is to write a list of instructions that tell the computer what to do step by step. It is based on procedures, which are also known as routines, routines or functions, simply contain a series of computational steps that must be completed.
Java only supports Object Oriented Programming (OOP). The focus is on encapsulating data and behavior in objects. The OOP application will use a collection of objects that know how to perform certain actions and how to interact with other elements of the application. For example, an object may be human. This person will have a name (this will be a property of the object), and he will know how to walk (this will be a method). A method in OOP can be considered as a procedure in PP, but here it belongs to a specific object. Another important aspect of OOP is classes. A class can be considered as a project for an object.
C supports Structural Programming (SP). SP, sometimes called modular programming, is a method developed to improve the reliability and clarity of programs. In SP, program flow control is limited to three structures, such as sequences, selections ( IF / THEN / ELSE ), and repetitions ( FOR / WHILE ), or a structure derived from a combination of the main three. The result is a program built from modules that are very independent of each other. This provides the logical structure of a written program to make it more efficient, as well as easier to understand and change.
What does it mean?
As follows from this simple definition, Java is a programming language based on classes and objects . Therefore, when you asked: โCan I just create the program directly, how do I do it in other languages?โ, The answer was NO, because it is part of the definition of the language.
Why can C and Python do this?
Well, this is because C * and ** Python support non-member functions, while Java only supports member functions.
What is the difference between a member function and a non-member function?
In fact, a function that is not a member is always defined outside the class. Although a member function should be defined as part of the class. This means that this function is a member of a particular class. Another difference between member functions and non-functions is how they are called (or called). To call a member function, you need a class object to access the function, but non-member functions can be called directly.
TL DR
Java needs a class to define a member function, such as main() because it only supports OOP. So, if you need a very minimal program, you can create a class using the main() method. Consider the following code segment:
public class MainClass { public static void main(String[] args) { System.out.print("Hello World!"); } }
This is the equivalent in C:
#include <stdio.h> int main() { printf("Hello, World!"); return 0; }