(Note) Java classes / variables / methods

class

Classes are like blueprints. java creates a program in units called classes. When writing, write the class name on the right side of "class" and enclose it in {} (block).

class Hello{
  public static void main(String[] args) {
    System.out.println("Hello World");
}

variable

Variables are like boxes that you name and temporarily store data attributes. There are two main types of variables.

** Basic type (basic data type / primitive type) ** There are 8 types. Basic type variables manage their values directly.

** Class type (reference type) ** Infinite. (There are as many classes as there are.) There is a variable of class type ... that means that the class exists. A class type variable manages a copy (address) of that class. Also, write the first letter of the class in uppercase.

Method

A med is an instruction to execute a program.

Let's write the code

When you enter the name,

import java.util.Scanner;

class BackHome{

  public static void main(String[] args){
    Scanner stdIn = new Scanner(System.in);

    System.out.print("Tell me your name:");
    String s = stdIn.next();

    System.out.println("Welcome, home" + s + "Sama");
  }
}

** Input procedure 1 ** Preparation for using the Scanner class.

import java.util.Scanner;

** Input procedure 2 ** The variable "scanner" for using the Scanner class is being initialized.

Scanner stdIn = new Scanner(System.in);

** Class creation assignment **

  1. Declare a variable s of String class type [String s]
  2. A copy of the String class that manages the input string is generated. A copy of the class is generated somewhere in your computer's memory. [stdIn.next ();]
  3. The address of the copy of the class is assigned to the variable s. [=]
String s = stdIn.next();

output (If you specify the variable s, you can use the character string that follows the address in it.)

System.out.println("Hello" + s + "!!");

19-08-22-15-40-13-166_deco.jpg

Recommended Posts

(Note) Java classes / variables / methods
[Java] Generics classes and generics methods
About Java class variables class methods
Java abstract methods and classes
Java methods
Java methods
Java generics (defines classes and methods)
[Java] output, variables
Java class methods
Java programming (classes and instances, main methods)
[WIP] Java variables
JAVA learning history abstract classes and methods
[Java] Personal summary of classes and methods (basic)
Java abstract modifier [Note]
[Java] Internal Iterator Note
java classes, instances, objects
[Note] Methods ending with?
[Java] About anonymous classes
Java JUnit brief note
[java] Java SE 8 Silver Note
[Note] Java: String search
[Note] Java: String survey
My Study Note (Java)
Ruby variables and methods
[Java] Variables and types
java (classes and instances)
java: Add date [Note]
A note about Java GC
How to separate words in names in classes, methods, and variables
Java programming (variables and data)
Check Java9 Interface private methods
Java methods and method overloads
[Java] Classes, constructors, static members
How to use Java variables
[Java] [Spring] Spring Boot 1.4-> 1.2 Downgrade Note
[Ruby] Singular methods and singular classes
About abstract classes in java
Ruby variables and functions (methods)
Ruby methods and classes (basic)
Study Java with Progate Note 1
[Ruby] Singular methods and singular classes
About Java static and non-static methods
Why are class variables needed? [Java]
Java, abstract classes starting from beginners
Various methods of Java String class
[Note] Java Silver SE8 qualification acquired
[Java] Points to note with Arrays.asList ()
Java Primer Series (Variables and Types)
[Ruby] Classes, instance variables, instances, etc ...
How to call classes and methods
Organize classes, instances, and instance variables
[Processing × Java] How to use variables
Java array variables are reference types
Note 1: Elementary, stumbling blocks (java, javascript)
[Ruby] Handle instance variables with instance methods
[Note] Handling of Java decimal point
Effective Java 3rd Edition Chapter 8 Methods
My note: Introducing Java to Ubuntu
Studying Java 8 (StaticIF and Default methods)
How to use class methods [Java]
[Java] Test private methods with JUnit