Java programming (classes and instances, main methods)

Main method

Java always consists of classes. The process is written in the method in the class. In the method, the original operation and processing are written in the method called the main method.

How to write the main method

The main method is written as follows. Let's name the class Test class according to the naming rule.

public class Test(){
  public void main(String[] args){
*Contents of main method processing
*The original operation is written here.


public static void main(String[] args)

Please remember how to write. By the way, static between public and static is called a static clause and is attached to a method or variable. The detailed meaning is not mentioned here.

It seems that there is a meaning and it became such a rule, but I think that it is not necessary to pursue it so much. However, please understand that it is a normal method writing method.

Use class

Now, let's use the MultipleIntegerNumber method of the Calculate class in the main method of this Test class. This method

public class Calculate {
 public int multipleIntegerNumber(int num){
  num = 3*num;
  return num; 



To use a class, first instantiate the class.

Calculate cal1 = new Calculate();

This cal1 is called an instance.

Method call

Then call the method.


That way, the method will return a return value of 9 as a result.

Recommended Posts

Java programming (classes and instances, main methods)
java (classes and instances)
[Java] Generics classes and generics methods
Java abstract methods and classes
Java generics (defines classes and methods)
Classes and instances Java for beginners
Classes and instances
JAVA learning history abstract classes and methods
[Ruby] Classes and instances
java classes, instances, objects
About classes and instances
Ruby classes and instances
[Java] Personal summary of classes and methods (basic)
(Note) Java classes / variables / methods
Java programming (variables and data)
Java classes and instances to understand in the figure
About classes and instances (evolution)
Consideration about classes and instances
Java methods and method overloads
[Ruby] Singular methods and singular classes
About Ruby classes and instances
Ruby methods and classes (basic)
Creating Ruby classes and instances
[Ruby] Singular methods and singular classes
[For beginners] Explanation of classes, instances, and statics in Java
About Java static and non-static methods
Writing code with classes and instances
Organize classes, instances, and instance variables
Studying Java 8 (StaticIF and Default methods)
Java methods
Java methods
Memorandum (Ruby: Basic Grammar: Classes and Instances)
Java programming (static clauses and "class variables")
Write code using Ruby classes and instances
[Java ~ Classes and External Libraries ~] Study Memo (6)
Getting Started with Java_Chapter 8_About Instances and Classes
Java class methods
I compared classes and instances with worldly things
Effective Java 3rd Edition Chapter 4 Classes and Interfaces
java programming basics
Differences in writing Java, C # and Javascript classes
[Processing x Java] Data type and object-oriented programming
Functions and methods
Kantai Collection Java # 1 Classes and Objects [For Beginners]
Check static and public behavior in Java methods
java Generic Programming
Java and JavaScript
XXE and Java
How to access Java Private methods and fields
About the difference between classes and instances in Ruby
Equivalence comparison of Java wrapper classes and primitive types
Constraint programming in Java
Getters and setters (Java)
[Java] Thread and Runnable
HashMap and HashSet classes
Java true and false
String literals and instances
[Java] String comparison and && and ||
[Java] About anonymous classes
Java programming basics practice-array
Java programming (class method)