Is it necessary to create a Java class everytime?

I am starting to learn the Java programming language and I am a little confused.

I would like to create a simple program like adding two numbers or calculate the sum of n numbers. I can do this in C or Python easily, but in Java, I have to create a class for my program and then create a main class and call my program from it.

I use both Netbeans and IntelliJ.

Can I just create the program directly the way I do it in other languages? I mean is the concept of a class necessary in Java?

Jon Skeet
people
quotationmark

Can I just create the program directly the way I do it in other languages?

No.

I mean is the concept of class necessary in Java?

Yes. Every method, field etc is always in a class (or interface). Yes, that's an overhead for tiny programs - but for larger programs, the impact is pretty tiny.

As ever, use the right tool for the job - if you want a script of a few lines, use a scripting language. If you want more structure and organization, then you should expect a bit of "ceremony" to go with that.

people

See more on this question at Stackoverflow