Java Tutorial For Beginners

public void methodName() { // code to be executed } public void methodName(int num, String data) { // code to be executed } methodName() methodName(10, “dataString”); class Test { public int sumNumbers(int a, int b) { int sum = a + b; return sum; } public static void main(String[] args) { int num1 = 10;…

Read More Methods in Java

type variableName = variableValue; public class Car { String brand; int maxSpeed; } class Car { String brand; int maxSpeed; public void printFields() { System.out.println(“BRAND: ” + brand); System.out.println(“MAX SPEED: ” + maxSpeed); } } public class Test { public static void main(String[] args) { Car ford = new Car(); ford.brand = “Ford”; ford.maxSpeed =…

Read More Variable in Java

class Car { int numberOfSeats = 4; void addOneSeat(int numberOfSeats) { numberOfSeats = numberOfSeats + 1; // changes will only affect the local variable } public static void main(String args[]) { Car car = new Car(); System.out.println(“Number of seats before the change: ” + car.numberOfSeats); car.addOneSeat(car.numberOfSeats); System.out.println(“Number of seats after the change ” + car.numberOfSeats);…

Read More Java Pass-by-Value vs Pass-by-Reference

In addition to the Java Runtime Environment (JRE), the JDK includes the following components: Compiler The Java compiler is used to convert Java source code into bytecode that can be executed on the Java Virtual Machine (JVM). A compiler is a command-line tool that takes a .java file as input and produces a .class file…

Read More JRE, JDK, and JVM: Understanding Differences and Uses

byte Uses 1 byte (8 bits) for a binary record of integers Values ​​of this type are integers in the range -2 ^ 7 to 2 ^ 7-1, ie. [-128, 127] The default value is 0 Example: byte var1=120, byte var2=-30 short Uses 2 bytes (16 bits) to write integer binaries Values ​​of this type…

Read More Java Data types