What is a class in Java language (1 /?)

Self-introduction

Nice to meet you. I am a graduate student who has no choice. Again. We are conducting research on networks in a laboratory surrounded by many pickled stones. Since this is my first time writing a blog, I think that both quantity and quality will be poor, but I look forward to working with you in the future.

In writing this article

An acquaintance who got a job in the IT industry this year told me to teach the basics of Java, so I decided to write an article. I hope it will be helpful for people in similar circumstances. Also, please read the references at the bottom of the page for books that have helped me a lot in learning Java.

Target audience

--Those who understand other languages but do not understand Java very much --Those who were studying Java but got stuck in the middle and gave up

Contents

This time, I will touch on some of the classes that are an essential part of object-oriented programming for understanding Java. I will write about the class over the next few days, so thank you.

What is a class

If you know C language, you should recognize the class as if it had hair on the structure. C language: wa, data Java: let data wa The Java language has classes and methods. A class is a bundle of methods. As I will write in a future article, you can make effective use of classes only by using instances and encapsulation. In this article, I hope you can get a feel for what the class is. The advantage of using classes is that the code is easier to manage and more readable. Now, let's actually compare the four arithmetic programs written in C and Java, and explain that using classes improves code management and readability.

Left half C language, right half Java


#include <stdio.h>
#include <stdlib.h>

typedef struct calculate {                         public class Calculate {
    int a, b;                                          int a, b;
} *Calculate;

Calculate new_Calculate(int a, int b) {            Calculate(int a, int b) {
    Calculate this = malloc(sizeof(*this));  
    this->a = a;                                       this.a = a;
    this->b = b;                                       this.b = b;
    return this;                              
}                                                  }

int add(Calculate this) {                          int add() {
    return this->a + this->b;                          return this.a + this.b; 
}                                                  }                           

int main(int argc, char *argv[]) {                 public static void main(String[] args) {
    Calculate data = new_Calculate(123, 456);          Calculate data = new Calculate(123, 456);
    printf("%d\n", add(data));                         System.out.printf("%d\n", data.add());
}                                                     }
                                                  }

In C language, four arithmetic operations are defined separately as functions, but in Java language, they can be described together in one class called keisan. If you want to write a program that finds the remainder of the quotient here, you have to add more functions in C language. However, in the Java language, you can add it to the keisan class. By using classes in this way, it becomes easier to understand where and what kind of program is. In other words, it makes the code easier to manage and improves readability. The larger and more complex the program, the more noticeable this difference will be. I will write about public and static described in Java programs in a future article. Please read it for now.

At the end

I wrote a blog for the first time, but it's very difficult. .. .. Let's get used to it and improve the quantity and quality! !! !! So the goal is to publish articles every day during GW. I will do my best. I would appreciate it if you could point out any mistakes in this article. Tomorrow I will write about calling another class. If you like, please stay with me tomorrow. Thank you for reading this far.

References

[Introduction to Java 2nd Edition (Refreshing Series)](https://www.amazon.co.jp/%E3%82%B9%E3%83%83%E3%82%AD%E3%83%AA % E3% 82% 8F% E3% 81% 8B% E3% 82% 8BJava% E5% 85% A5% E9% 96% 80-% E7% AC% AC2% E7% 89% 88-% E3% 82% B9 % E3% 83% 83% E3% 82% AD% E3% 83% AA% E3% 82% B7% E3% 83% AA% E3% 83% BC% E3% 82% BA-% E4% B8% AD% E5% B1% B1-% E6% B8% 85% E5% 96% AC / dp / 484433638X / ref = zg_bs_515820_1? _Encoding = UTF8 & psc = 1 & refRID = JGCC33P1VGV3V5VKQGQR)

Recommended Posts

What is a class in Java language (1 /?)
What is a class in Java language (2 /?)
What is a wrapper class?
What is a Java collection?
[Java] What is class inheritance?
[Java basics] What is Class?
What is a snippet in programming?
What is a lambda expression (Java)
[Swift] What is "inheriting a class"?
What is java
What is Java <>?
What is Java
What is the main method in Java?
Creating a matrix class in Java Part 1
What is a constructor?
What is a stream
What is Java Encapsulation?
What is Java technology?
What is Java API-java
[Java] What is flatMap?
What is a Servlet?
[Java] What is JavaBeans?
[Java] What is ArrayList?
GetInstance () from a @Singleton class in Groovy from Java
A quick review of Java learned in class
What is Java Assertion? Summary.
What is a boolean type?
A quick review of Java learned in class part4
What is a meaningful comment?
Write a class that can be ordered in Java
What is the BufferedReader class?
What is a jar file?
Find a subset in Java
What is a lambda expression?
What I learned when building a server in Java
[Java] What is jaee j2ee?
A quick review of Java learned in class part3
A quick review of Java learned in class part2
Cause of is not visible when calling a method of another class in java
What is a fa⁉ enum?
Java11: Run Java code in a single file as is
What is java escape analysis?
What is the LocalDateTime class? [Java beginner] -Date and time class-
[MQTT / Java] Implemented a class that does MQTT Pub / Sub in Java
[Java] A class is an OS, and an instance is a virtual computer.
Road to Java Engineer Part2 What kind of language is Java?
What is JVM (Java Virtual Machine)?
3 Implement a simple interpreter in Java
I created a PDF in Java.
How slow is a Java Scanner?
thread safe process in java language
StringBuffer and StringBuilder Class in Java
A simple sample callback in Java
[Java] What got caught in encapsulation
What is thread safe (with Java)
What is a column Boolean type?
What is a reference type variable?
What is @Autowired in Spring boot?
[Java] What is Concurrent Modification Exception?
Java Calendar is not a singleton.
Get stuck in a Java primer