It's been about 4 months since I started learning Java, Looking back at the question notes I wrote down when I started learning "Everyone who is a beginner has such a question." I thought, so I would like to share it with the hope that it will help beginners.
System.out.print () is a normal display. Output to the console. System.out.println () is an output method that breaks at the end.
For example
System.out.print("Miki");
System.out.print("is");
When executed with The display is
I'm Miki
Will be.
System.out.println("Miki");
System.out.println("is");
Then
Miki
is
become.
What are Java data types [String] and [Char]? What's the difference? [39 times] Is easy to understand.
Enclose char in single quotes.
char a = 'A'
This is because single quotes are judged as one character and double quotes are judged as character strings.
In the task of displaying 8 to the 20th power in loop processing, The code is correct, but the display is 0! → It may be a problem of data type tolerance.
For integers [byte<short<int<long] Please note that the size of the numerical values that can be stored is different. If you look it up, you'll see how long you can store it. With int, large numbers that exceed the capacity of int, such as 8 to the 20th power, cannot be displayed. In this case, use long (for integers). → It is necessary to use different data types depending on the size of the numerical value.
As for the method, the Main method is processed first.
public static void main(String[] args){ }
That thing.Class methods other than the Main method will work if called as needed, so no matter how much you write, they won't work (basically).
So when you make a lot of methods
For the Main method, this article is easy to understand. [Introduction to Java] Explanation of main method, its arguments (args), and return value
An "instance" is an object in a class.
For example
test.java
//Class name Instance name you want to create=new class name();← Hako to put things you want to use in the User class
User mycards = new User();
Write.
Then, an area with the same structure as the User class is secured in the memory, and that area is called mycards programmatically. The point is to call a class that has something you want to use and create a box to use it. Since mycards has the same structure as the User class, it has a field (cards, etc.) area in the User class. You can also use the methods in the User class. (Unless the field or method is "private" or something with restricted access)
"Void" in English means "empty" or "invalid". Along with this, void in Java means that the method has no return value.
test.java
public static void testMethod(Argument 1,Argument 2){
System.out.print("hogehoge");
}
At this time, the return value is void (invalidated) because it is just a process called "testMethod" that does not require a return value! It has become.
At this time, the method name does not have a type such as String.
Rather, void is the "type of the method that does not return a value".
For example, if you write ʻintinstead of
void`, it becomes a" method that returns an int ".
test.java
public static int add(int a, int b){
return a+b;
}
At this time, the add method wants to use the return value, so int is used instead of void. Therefore, at this time, it is necessary to return the int type "a + b".
The advantage of using the return value is that it can be used when the processing result of this method is called. For example, this add method
test.java
int result = add(2,3);
System.out.print(result);
If you call "add method come on!", You can use the processing result as it is here, so even if you do not write out.print (a + b), the display will be displayed.
5
Will be.
"This method expression is long, but I want to use it elsewhere. But it's subtle to write it in out.print for a long time ..." Sometimes if you set a return value, it will be a short sentence.
That was the question series when I was a beginner! This kind of rudimentary elementary step is too rudimentary and no one writes on the net. It's a waste to be addicted to it for an hour.
Let's solve the basic questions during GW! If you have any other questions, please comment ^^
Recommended Posts