0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Javaの基礎的な文法

Last updated at Posted at 2025-05-14

🔹 1. Javaとは?
オブジェクト指向プログラミング言語

クロスプラットフォーム(OSに依存しない)

Android開発にも使われている

🔹 2. 基本の構文
▶ クラスとメソッド

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

public class Main:クラスの定義

mainメソッド:プログラムのスタート地点

System.out.println:コンソールに出力

🔹 3. 変数の宣言と型

int age = 25;
String name = "Taro";
boolean isStudent = true;

🔹 4. if文(条件分岐)

int score = 80;
if (score >= 60) {
  System.out.println("合格!");
} else {
  System.out.println("不合格");
}

🔹 5. for文(繰り返し)

for (int i = 0; i < 5; i++) {
  System.out.println(i);
}

🔹 6. 配列

int[] numbers = {10, 20, 30};
System.out.println(numbers[0]); // 10

🔹 7. メソッドの定義

public static int add(int a, int b) {
  return a + b;
}

🔹 8. クラスとオブジェクト

public class Person {
  String name;

  public void greet() {
    System.out.println("こんにちは、" + name + "です!");
  }
}
Person p = new Person();
p.name = "Taro";
p.greet();

📝 まとめ
Javaは型が厳密で、文法がしっかりしているので、基礎を押さえると応用も楽になる。

特にクラスやメソッドの書き方に慣れると、他の言語にも応用が効く。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?