A collection of simple questions for Java beginners

A collection of simple questions for Java beginners

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.

Difference between System.out.print () and System.out.println ()

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


When executed with The display is

I'm Miki

Will be.





Proper use of string and char types

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.

How to properly use numeric data types (int, long)

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.

Writing a method in a Java class doesn't work! ?? (About Main method)

As for the method, the Main method is processed first.

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

  1. Create Main method
  2. A description that calls the A method to the Main method
  3. A description that calls the B method to the A method ... It is good to write like this.

For the Main method, this article is easy to understand. [Introduction to Java] Explanation of main method, its arguments (args), and return value

What is "instantiation" after all?

An "instance" is an object in a class.

For example


//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();


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)

What is "void"?

"Void" in English means "empty" or "invalid". Along with this, void in Java means that the method has no return value.


public static void testMethod(Argument 1,Argument 2){

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 ofvoid`, it becomes a" method that returns an int ".


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


int result = add(2,3);

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

A collection of simple questions for Java beginners
[For beginners] Summary of java constructor
Expired collection of java
Java collection interview questions
Kantai Collection Java # 1 Classes and Objects [For Beginners]
[Introduction to Java] Basics of java arithmetic (for beginners)
Get a list of MBean information for Java applications
[For beginners] Quickly understand the basics of Java 8 Lambda
Let's make a robot! "A simple demo of Java AWT Robot"
Introduction to Java for beginners Basic knowledge of Java language ①
List of frequently used Java instructions (for beginners and beginners)
[Java] Beginner's understanding of Servlet-②
Java debug execution [for Java beginners]
[Java] Beginner's understanding of Servlet-①
What is a Java collection?
[Java] Draw a simple pattern
[Java] Summary of for statements
Java for beginners, data hiding
Java application for beginners: stream
[For beginners] Explanation of classes, instances, and statics in Java
Explanation of Ruby on rails for beginners ③ ~ Creating a database ~
Introducing Spring Boot2, a Java framework for web development (for beginners)
A collection of simple questions for Java beginners
[Introduction to Java] Basics of java arithmetic (for beginners)
Introduction to Java for beginners Basic knowledge of Java language ①
Think of a Java update strategy
Rock-paper-scissors game for beginners in Java
3 Implement a simple interpreter in Java
Java for beginners, expressions and operators 1
[For beginners] Run Selenium in Java
A list of rawValues for UITextContentType.
Java for beginners, expressions and operators 2
A simple sample callback in Java
A brief description of JAVA dependencies
Generics of Kotlin for Java developers
[For Java beginners] About exception handling
Classes and instances Java for beginners
Kantai Collection Java # 0 What is Object Oriented Programming (OOP)? [For beginners]
Handle business logic for a set of Entity in Java class
How to check for the contents of a java fixed-length string
Implementation of clone method for Java Record
(For beginners) Swift UI view element collection
Significance of interface learned from Java Collection
Name a group of regular expressions (Java)
A collection of phrases that impresses the "different feeling" of Java and JavaScript
Get a list of S3 files with ListObjectsV2Request (AWS SDK for Java)
I was addicted to a simple test of Jedis (Java-> Redis library)
Learn Java with "So What" [For beginners]
[Rails] A collection of tips that are immediately useful for improving performance
[For programming beginners] What is a method?
A simple sample of ArBiMap (two-way map)
[For beginners] Difference between Java and Kotlin
Sample code collection for Azure Java development
Java9 collection
Rails [For beginners] Implementation of comment function
List of download destinations for oracle java
I wrote EX25 of AtCoder Programming Guide for beginners (APG4b) in java.
Features of spring framework for java developers
Explanation of Ruby on rails for beginners ①
A simple and convenient method for HashMap
[Java] [For beginners] How to insert elements directly in a 2D array
A simple example of an MVC model
[Java] Contents of Collection interface and List interface