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.
Since java is a little more time-consuming code than ruby I will write the procedure.
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.
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.
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.
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 !.
There are some precautions such as making the names the same.
There is a Java convention that file names and class names must be the same.
Also, because Java recognizes uppercase and lowercase letters, "Class sample" and "Class Sample" are treated as different things.
Recommended Posts