java practice part 1

Today about how to handle java easily write.

In addition, I will write on the assumption that the JDK that was posted the other day is over.

Basic procedure

Since java is a little more time-consuming code than ruby I will write the procedure.

  1. Create a .java file and write the jaca code 2, Create a class file with the above file with the javac command 3, execute the class file.

This is a simple flow. Even if you write the basic code, you have to compile it and create a class file Since java cannot be used, it is converted to a class file with the javac command.

Basic format

First, I will write the basic format. The preparatory code is quite long compared to other languages.

Basic format.java


class file name (class name){
   public static void main(String[] args){
(Processing content)
  } 
}

Click here for an example

HelloJava.java


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

Now the command to output Hello! Is issued.

Creating class files

Next, create a class file that corresponds to the executable file.

Terminal


javac java filename.java

As an example

Terminal


javac HelloJava.java

HelloJava.class is now created.

File execution

Then run the class file. Run the HelloJava.class used in the example.

Terminal


java class file name

Terminal


 java HelloJava

This will output Hello !.

Name notes

There are some precautions such as making the names the same.

Make the file name and class name the same

There is a Java convention that file names and class names must be the same.

Be aware of uppercase and lowercase letters

Also, because Java recognizes uppercase and lowercase letters, "Class sample" and "Class Sample" are treated as different things.

Recommended Posts

java practice part 1
Scraping practice using Java ②
Java8 Stream API practice
Scraping practice using Java ①
Studying Java ~ Part 8 ~ Cast
45 Java Performance Optimization Techniques (Part 1)
[Java] Practice of exception handling [Exception]
Apache Hadoop and Java 9 (Part 1)
Java
Java
Java Servlet / JSP Request Scope Part 1
Java to learn with ramen [Part 1]
Java Servlet / JSP Request Scope Part 2
Basic usage of java Optional Part 1
Server processing with Java (Introduction part.1)
[Practice! ] Java database linkage (Connector / J 8.0.20)
Creating lexical analysis in Java 8 (Part 2)
GAE / Java8 trial (Part 6: "Deployment failure")
Creating lexical analysis in Java 8 (Part 1)
Studying Java ―― 3
[Java] array
Java protected
[Java] Annotation
[Java] Module
Java array
Kotlin Class part.2 to send to Java developers
Studying Java ―― 9
[Practice] ArrayList
Java scratch scratch
Java tips, tips
Array practice
Java methods
Java method
java (constructor)
Java array
[Java] ArrayDeque
java (override)
java (method)
Java Day 2018
Java string
java (array)
Java static
Java serialization
java beginner 4
Call GitHub API from Java Socket API part2
JAVA paid
Introduction to swift practice output Chapter 5 Part 2
Studying Java ―― 4
java shellsort
[Java] compareTo
java reflexes
java (interface)
[Practice] ArrayList
Java memorandum
☾ Java / Collection
Java array
Studying Java ―― 1
[Java] Array
[Java] Polymorphism
Java review
java framework