🪟 Windows TippsThe Gemini desktop app is now available for Windows(11.09.2026 um 17:06 Uhr)
🔧 AI Nachrichten ChatGPT automatically logged out [Fix](12.09.2026 um 17:09 Uhr)
⚠️ Malware / Trojaner / VirenWindows 11 just dropped the tool ransomware abused, Microsoft says don’t restore WMIC(10.09.2026 um 20:11 Uhr)
🪟 Windows TippsServertimeout in Outlook über 10 Minuten verlängern(12.09.2026 um 15:10 Uhr)
🪟 Windows TippsThe Gemini desktop app is now available for Windows(11.09.2026 um 17:06 Uhr)
🔧 AI Nachrichten ChatGPT automatically logged out [Fix](12.09.2026 um 17:09 Uhr)
⚠️ Malware / Trojaner / VirenWindows 11 just dropped the tool ransomware abused, Microsoft says don’t restore WMIC(10.09.2026 um 20:11 Uhr)
🪟 Windows TippsServertimeout in Outlook über 10 Minuten verlängern(12.09.2026 um 15:10 Uhr)

🔧 Programmierung 🕛 vor 7 Monaten 8 Min Lesezeit
0

Java Basics

↗ Quelle (dev.to)
🗣️ Stimme:

Run Java from terminal




CODE
javac Main.java
java Main






Welcome to Java!




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






Variables




CODE
class Main{
static void main(String[] args){
byte age = 27;
short dailyIncome = 32678;
int annualIncome = 12156216;
long phoneNumber = 2348137963060L;
float height = 1.83F;
String name = "Grace"
double weight = 80.8;
char incomeCurrency = '$';
boolean worksRemotely = true;

System.out.println(age);
System.out.println(dailyIncome);
System.out.println(annualIncome);
System.out.println(phoneNumber);
System.out.println(height);
System.out.println(weight);
System.out.println(incomeCurrency);
System.out.println(worksRemotely);

System.out.println(((Object) height).getClass().getSimpleName());
System.out.println(((Object) worksRemotely).getClass().getSimpleName());
}
}






String Methods




CODE
public class Main {
public static void main(String[] args) {

String name = "Olubiyi Grace";
System.out.println(name.toLowerCase());
System.out.println(name.toUpperCase());
System.out.println(name.length());
}
}






Enum




CODE
public class Main {
enum TRANSACTION{
SUCCESS,
PENDING,
FAILED
}
public static void main(String[] args) {

TRANSACTION transactionStatus = TRANSACTION.PENDING;
System.out.println(transactionStatus);
System.out.println(transactionStatus.compareTo(TRANSACTION.SUCCESS));
}
}






Condition




CODE
class Main {
public static void main(String[] args) {
int ageA = 27;
int ageB = 25;

if (ageA > ageB){
System.out.println("I am older");
} else if (ageA < ageB){
System.out.println("You are older");
} else {
System.out.println("We are age mates.");
}
}
}






Switch




CODE
class Main{
static void main(String[] args){
int age = 27;
switch (age) {
case 25 -> System.out.println("Not my age");
case 26 -> System.out.println("Add 1 and you will be correct.");
case 27 -> System.out.println("You got it right! This is my age.");
default -> System.out.println("Why not ask me instead of taking a guess.");
}
}
}






For Loop




CODE
public class Main {
public static void main(String[] args) {
int age = 27;

for(int x = 0; i < age; x++){
System.out.println("Age is " + x);
}
}
}






While Loop




CODE
public class Main {
public static void main(String[] args) {
//while example1
int x = 9;
while (x < 15){
System.out.println(x);
x++;
}
//while example2
int x = 9
while (x > 3){
System.out.println(x);
x--;
}
}
}






Do/while Loop




CODE
// do/while example1
int x = 8;
do{
System.out.println(x);
x++;
}
while (x < 12);
// do/while example2
int x = 12;
do {
System.out.println(x);
x++;
}
while (x >15); //this will still print despite having a false condition. That is what differentiate it from do loop.







Function




CODE
public class Main {
public static void main(String[] args) {
int response = addSum(2, 3);
System.out.println(response);
System.out.println(((Object) response).getClass().getSimpleName());
}
public static int addSum(int a, int b) {
return a + b;
}
}






Atomicity




CODE
AtomicInteger atomicInt = new AtomicInteger(0);

atomicInt.incrementAndGet(); // ++count
atomicInt.getAndIncrement(); // count++

atomicInt.decrementAndGet(); // --count

atomicInt.addAndGet(5); // count += 5

int value = atomicInt.get(); // get the current value

boolean updated = atomicInt.compareAndSet(5, 10);
// if current value == 5, update to 10






Array




CODE
public class Main {
public static void main(String[] args) {

int[] arrays = {1, 2, 3, 4};
for (int item : arrays) {
System.out.println("Item :" + item);
}
}
}






Class and Object




CODE
public class Main {
public static void main(String[] args) {

Person personOne =new Person("joe", 78);
personOne.speak();
}

}

class Person{
private final String name;
private final int age;

public Person(String name, int age) {
this.name = name;
this.age = age;
}

void speak (){
System.out.println("Name is " + name + " and age is " + age);
}
}






Inheritance




CODE
public class Main {
public static void main(String[] args) {

Person personOne =new Person("joe", 78);
personOne.speak();
personOne.scream();
}

}

class Scream {
void scream(){
System.out.println("Ahhhhhhh!");
}
}

class Person extends Scream{
private final String name;
private final int age;

public Person(String name, int age) {
this.name = name;
this.age = age;
}

void speak (){
System.out.println("Name is " + name + " and age is " + age);
}
}






Interface




CODE
public class Main {
public static void main(String[] args) {

Person personOne = new Person("joe");
personOne.scream();
}

}

interface Scream {
void scream();
}

class Person implements Scream {

private final String name;

public Person(String name) {
this.name = name;
}

@Override
public void scream() {
System.out.println(name + " screamed, Ahhhhh!!!");
}
}






Static Method




CODE
public class Main {
public static void main(String[] args) {
double pi = Utils.PI;
int square = Utils.square(3);
System.out.println(pi);
System.out.println(square);

}

}


class Utils {
static final double PI = 3.14;

static int square(int x) {
return x * x;
}
}






This




CODE
public class Main {
public static void main(String[] args) {
Bark dog = new Bark("woof");
System.out.println(dog.action);
System.out.println(dog.play());

}

}

class Bark{
String action;

public Bark(String action) {
this.action = action; // refers to Bark
}

boolean play(){
System.out.println("Joe is " + this.action);
return false;
}
}






Constructor Overloading




CODE
public class Main {
public static void main(String[] args) {
Bark dog = new Bark("woof");

}

}

class Bark {
String name;
String color;

public Bark(String name, String color) {
this.name = name;
this.color = color;
}

public Bark(String name){
this.name = name;
}
}






Override (Polymorphism)




CODE
public class Main {
public static void main(String[] args) {
Dog dog = new Dog();
dog.sound();

}

}

class Animal {
void sound(){
System.out.println("woof");
}
}

class Dog extends Animal{
@Override
void sound(){
System.out.println("Barking...");
}
}






Abstract




CODE
public class Main {
public static void main(String[] args) {
Dog dog = new Dog();
dog.sound();

Animal n = new Animal(); // abstract class cannot be instantiated
}

}

abstract class Animal {
void sound(){
System.out.println("woof");
}
}

class Dog extends Animal{
@Override
void sound(){
System.out.println("Barking...");
}
}






super()




CODE
public class Main {
public static void main(String[] args) {
Dog dog = new Dog();
}

}


class Animal {
Animal() {
System.out.println("Animal created");
}
}

class Dog extends Animal {
Dog() {
super(); // calls Animal constructor
System.out.println("Dog created");
}
}






Wrapper Class




CODE
public class Main {
public static void main(String[] args) {
Integer num = 90;
Float f1 = 90.90F; //use wrapper class if you are working with collections, JSON serialization, null-checking
System.out.println(num.equals(90)); //stick with primitives if you need performance and don't need object features.
}
// Wrapper classes provide helper methods (e.g., Integer.parseInt(), Double.compare()).
}






String Builder




CODE
public class Main {
public static void main(String[] args) {
StringBuilder sb = new StringBuilder("Hi");
sb.append(" there!");
System.out.println(sb.toString());
}
}






Null Pointer




CODE
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

import static java.lang.Character.getName;

public class Main {
public static void main(String[] args) {

try {
//Avoiding null NPE
String myName = "";
int[] myNumbers = new int[10];
List<String> items = new ArrayList<>();
System.out.println(myName);
System.out.println(myNumbers);
System.out.println(items);

if (myName != null) {
System.out.println("printing this");
}

String possiblyNullName = "";
String nullName = possiblyNullName != null ? possiblyNullName : "Unknown";
System.out.println(nullName);


String name = null;
System.out.println(name.length()); //💥 NullPointerException

int[] numbers = null;
System.out.println(numbers.length); // 💥 NPE
} catch (NullPointerException e) {
System.out.println(e.getMessage());
}

}

}






List




CODE
import java.util.ArrayList;
import java.util.List;

public class Main {
public static void main(String[] args) {
List<String> animals = new ArrayList<>(); //List<Object>
animals.add("monkey");
animals.add("lion");
System.out.println(animals);
for (String animal: animals){
System.out.println("I am a/an " + animal);
}
}

}

HashMap

import java.util.HashMap;

public class Main {
public static void main(String[] args) {
HashMap<String, String> response = new HashMap<>();
response.put("message", "success");
response.put("status", "ongoing");
System.out.println(response);
System.out.println(((Object) response).getClass().getSimpleName());
}

}
LinkedMap

import java.util.LinkedHashMap;
import java.util.Map;

public class Main {
public static void main(String[] args) {
// Create a LinkedHashMap
LinkedHashMap<String, String> capitals = new LinkedHashMap<>();

// Add key-value pairs
capitals.put("Nigeria", "Abuja");
capitals.put("USA", "Washington D.C.");
capitals.put("France", "Paris");
capitals.put("Japan", "Tokyo");

// Iterate in insertion order
System.out.println("Countries and their Capitals (in insertion order):");
for (Map.Entry<String, String> entry : capitals.entrySet()) {
System.out.println(entry.getKey() + " → " + entry.getValue());
}

// Access a value
System.out.println("\nCapital of Japan is: " + capitals.get("Japan"));

// Check if a key exists
if (capitals.containsKey("France")) {
System.out.println("France is in the map.");
}

// Remove an entry
capitals.remove("USA");
System.out.println("\nAfter removing USA:");
System.out.println(capitals);
}
}






Stream




CODE
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class Main {
public static void main(String[] args) {
List<Integer> numbers = new ArrayList<>();
numbers.add(1);
numbers.add(2);
numbers.add(3);
numbers.add(4);

List<Integer> response = numbers.stream()
.filter(i -> i % 2 == 0)
.toList();

System.out.println(response);
}

}






Stream




CODE
import java.util.Arrays;
import java.util.List;

public class Main {
public static void main(String[] args) {
List<Integer> numbers = Arrays.asList(1,2,3,4,5,6,7,8,9,10);
List<Integer> response = numbers.stream()
.filter(i -> i % 2 == 0)
.toList();

System.out.println(response);
}

}






Exception




CODE
public class Main {
public static void main(String[] args) {

try {
int response = 10 / 0;
System.out.println(response);
}catch (ArithmeticException e){
System.out.println("Oops!, Error");
}
}

}






I/O




CODE
import java.io.*;

public class Main {
public static void main(String[] args) {
try {
BufferedReader reader = new BufferedReader(new FileReader("C:\\Users\\CAPTAIN ENJOY\\Downloads\\JavaNote\\src\\text.txt"));
String line;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
reader.close();

BufferedWriter writer = new BufferedWriter(new FileWriter("C:\\Users\\CAPTAIN ENJOY\\Downloads\\JavaNote\\src\\text.txt"));
writer.write("ner");
writer.close();
} catch (IOException e) {
System.out.println(e.getMessage());
}
}
}






Lambda




CODE
import java.io.*;
import java.util.Arrays;
import java.util.List;

public class Main {
public static void main(String[] args) {

List<String> names = Arrays.asList("john", "wick", "doe");
names.forEach(name -> System.out.println("my name is " + name));
}
}


Vollständiger Original-Bericht
Ausführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
1 Quelle
The Gemini desktop app is now available for Windows
1 Quelle
ChatGPT automatically logged out [Fix]
1 Quelle
Windows 11 just dropped the tool ransomware abused, Microsoft says don’t restore WMIC
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Java Basics

Thematisch verwandte Begriffe: Java, Basics · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...