This is an article about server development for Minecraft BE (formerly PE). When we move development from PocketMine to Nukkit, the programming language changes from PHP to Java. I tried to summarize the differences between PHP and Java with a grammar that I often use personally so that I can develop it as soon as possible even if the programming language changes.
It is a variable that is often used, but in Java, ** type ** is written before the variable name. In PHP, you may have written it in the argument etc.
variable
//Type name Variable name
int number = 334;
For the type, you can write the name of the class that implements the value (334 in this case) and the name of the class that the class inherits or implements. So when it comes to creating a class and assigning that object to a variable
class Player{
}
Player player = new Player();
It will be written like this.
Java arrays are not as flexible as php. Put the determined number and put the objects of the same type.
Array
int[] array = new int[3];
array[0] = 0;
array[1] = 1;
array[2] = 2;
System.out.println(array[1]); // 1
The above can be shortened.
int[] array = new int[3]{1,2,3};
System.out.println(array[1]); // 1
List,Map In php I was able to assign a lot of objects to an array. In Java you can do the same with Lists and Maps.
ArrayList,Map
ArrayList<Integer> list = new ArrayList<Integer>(); // List
HashMap<Integer,Integer> map = new HashMap<Integer,Integer>(); // Map
In List and Map, a type called reference type is assigned. Most reference types start with an uppercase letter.
It looks like only the words are lined up, but I'd be happy if you could think that there is something like this. You will be happy to know the reference types and primitive types!
Recommended Posts