Ricochet_Master
Ricochet_Master
JCHJava Community | Help. Code. Learn.
Created by Ricochet_Master on 11/20/2024 in #java-help
Good source to study threading for newer JDK releases(17 and greater)
dev.java does not seem to have a page for threading, can someone please suggest me a source for it for newer JDK version(17 and greater)?
7 replies
JCHJava Community | Help. Code. Learn.
Created by Ricochet_Master on 10/20/2024 in #java-help
Enums, mutable fields
Look at second message class myClass{ public static void main(String[] args) { // Test the EngineType enum functionality EngineType engine = EngineType.V8; // Display engine details System.out.println("Engine: " + engine.name()); System.out.println("Cylinders: " + engine.getCylinders()); System.out.println("Load Capacity: " + engine.getLoadCapacity()); // Start the engine engine.startEngine(); // Try starting it again (should show already on) engine.startEngine(); // Stop the engine engine.stopEngine(); // Try stopping it again (should show already off) engine.stopEngine(); }
public enum EngineType { V2(2, 1000), V6(6, 3000), V8(8, 4000), V10(10, 5000), V12(12, 6000); private final int cylinders; private final double loadCapacity; private boolean engineState; // mutable field // Constructor for enum constants EngineType(int cylinders, double loadCapacity) { this.cylinders = cylinders; this.loadCapacity = loadCapacity; this.engineState = false; // default engine state is off } public int getCylinders() { return cylinders; } public double getLoadCapacity() { return loadCapacity; } public boolean isEngineOn() { return engineState; } public void startEngine() { if (!engineState) { engineState = true; System.out.println(this.name() + " engine is starting."); } else { System.out.println(this.name() + " engine is already on."); } } public void stopEngine() { if (engineState) { engineState = false; System.out.println(this.name() + " engine is stopping."); } else { System.out.println(this.name() + " engine is already off."); } } } }
11 replies
JCHJava Community | Help. Code. Learn.
Created by Ricochet_Master on 9/26/2024 in #java-help
What do the modifiers of classes do?
public, private I have understood But what do abstract, static and final do? I have searched a lot, and the definitions are inconsistent over different sites
10 replies
JCHJava Community | Help. Code. Learn.
Created by Ricochet_Master on 5/4/2024 in #java-help
Where to learn Java from as a complete beginner?
Books, tutorials and which IDE to use, or just use JDK ? I am very confused on where to start learning from, please tell me about free sources only, as I am a college student and do not have the sufficient funds right now.
7 replies