[Introduction to Java] How to write a Java program

I'm a fledgling programmer for the first year. This is a collection of personal notes that have been organized and published for review purposes. Please note that there is a high possibility that you are wrong.

Hello World!

public class Main{
    public static void main(String[] args){
        System.out.println("Hello World!");
    }
}

--Just output the string "Hello World!". It is called "the most famous program in the world". ――At first, remember that you write it like this.

Basic structure of Java program

public class Main{
	public static void main(String[] args){
		//Write the process to be executed here
	}
}

--The structure is that the class is on the outside and the method is on the inside. --Basically, write in order from the outside to the inside

How to write a comment

//Comment here

/*
Comment here
*/

--/ // is recognized as a comment and is not processed as a program -The part surrounded by / \ * and \ * / is also recognized as a comment (multiple lines are possible)

The contents of the method

Roughly speaking, the contents of the method are the following four.

  1. Statement declaring a variable
  2. Statement to calculate
  3. Statement that executes the instruction
  4. Control statements (if statements, for statements, etc.)
public void sample(){
	//declare
	String message = "";
	int numberA = 1;
	int numberB = 3;
	int bumberC = 0;

	//calculate
	numberC = numberA + numberB; 
	
	//Control what to do
	if( numberC > 2 ){
		//Substitute (a type of calculation)
		message = "numberC is greater than 2";;
	}
	
	//Execute the instruction
	System.out.println(message);
}

Recommended Posts

[Introduction to Java] How to write a Java program
How to write java comments
To write a user-oriented program (1)
java: How to write a generic type list [Note]
Studying Java # 6 (How to write blocks)
How to make a Java container
[Java] How to create a folder
How to write a ternary operator
How to write Java variable declaration
How to make a Java array
Basics of Java development ~ How to write a program (flow and conditional branching) ~
[Java] Introduction to Java
Introduction to java
[Basic] How to write a Dockerfile Self-learning ②
[Java] How to output and write files!
[Java] How to measure program execution time
How to make a Discord bot (Java)
How to print a Java Word document
[SpringBoot] How to write a controller test
How to write dockerfile
How to write docker-compose
How to write Mockito
How to write migrationfile
Introduction to java command
Rails: How to write a rake task nicely
[Java] How to use Thread.sleep to pause the program
[Rails] How to write when making a subquery
Java Development Basics ~ How to Write Programs * Exercise 1 ~
How to display a web page in Java
How to convert a solidity contract to a Java contract class
[Java] Memo on how to write the source
How to write Java String # getBytes in Kotlin?
[Java] How to use Map
How to create a Java environment in just 3 seconds
How to lower java version
[Java] How to use Map
How to uninstall Java 8 (Mac)
How to write good code
How to jump from Eclipse Java to a SQL file
How to write Scala from the perspective of Java
[Java] Types of comments and how to write them
How to write a unit test for Spring Boot 2
How to use java Optional
Bit Tetris (how to write)
[Java] How to play rock-paper-scissors (equivalent to paiza rank A)
How to minimize Java images
How to leave a comment
[Refactoring] How to write routing
How to use java class
[Java] How to use Optional ②
How to create a data URI (base64) in Java
[Java] How to use removeAll ()
[Java] How to display Wingdings
Great poor (how to write)
[Java] How to get a request by HTTP communication
[Java] Introduction to lambda expressions
How to launch another command in a Ruby program
[Java] How to use string.format
[Note] How to write Dockerfile/docker-compose.yml
How to use Java Map
How to write a date comparison search in Rails