This is Not AD.
Join Our Telegram Channel To Get OUR all Material Up to Date.
Don't Worry Your All Info Will Be Secured
Home About Us Services Materials Contact Us
Home About Services Materials Contact
‹
›
Home
Home > JAVA | JOURNAL
Java Journal
JAVA JOURNAL PDF

Code

class HelloJava {
    public static void main(String arg[]) {
        System.out.println("Hello Java");
        System.out.print("Java is an OOP");
    }
}
Output

Hello Java
Java is an OOP
Code

class VariableDemo {
    public static void main(String[] arg) {
        int i = 10;
        String n = "Java";
        float f = 5.5f;
        System.out.println("Value of i : " + i);
        System.out.println("Value of n: " + n);
        System.out.println("Value of f: " + f);
    }
}
Output

Value of i : 10
Value of n: Java
Value of f: 5.5
Code

public class LeapYearExample {
    public static void main(String[] args) {
        int year = 2021;
        if(((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)){
            System.out.println("LEAP YEAR");
        } else {
            System.out.println("COMMON YEAR");
        }
    }
}
Output

COMMON YEAR
Code

public class SwitchExample {
    public static void main(String[] args) {
        char ch='L';
        switch(ch) {
            case 'a': case 'e': case 'i': case 'o': case 'u':
            case 'A': case 'E': case 'I': case 'O': case 'U':
                System.out.println("Vowel");
                break;
            default:
                System.out.println("Consonant");
        }
    }
}
Output

Consonant
Code

class FindMin {
    static void min(int arr[]) {
        int min = arr[0];
        for(int i = 1; i < arr.length; i++) {
            if(min > arr[i]) min = arr[i];
        }
        System.out.println(min);
    }
    public static void main(String args[]) {
        int a[] = {33, 3, 1, 5};
        min(a);
    }
}
Output

1
Code

class Student {
    int id;
    String name;
}
class TestStudent {
    public static void main(String args[]) {
        Student s1 = new Student();
        Student s2 = new Student();
        s1.id = 101;
        s1.name = "Ritul";
        s2.id = 102;
        s2.name = "Amit";
        System.out.println(s1.id + " " + s1.name);
        System.out.println(s2.id + " " + s2.name);
    }
}
Output

101 Ritul
102 Amit
Code

class Employee {
    int id;
    String name;
    float salary;
    void setData(int i, String n, float s) {
        id = i;
        name = n;
        salary = s;
    }
    void getData() {
        System.out.println(id + " " + name + " " + salary);
    }
}
public class TestEmployee {
    public static void main(String[] args) {
        Employee e1 = new Employee();
        Employee e2 = new Employee();
        e1.setData(101, "Ravi", 45000);
        e2.setData(102, "Mohit", 25000);
        e1.getData();
        e2.getData();
    }
}
Output

101 Ravi 45000.0
102 Mohit 25000.0
Code

class Student4 {
    int id;
    String name;
    Student4(int i, String n) {
        id = i;
        name = n;
    }
    void display() { System.out.println(id + " " + name); }
    public static void main(String args[]) {
        Student4 s1 = new Student4(111, "Ritul");
        Student4 s2 = new Student4(222, "Ravi");
        s1.display();
        s2.display();
    }
}
Output

111 Ritul
222 Ravi
Code

class Student5 {
    int id;
    String name;
    int age;
    Student5(int i, String n) {
        id = i;
        name = n;
    }
    Student5(int i, String n, int a) {
        id = i;
        name = n;
        age = a;
    }
    void display() { System.out.println(id + " " + name + " " + age); }
    public static void main(String args[]) {
        Student5 s1 = new Student5(111, "Mohit");
        Student5 s2 = new Student5(222, "Priyanshu", 25);
        s1.display();
        s2.display();
    }
}
Output

111 Mohit 0
222 Priyanshu 25
Code

class Test {
    public static void main(String[] args) {
        int[][] arr = new int[2][]; 
        arr[0] = new int[] { 11, 21, 56, 78 };
        arr[1] = new int[] { 42, 61, 37, 41, 59, 63 };
        
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr[i].length; j++) {
                System.out.print(arr[i][j] + " ");
            }
            System.out.println();
        }
    }
}
Output

11 21 56 78 
42 61 37 41 59 63 
Code

class Student6 {
    int id;
    String name;
    Student6(int i, String n) {
        id = i;
        name = n;
    }
    Student6(Student6 s) {
        id = s.id;
        name = s.name;
    }
    void display() { System.out.println(id + " " + name); }
    public static void main(String args[]) {
        Student6 s1 = new Student6(111, "Krupa");
        Student6 s2 = new Student6(s1);
        s1.display();
        s2.display();
    }
}
Output

111 Krupa
111 Krupa
Code

class Animal {
    void eat() { System.out.println("eating...."); }
}
class Dog extends Animal {
    void bark() { System.out.println("barking..."); }
}
class BabyDog extends Dog {
    void weep() { System.out.println("weeping..."); }
}
class TestInheritance {
    public static void main(String args[]) {
        BabyDog d = new BabyDog();
        d.weep();
        d.bark();
        d.eat();
    }
}
Output

weeping...
barking...
eating....
Code

class Adder {
    static int add(int a, int b) { return a + b; }
    static double add(double a, double b) { return a + b; }
}
class TestOverloading {
    public static void main(String[] args) {
        System.out.println(Adder.add(11, 11));
        System.out.println(Adder.add(12.3, 12.6));
    }
}
Output

22
24.9
Code

class Animal {
    Animal() { System.out.println("From animal constructor"); }
    void eat() { System.out.println("eating...."); }
    protected void finalize() { System.out.println("End of animal"); }
}
class Dog extends Animal {
    Dog() { System.out.println("From dog constructor"); }
    void bark() { System.out.println("barking..."); }
    protected void finalize() { System.out.println("End of dog"); }
}
class BabyDog extends Dog {
    BabyDog() { System.out.println("From babydog constructor"); }
    void weep() { System.out.println("weeping..."); }
    protected void finalize() { System.out.println("End of babydog"); }
}
class TestInheritance2 {
    public static void main(String args[]) {
        BabyDog d = new BabyDog();
        d.weep();
        d.bark();
        d.eat();
        d = null;
        System.gc();
    }
}
Output

From animal constructor
From dog constructor
From babydog constructor
weeping...
barking...
eating....
End of babydog
Code

abstract class Shape {
    abstract void draw();
}
class Rectangle extends Shape {
    void draw() { System.out.println("drawing rectangle"); }
}
class Circle extends Shape {
    void draw() { System.out.println("drawing circle"); }
}
class TestAbstraction {
    public static void main(String args[]) {
        Shape s1 = new Circle();
        Shape s2 = new Rectangle();
        s1.draw();
        s2.draw();
    }
}
Output

drawing circle
drawing rectangle
Code

final class ParentClass {
    void showData() { System.out.println("This is a method of final Parent class"); }
}
// Compilation Error will occur here:
class ChildClass extends ParentClass {
    void showData() { System.out.println("This is a method of Child class"); }
}
class MainClass {
    public static void main(String arg[]) {
        ParentClass obj = new ChildClass();
        obj.showData();
    }
}
Output

Compilation error! Cannot inherit from final 'ParentClass'.
Code

interface Animal {
    public void eat();
    public void travel();
}
class MammalInt implements Animal {
    public void eat() { System.out.println("Mammal eats"); }
    public void travel() { System.out.println("Mammal travels"); }
    public int noOfLegs() { return 0; }
}
public class Main {
    public static void main(String args[]) {
        MammalInt m = new MammalInt();
        m.eat();
        m.travel();
    }
}
Output

Mammal eats
Mammal travels
Code

class Main {
    private int data = 30;
    class Inner {
        void msg() { System.out.println("data is " + data); }
    }
    public static void main(String args[]) {
        Main obj = new Main();
        Main.Inner in = obj.new Inner();
        in.msg();
    }
}
Output

data is 30
Code

import java.util.Date;
public class Main {
    public static void main(String args[]) {
        Date date = new Date();
        System.out.println(date.toString());
    }
}
Output

[Current Date & Time, e.g., Sun Mar 08 17:29:12 IST 2026]
Code

public class Main {
    public static void main(String args[]) {
        byte b = 10;
        int i = 30;
        
        //Autoboxing
        Byte byteobj = b;
        Integer intobj = i;
        
        System.out.println("Byte object: " + byteobj);
        System.out.println("Integer object: " + intobj);
        
        //Unboxing
        byte bytevalue = byteobj;
        int intvalue = intobj;
        
        System.out.println("byte value: " + bytevalue);
        System.out.println("int value: " + intvalue);
    }
}
Output

Byte object: 10
Integer object: 30
byte value: 10
int value: 30
Code

package mypack;
public class Simple {
    public static void main(String args[]) {
        System.out.println("Welcome to package");
    }
}
Output

Welcome to package
Code

import java.util.StringTokenizer;
public class Simple {
    public static void main(String args[]) {
        StringTokenizer st = new StringTokenizer("Java OOP Programing Language", " ");
        while (st.hasMoreTokens()) {
            System.out.println(st.nextToken());
        }
    }
}
Output

Java
OOP
Programing
Language
Code

public class Main {
    public static void main(String[] args) {
        int a = 10, b = 0, c = 0;
        System.out.println("Start of main()");
        try {
            c = a / b;
        } catch(ArithmeticException ae) {
            System.out.println(ae);
        } finally {
            System.out.println("I am always there...");
            System.out.println("Value of C:" + c);
            System.out.println("End of main()");
        }
    }
}
Output

Start of main()
java.lang.ArithmeticException: / by zero
I am always there...
Value of C:0
End of main()
Code

public class Main {
    public static void main(String[] args) {
        try {
            int a[] = new int[5];
            a[5] = 30 / 0;
        } catch(ArithmeticException e) {
            System.out.println("Arithmetic Exception occurs");
        } catch(ArrayIndexOutOfBoundsException e) {
            System.out.println("ArrayIndexOutOfBounds Exception occurs");
        } catch(Exception e) {
            System.out.println("Parent Exception occurs");
        }
        System.out.println("rest of the code");
    }
}
Output

Arithmetic Exception occurs
rest of the code
Code

class InvalidAgeException extends Exception {
    InvalidAgeException(String s) { super(s); }
}
class Main {
    static void validate(int age) throws InvalidAgeException {
        if(age < 18) throw new InvalidAgeException("not valid");
        else System.out.println("welcome to vote");
    }
    public static void main(String args[]) {
        try {
            validate(13);
        } catch(Exception m) { 
            System.out.println("Exception occured: " + m); 
        }
        System.out.println("rest of the code...");
    }
}
Output

Exception occured: InvalidAgeException: not valid
rest of the code...
Code

public class ThreadDemo1 {
    public static void main(String[] args) {
        System.out.println("Start of main");
        MyThread1 mt1 = new MyThread1();
        MyThread2 mt2 = new MyThread2();
        mt1.start();
        mt2.start();
        System.out.println("End of main");
    }
}
class MyThread1 extends Thread {
    public void run() {
        for(int i = 1; i <= 10; i++) System.out.println("MyThread-1." + i);
    }
}
class MyThread2 extends Thread {
    public void run() {
        for(int i = 1; i <= 10; i++) System.out.println("MyThread-2." + i);
    }
}
Output

Start of main
End of main
MyThread-1.1
MyThread-2.1
[... Interleaved outputs of threads 1 and 2 ...]
Code

public class ThreadDemo2 {
    public static void main(String[] args) {
        System.out.println("Start of main");
        MyThread mt = new MyThread();
        Thread t1 = new Thread(mt, "Thread-1");
        Thread t2 = new Thread(mt, "Thread-2");
        t1.start();
        t2.start();
        System.out.println("End of main");
    }
}
class MyThread implements Runnable {
    public void run() {
        for(int i = 1; i <= 10; i++) {
            System.out.println(Thread.currentThread().getName() + "." + i);
        }
    }
}
Output

Start of main
End of main
Thread-1.1
Thread-2.1
[... Interleaved output ...]
Code

public class ThreadDemo3 {
    public static void main(String[] args) {
        System.out.println("Start of main");
        MyThread1 mt1 = new MyThread1();
        MyThread2 mt2 = new MyThread2();
        mt1.start();
        mt2.start();
        System.out.println("End of main");
    }
}
class MyThread1 extends Thread {
    public void run() {
        for(int i = 1; i <= 10; i++) {
            System.out.println("MyThread-1." + i);
            Thread.yield();
        }
    }
}
class MyThread2 extends Thread {
    public void run() {
        for(int i = 1; i <= 10; i++) {
            System.out.println("MyThread-2." + i);
            Thread.yield();
        }
    }
}
Output

Start of main
End of main
MyThread-1.1
MyThread-2.1
[... Alternating due to yield ...]
Code

public class ThreadDemo3 {
    public static void main(String[] args) {
        try {
            System.out.println("Start of main");
            MyThread1 mt1 = new MyThread1();
            MyThread2 mt2 = new MyThread2();
            mt1.start();
            mt2.start();
            mt2.join();
            System.out.println("End of main");
        } catch(Exception e) {}
    }
}
class MyThread1 extends Thread {
    public void run() {
        for(int i = 1; i <= 10; i++) {
            System.out.println("MyThread-1." + i);
            try { sleep(100); } catch(Exception e) {}
        }
    }
}
class MyThread2 extends Thread {
    public void run() {
        for(int i = 1; i <= 10; i++) {
            System.out.println("MyThread-2." + i);
            try { sleep(200); } catch(Exception e) {}
        }
    }
}
Output

Start of main
MyThread-1.1
MyThread-2.1
[... Threads run, main blocks ...]
End of main
Code

public class ThreadDemo4 {
    public static void main(String[] args) {
        System.out.println("Start main");
        MyThread mt = new MyThread();
        Thread t1 = new Thread(mt, "Thread-1");
        Thread t2 = new Thread(mt, "Thread-2");
        t1.start();
        t2.start();
        t2.setPriority(t1.getPriority() + 5);
        System.out.println("End main");
    }
}
class MyThread implements Runnable {
    public void run() {
        for(int i = 1; i <= 10; i++) {
            System.out.println(Thread.currentThread().getName());
        }
    }
}
Output

Start main
End main
Thread-2
Thread-2
[... Thread 2 completes faster due to higher priority ...]
Code

import java.io.*;
public class IODemo1 {
    public static void main(String[] args) {
        try {
            File f = new File("abc.txt");
            if(f.createNewFile()) {
                System.out.println("File Sucessfully created");
            } else {
                System.out.println("File already exist");
            }
            System.out.println("File name: " + f.getName());
            System.out.println("Exists: " + f.exists());
        } catch(Exception e) {
            System.out.println(e);
        }
    }
}
Output

File Sucessfully created
File name: abc.txt
Exists: true
Code

import java.io.*;
public class IODemo3 {
    public static void main(String[] args) {
        System.out.println("Content of output.txt file:\n");
        try {
            FileInputStream fin = new FileInputStream("output.txt");
            int c;
            while((c = fin.read()) != -1) {
                System.out.print((char)c);
            }
        } catch(Exception e) { }
    }
}
Output

Content of output.txt file:
[Text content of file]
Code

import java.io.*;
public class IODemo2 {
    public static void main(String[] args) {
        try {
            BufferedInputStream out = new BufferedInputStream(System.in);
            FileOutputStream fout = new FileOutputStream("output.txt");
            System.out.println("Enter text (enter & to end): ");
            int ch;
            while ((ch = out.read()) != '&') {
                fout.write((char)ch);
            }
            fout.close();
        } catch(Exception e) {}
    }
}
Output

Enter text (enter & to end): 
Code

import java.io.*;
public class IOStreamsExample {
    public static void main(String args[]) throws IOException {
        File file = new File("D:/myFile.txt");
        FileReader reader = new FileReader(file);
        char chars[] = new char[(int) file.length()];
        reader.read(chars);
        
        File out = new File("D:/CopyOfmyFile.txt");
        FileWriter writer = new FileWriter(out);
        writer.write(chars);
        writer.flush();
        System.out.println("Data successfully written in the specified file");
    }
}
Output

Data successfully written in the specified file
Code

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

public class FirstApp extends Application {
    @Override
    public void start(Stage primaryStage) {
        Button btn = new Button();
        btn.setText("Say 'Hello World'");
        btn.setOnAction(new EventHandler<ActionEvent>() {
            public void handle(ActionEvent event) {
                System.out.println("Hello World!");
            }
        });
        StackPane root = new StackPane();
        root.getChildren().add(btn);
        Scene scene = new Scene(root, 300, 250);
        primaryStage.setTitle("Hello World!");
        primaryStage.setScene(scene);
        primaryStage.show();
    }
    public static void main(String[] args) { launch(args); }
}
GUI Output Mockup

Hello World!
Code

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.scene.text.*;
import javafx.stage.Stage;

public class TextExample extends Application {
    @Override
    public void start(Stage primaryStage) {
        Text text = new Text();
        text.setText("Hello !! Welcome to JavaFX");
        text.setFill(Color.BLUE);
        text.setStrokeWidth(2);
        text.setStroke(Color.RED);
        text.setFont(Font.font("Comic Sans MS", FontWeight.BOLD, FontPosture.REGULAR, 30));
        StackPane root = new StackPane();
        root.getChildren().add(text);
        Scene scene = new Scene(root, 600, 400);
        primaryStage.setTitle("Text Example");
        primaryStage.setScene(scene);
        primaryStage.show();
    }
    public static void main(String[] args) { launch(args); }
}
GUI Output Mockup

Text Example
Hello !! Welcome to JavaFX
Code

import javafx.application.Application;
import javafx.scene.*;
import javafx.scene.paint.Color;
import javafx.scene.shape.*;
import javafx.stage.Stage;

public class ShapeExample extends Application {
    @Override
    public void start(Stage primaryStage) {
        Group group = new Group();
        Rectangle rect = new Rectangle();
        rect.setX(10); rect.setY(10); rect.setWidth(100); rect.setHeight(100);
        rect.setArcHeight(35); rect.setArcWidth(35); rect.setFill(Color.RED);
        
        Circle circle = new Circle();
        circle.setCenterX(300); circle.setCenterY(200); circle.setRadius(100);
        circle.setFill(Color.GREEN);
        
        group.getChildren().addAll(rect, circle);
        Scene scene = new Scene(group, 600, 400);
        primaryStage.setTitle("2D Shape Example");
        primaryStage.setScene(scene);
        primaryStage.show();
    }
    public static void main(String[] args) { launch(args); }
}
GUI Output Mockup

2D Shape Example
Code

import javafx.application.Application;
import javafx.scene.*;
import javafx.scene.paint.Color;
import javafx.scene.shape.*;
import javafx.stage.Stage;

public class Shapes3DExample extends Application {
    @Override
    public void start(Stage primaryStage) throws Exception {
        Box box1 = new Box();
        box1.setHeight(100); box1.setWidth(100); box1.setDepth(400);
        box1.setTranslateX(200); box1.setTranslateY(200); box1.setTranslateZ(200);
        
        Cylinder cyn = new Cylinder();
        cyn.setRadius(80); cyn.setHeight(200);
        cyn.setTranslateX(400); cyn.setTranslateY(250);
        
        PerspectiveCamera camera = new PerspectiveCamera();
        camera.setTranslateX(100); camera.setTranslateY(100); camera.setTranslateZ(50);
        
        Group root = new Group();
        root.getChildren().addAll(box1, cyn);
        Scene scene = new Scene(root, 450, 350, Color.LIMEGREEN);
        scene.setCamera(camera);
        primaryStage.setScene(scene);
        primaryStage.setTitle("3DShape Example");
        primaryStage.show();
    }
    public static void main(String[] args) { launch(args); }
}
GUI Output Mockup

3DShape Example
Code

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;

public class GridPaneExample extends Application {
    @Override
    public void start(Stage primaryStage) throws Exception {
        Label first_name = new Label("First Name");
        Label last_name = new Label("Last Name");
        TextField tf1 = new TextField();
        TextField tf2 = new TextField();
        Button Submit = new Button("Submit");
        
        GridPane root = new GridPane();
        root.addRow(0, first_name, tf1);
        root.addRow(1, last_name, tf2);
        root.addRow(2, Submit);
        
        Scene scene = new Scene(root, 400, 200);
        primaryStage.setTitle("GridPane Layout");
        primaryStage.setScene(scene);
        primaryStage.show();
    }
    public static void main(String[] args) { launch(args); }
}
GUI Output Mockup

GridPane Layout
Code

import javafx.application.Application;
import javafx.scene.*;
import javafx.scene.effect.ImageInput;
import javafx.scene.image.Image;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;

public class ImageInputExample extends Application {
    @Override
    public void start(Stage primaryStage) throws Exception {
        Image img = new Image("https://upload.wikimedia.org/wikipedia/commons/e/e3/Animhorse.gif");
        ImageInput imginput = new ImageInput();
        Rectangle rect = new Rectangle();
        
        imginput.setSource(img);
        imginput.setX(20); imginput.setY(100);
        rect.setEffect(imginput);
        
        Group root = new Group();
        root.getChildren().add(rect);
        Scene scene = new Scene(root, 530, 500, Color.BLACK);
        primaryStage.setScene(scene);
        primaryStage.setTitle("ImageInput Example");
        primaryStage.show();
    }
    public static void main(String[] args) { launch(args); }
}
GUI Output Mockup

ImageInput Example
Running Horse
Code

import javafx.application.Application;
import javafx.animation.FadeTransition;
import javafx.scene.*;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.util.Duration;
import javafx.stage.Stage;

public class AnimationExample extends Application{
    @Override
    public void start(Stage primaryStage) throws Exception {
        Circle cir = new Circle(250, 120, 80);
        cir.setFill(Color.RED);
        cir.setStroke(Color.BLACK);
        
        FadeTransition fade = new FadeTransition();
        fade.setDuration(Duration.millis(5000));
        fade.setFromValue(10);
        fade.setToValue(0.1);
        fade.setCycleCount(1000);
        fade.setAutoReverse(true);
        fade.setNode(cir);
        fade.play();
        
        Group root = new Group();
        root.getChildren().addAll(cir);
        Scene scene = new Scene(root, 500, 250, Color.WHEAT);
        primaryStage.setScene(scene);
        primaryStage.setTitle("Transition example");
        primaryStage.show();
    }
    public static void main(String[] args) { launch(args); }
}
GUI Output Mockup

Transition example
Code

import javafx.application.Application;
import javafx.scene.*;
import javafx.scene.control.Label;
import javafx.scene.paint.Color;
import javafx.scene.text.*;
import javafx.stage.Stage;

public class JavafxLabel extends Application {
    public void start(Stage stage) {
        Label label = new Label("Sample label");
        Font font = Font.font("Brush Script MT", FontWeight.BOLD, FontPosture.REGULAR, 25);
        label.setFont(font);
        label.setTextFill(Color.BROWN);
        label.setTranslateX(10); label.setTranslateY(10);
        
        Group root = new Group();
        root.getChildren().add(label);
        Scene scene = new Scene(root, 400, 300, Color.BEIGE);
        stage.setTitle("Label Example");
        stage.setScene(scene);
        stage.show();
    }
    public static void main(String args[]) { launch(args); }
}
GUI Output Mockup

Label Example
Sample label
Code

import javafx.application.Application;
import javafx.event.*;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.HBox;
import javafx.scene.paint.Color;
import javafx.stage.Stage;

public class JavafxTextfield extends Application {
    public void start(Stage stage) {
        TextField textField1 = new TextField();
        TextField textField2 = new TextField();
        Label label1 = new Label("Enter Text: ");
        Label label2 = new Label("Entered Text: ");
        Button btn = new Button("Click");
        
        btn.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent arg0) {
                textField2.setText(textField1.getText());
            }
        });
        
        HBox box = new HBox(5);
        box.setPadding(new Insets(25, 5, 5, 50));
        box.getChildren().addAll(label1, textField1, label2, textField2, btn);
        
        Scene scene = new Scene(box, 595, 150, Color.BEIGE);
        stage.setTitle("Text Field Example");
        stage.setScene(scene);
        stage.show();
    }
    public static void main(String args[]) { launch(args); }
}
GUI Output Mockup

Text Field Example
Code

import javafx.application.Application;
import javafx.collections.*;
import javafx.event.*;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.VBox;
import javafx.scene.text.*;
import javafx.stage.Stage;

public class JavafxListview extends Application {
    public void start(Stage stage) {
        Label label = new Label("Educational qualification:");
        Label label2 = new Label();
        Font font = Font.font("verdana", FontWeight.BOLD, FontPosture.REGULAR, 12);
        label.setFont(font);
        
        ObservableList<String> names = FXCollections.observableArrayList(
            "Engineering", "MCA", "MBA", "Graduation", "MTECH", "Mphil", "Phd");
        ListView<String> listView = new ListView<String>(names);
        listView.setMaxSize(200, 160);
        
        Button btn = new Button("Select Course");
        btn.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent arg0) {
                label2.setText(listView.getItems().toString());
            }
        });
        
        VBox layout = new VBox(10);
        layout.setPadding(new Insets(5, 5, 5, 50));
        layout.getChildren().addAll(label, listView, btn, label2);
        
        Scene scene = new Scene(layout, 400, 300);
        stage.setTitle("List View Example");
        stage.setScene(scene);
        stage.show();
    }
    public static void main(String args[]) { launch(args); }
}
GUI Output Mockup

List View Example
Code

import javafx.application.Application;
import javafx.scene.*;
import javafx.scene.control.Slider;
import javafx.stage.Stage;

public class SliderExample extends Application {
    public void start(Stage stage) {
        Group root = new Group();
        Scene scene = new Scene(root, 600, 400);
        stage.setScene(scene);
        stage.setTitle("Slider Sample");
        
        Slider slider = new Slider();
        root.getChildren().add(slider);
        
        stage.show();
    }
    public static void main(String[] args) { launch(args); }
}
GUI Output Mockup

Slider Sample
Code (PlayAudio)

import java.io.File;
import javafx.application.Application;
import javafx.scene.media.*;
import javafx.stage.Stage;

public class PlayAudio extends Application {
    @Override
    public void start(Stage primaryStage) throws Exception {
        String path = "C:\\Users\\malay\\Downloads\\test.mp3";
        Media media = new Media(new File(path).toURI().toString());
        MediaPlayer mediaPlayer = new MediaPlayer(media);
        mediaPlayer.setAutoPlay(true);
        primaryStage.setTitle("Playing Audio");
        primaryStage.show();
    }
    public static void main(String[] args) { launch(args); }
}

Code (PlayVideo)

import java.io.File;
import javafx.application.Application;
import javafx.scene.*;
import javafx.scene.media.*;
import javafx.stage.Stage;

public class PlayVideo extends Application {
    @Override
    public void start(Stage primaryStage) throws Exception {
        String path = "C:\\Users\\malay\\Downloads\\test.mp4";
        Media media = new Media(new File(path).toURI().toString());
        MediaPlayer mediaPlayer = new MediaPlayer(media);
        MediaView mediaView = new MediaView(mediaPlayer);
        mediaPlayer.setAutoPlay(true);
        
        Group root = new Group();
        root.getChildren().add(mediaView);
        Scene scene = new Scene(root, 500, 400);
        
        primaryStage.setScene(scene);
        primaryStage.setTitle("Playing video");
        primaryStage.show();
    }
    public static void main(String[] args) { launch(args); }
}
GUI Output Mockup

Playing video
Video element placeholder

No comments:

Post a Comment

Friday, 27 February 2026

JAVA | JOURNAL

Java Journal
JAVA JOURNAL PDF

Code

class HelloJava {
    public static void main(String arg[]) {
        System.out.println("Hello Java");
        System.out.print("Java is an OOP");
    }
}
Output

Hello Java
Java is an OOP
Code

class VariableDemo {
    public static void main(String[] arg) {
        int i = 10;
        String n = "Java";
        float f = 5.5f;
        System.out.println("Value of i : " + i);
        System.out.println("Value of n: " + n);
        System.out.println("Value of f: " + f);
    }
}
Output

Value of i : 10
Value of n: Java
Value of f: 5.5
Code

public class LeapYearExample {
    public static void main(String[] args) {
        int year = 2021;
        if(((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)){
            System.out.println("LEAP YEAR");
        } else {
            System.out.println("COMMON YEAR");
        }
    }
}
Output

COMMON YEAR
Code

public class SwitchExample {
    public static void main(String[] args) {
        char ch='L';
        switch(ch) {
            case 'a': case 'e': case 'i': case 'o': case 'u':
            case 'A': case 'E': case 'I': case 'O': case 'U':
                System.out.println("Vowel");
                break;
            default:
                System.out.println("Consonant");
        }
    }
}
Output

Consonant
Code

class FindMin {
    static void min(int arr[]) {
        int min = arr[0];
        for(int i = 1; i < arr.length; i++) {
            if(min > arr[i]) min = arr[i];
        }
        System.out.println(min);
    }
    public static void main(String args[]) {
        int a[] = {33, 3, 1, 5};
        min(a);
    }
}
Output

1
Code

class Student {
    int id;
    String name;
}
class TestStudent {
    public static void main(String args[]) {
        Student s1 = new Student();
        Student s2 = new Student();
        s1.id = 101;
        s1.name = "Ritul";
        s2.id = 102;
        s2.name = "Amit";
        System.out.println(s1.id + " " + s1.name);
        System.out.println(s2.id + " " + s2.name);
    }
}
Output

101 Ritul
102 Amit
Code

class Employee {
    int id;
    String name;
    float salary;
    void setData(int i, String n, float s) {
        id = i;
        name = n;
        salary = s;
    }
    void getData() {
        System.out.println(id + " " + name + " " + salary);
    }
}
public class TestEmployee {
    public static void main(String[] args) {
        Employee e1 = new Employee();
        Employee e2 = new Employee();
        e1.setData(101, "Ravi", 45000);
        e2.setData(102, "Mohit", 25000);
        e1.getData();
        e2.getData();
    }
}
Output

101 Ravi 45000.0
102 Mohit 25000.0
Code

class Student4 {
    int id;
    String name;
    Student4(int i, String n) {
        id = i;
        name = n;
    }
    void display() { System.out.println(id + " " + name); }
    public static void main(String args[]) {
        Student4 s1 = new Student4(111, "Ritul");
        Student4 s2 = new Student4(222, "Ravi");
        s1.display();
        s2.display();
    }
}
Output

111 Ritul
222 Ravi
Code

class Student5 {
    int id;
    String name;
    int age;
    Student5(int i, String n) {
        id = i;
        name = n;
    }
    Student5(int i, String n, int a) {
        id = i;
        name = n;
        age = a;
    }
    void display() { System.out.println(id + " " + name + " " + age); }
    public static void main(String args[]) {
        Student5 s1 = new Student5(111, "Mohit");
        Student5 s2 = new Student5(222, "Priyanshu", 25);
        s1.display();
        s2.display();
    }
}
Output

111 Mohit 0
222 Priyanshu 25
Code

class Test {
    public static void main(String[] args) {
        int[][] arr = new int[2][]; 
        arr[0] = new int[] { 11, 21, 56, 78 };
        arr[1] = new int[] { 42, 61, 37, 41, 59, 63 };
        
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr[i].length; j++) {
                System.out.print(arr[i][j] + " ");
            }
            System.out.println();
        }
    }
}
Output

11 21 56 78 
42 61 37 41 59 63 
Code

class Student6 {
    int id;
    String name;
    Student6(int i, String n) {
        id = i;
        name = n;
    }
    Student6(Student6 s) {
        id = s.id;
        name = s.name;
    }
    void display() { System.out.println(id + " " + name); }
    public static void main(String args[]) {
        Student6 s1 = new Student6(111, "Krupa");
        Student6 s2 = new Student6(s1);
        s1.display();
        s2.display();
    }
}
Output

111 Krupa
111 Krupa
Code

class Animal {
    void eat() { System.out.println("eating...."); }
}
class Dog extends Animal {
    void bark() { System.out.println("barking..."); }
}
class BabyDog extends Dog {
    void weep() { System.out.println("weeping..."); }
}
class TestInheritance {
    public static void main(String args[]) {
        BabyDog d = new BabyDog();
        d.weep();
        d.bark();
        d.eat();
    }
}
Output

weeping...
barking...
eating....
Code

class Adder {
    static int add(int a, int b) { return a + b; }
    static double add(double a, double b) { return a + b; }
}
class TestOverloading {
    public static void main(String[] args) {
        System.out.println(Adder.add(11, 11));
        System.out.println(Adder.add(12.3, 12.6));
    }
}
Output

22
24.9
Code

class Animal {
    Animal() { System.out.println("From animal constructor"); }
    void eat() { System.out.println("eating...."); }
    protected void finalize() { System.out.println("End of animal"); }
}
class Dog extends Animal {
    Dog() { System.out.println("From dog constructor"); }
    void bark() { System.out.println("barking..."); }
    protected void finalize() { System.out.println("End of dog"); }
}
class BabyDog extends Dog {
    BabyDog() { System.out.println("From babydog constructor"); }
    void weep() { System.out.println("weeping..."); }
    protected void finalize() { System.out.println("End of babydog"); }
}
class TestInheritance2 {
    public static void main(String args[]) {
        BabyDog d = new BabyDog();
        d.weep();
        d.bark();
        d.eat();
        d = null;
        System.gc();
    }
}
Output

From animal constructor
From dog constructor
From babydog constructor
weeping...
barking...
eating....
End of babydog
Code

abstract class Shape {
    abstract void draw();
}
class Rectangle extends Shape {
    void draw() { System.out.println("drawing rectangle"); }
}
class Circle extends Shape {
    void draw() { System.out.println("drawing circle"); }
}
class TestAbstraction {
    public static void main(String args[]) {
        Shape s1 = new Circle();
        Shape s2 = new Rectangle();
        s1.draw();
        s2.draw();
    }
}
Output

drawing circle
drawing rectangle
Code

final class ParentClass {
    void showData() { System.out.println("This is a method of final Parent class"); }
}
// Compilation Error will occur here:
class ChildClass extends ParentClass {
    void showData() { System.out.println("This is a method of Child class"); }
}
class MainClass {
    public static void main(String arg[]) {
        ParentClass obj = new ChildClass();
        obj.showData();
    }
}
Output

Compilation error! Cannot inherit from final 'ParentClass'.
Code

interface Animal {
    public void eat();
    public void travel();
}
class MammalInt implements Animal {
    public void eat() { System.out.println("Mammal eats"); }
    public void travel() { System.out.println("Mammal travels"); }
    public int noOfLegs() { return 0; }
}
public class Main {
    public static void main(String args[]) {
        MammalInt m = new MammalInt();
        m.eat();
        m.travel();
    }
}
Output

Mammal eats
Mammal travels
Code

class Main {
    private int data = 30;
    class Inner {
        void msg() { System.out.println("data is " + data); }
    }
    public static void main(String args[]) {
        Main obj = new Main();
        Main.Inner in = obj.new Inner();
        in.msg();
    }
}
Output

data is 30
Code

import java.util.Date;
public class Main {
    public static void main(String args[]) {
        Date date = new Date();
        System.out.println(date.toString());
    }
}
Output

[Current Date & Time, e.g., Sun Mar 08 17:29:12 IST 2026]
Code

public class Main {
    public static void main(String args[]) {
        byte b = 10;
        int i = 30;
        
        //Autoboxing
        Byte byteobj = b;
        Integer intobj = i;
        
        System.out.println("Byte object: " + byteobj);
        System.out.println("Integer object: " + intobj);
        
        //Unboxing
        byte bytevalue = byteobj;
        int intvalue = intobj;
        
        System.out.println("byte value: " + bytevalue);
        System.out.println("int value: " + intvalue);
    }
}
Output

Byte object: 10
Integer object: 30
byte value: 10
int value: 30
Code

package mypack;
public class Simple {
    public static void main(String args[]) {
        System.out.println("Welcome to package");
    }
}
Output

Welcome to package
Code

import java.util.StringTokenizer;
public class Simple {
    public static void main(String args[]) {
        StringTokenizer st = new StringTokenizer("Java OOP Programing Language", " ");
        while (st.hasMoreTokens()) {
            System.out.println(st.nextToken());
        }
    }
}
Output

Java
OOP
Programing
Language
Code

public class Main {
    public static void main(String[] args) {
        int a = 10, b = 0, c = 0;
        System.out.println("Start of main()");
        try {
            c = a / b;
        } catch(ArithmeticException ae) {
            System.out.println(ae);
        } finally {
            System.out.println("I am always there...");
            System.out.println("Value of C:" + c);
            System.out.println("End of main()");
        }
    }
}
Output

Start of main()
java.lang.ArithmeticException: / by zero
I am always there...
Value of C:0
End of main()
Code

public class Main {
    public static void main(String[] args) {
        try {
            int a[] = new int[5];
            a[5] = 30 / 0;
        } catch(ArithmeticException e) {
            System.out.println("Arithmetic Exception occurs");
        } catch(ArrayIndexOutOfBoundsException e) {
            System.out.println("ArrayIndexOutOfBounds Exception occurs");
        } catch(Exception e) {
            System.out.println("Parent Exception occurs");
        }
        System.out.println("rest of the code");
    }
}
Output

Arithmetic Exception occurs
rest of the code
Code

class InvalidAgeException extends Exception {
    InvalidAgeException(String s) { super(s); }
}
class Main {
    static void validate(int age) throws InvalidAgeException {
        if(age < 18) throw new InvalidAgeException("not valid");
        else System.out.println("welcome to vote");
    }
    public static void main(String args[]) {
        try {
            validate(13);
        } catch(Exception m) { 
            System.out.println("Exception occured: " + m); 
        }
        System.out.println("rest of the code...");
    }
}
Output

Exception occured: InvalidAgeException: not valid
rest of the code...
Code

public class ThreadDemo1 {
    public static void main(String[] args) {
        System.out.println("Start of main");
        MyThread1 mt1 = new MyThread1();
        MyThread2 mt2 = new MyThread2();
        mt1.start();
        mt2.start();
        System.out.println("End of main");
    }
}
class MyThread1 extends Thread {
    public void run() {
        for(int i = 1; i <= 10; i++) System.out.println("MyThread-1." + i);
    }
}
class MyThread2 extends Thread {
    public void run() {
        for(int i = 1; i <= 10; i++) System.out.println("MyThread-2." + i);
    }
}
Output

Start of main
End of main
MyThread-1.1
MyThread-2.1
[... Interleaved outputs of threads 1 and 2 ...]
Code

public class ThreadDemo2 {
    public static void main(String[] args) {
        System.out.println("Start of main");
        MyThread mt = new MyThread();
        Thread t1 = new Thread(mt, "Thread-1");
        Thread t2 = new Thread(mt, "Thread-2");
        t1.start();
        t2.start();
        System.out.println("End of main");
    }
}
class MyThread implements Runnable {
    public void run() {
        for(int i = 1; i <= 10; i++) {
            System.out.println(Thread.currentThread().getName() + "." + i);
        }
    }
}
Output

Start of main
End of main
Thread-1.1
Thread-2.1
[... Interleaved output ...]
Code

public class ThreadDemo3 {
    public static void main(String[] args) {
        System.out.println("Start of main");
        MyThread1 mt1 = new MyThread1();
        MyThread2 mt2 = new MyThread2();
        mt1.start();
        mt2.start();
        System.out.println("End of main");
    }
}
class MyThread1 extends Thread {
    public void run() {
        for(int i = 1; i <= 10; i++) {
            System.out.println("MyThread-1." + i);
            Thread.yield();
        }
    }
}
class MyThread2 extends Thread {
    public void run() {
        for(int i = 1; i <= 10; i++) {
            System.out.println("MyThread-2." + i);
            Thread.yield();
        }
    }
}
Output

Start of main
End of main
MyThread-1.1
MyThread-2.1
[... Alternating due to yield ...]
Code

public class ThreadDemo3 {
    public static void main(String[] args) {
        try {
            System.out.println("Start of main");
            MyThread1 mt1 = new MyThread1();
            MyThread2 mt2 = new MyThread2();
            mt1.start();
            mt2.start();
            mt2.join();
            System.out.println("End of main");
        } catch(Exception e) {}
    }
}
class MyThread1 extends Thread {
    public void run() {
        for(int i = 1; i <= 10; i++) {
            System.out.println("MyThread-1." + i);
            try { sleep(100); } catch(Exception e) {}
        }
    }
}
class MyThread2 extends Thread {
    public void run() {
        for(int i = 1; i <= 10; i++) {
            System.out.println("MyThread-2." + i);
            try { sleep(200); } catch(Exception e) {}
        }
    }
}
Output

Start of main
MyThread-1.1
MyThread-2.1
[... Threads run, main blocks ...]
End of main
Code

public class ThreadDemo4 {
    public static void main(String[] args) {
        System.out.println("Start main");
        MyThread mt = new MyThread();
        Thread t1 = new Thread(mt, "Thread-1");
        Thread t2 = new Thread(mt, "Thread-2");
        t1.start();
        t2.start();
        t2.setPriority(t1.getPriority() + 5);
        System.out.println("End main");
    }
}
class MyThread implements Runnable {
    public void run() {
        for(int i = 1; i <= 10; i++) {
            System.out.println(Thread.currentThread().getName());
        }
    }
}
Output

Start main
End main
Thread-2
Thread-2
[... Thread 2 completes faster due to higher priority ...]
Code

import java.io.*;
public class IODemo1 {
    public static void main(String[] args) {
        try {
            File f = new File("abc.txt");
            if(f.createNewFile()) {
                System.out.println("File Sucessfully created");
            } else {
                System.out.println("File already exist");
            }
            System.out.println("File name: " + f.getName());
            System.out.println("Exists: " + f.exists());
        } catch(Exception e) {
            System.out.println(e);
        }
    }
}
Output

File Sucessfully created
File name: abc.txt
Exists: true
Code

import java.io.*;
public class IODemo3 {
    public static void main(String[] args) {
        System.out.println("Content of output.txt file:\n");
        try {
            FileInputStream fin = new FileInputStream("output.txt");
            int c;
            while((c = fin.read()) != -1) {
                System.out.print((char)c);
            }
        } catch(Exception e) { }
    }
}
Output

Content of output.txt file:
[Text content of file]
Code

import java.io.*;
public class IODemo2 {
    public static void main(String[] args) {
        try {
            BufferedInputStream out = new BufferedInputStream(System.in);
            FileOutputStream fout = new FileOutputStream("output.txt");
            System.out.println("Enter text (enter & to end): ");
            int ch;
            while ((ch = out.read()) != '&') {
                fout.write((char)ch);
            }
            fout.close();
        } catch(Exception e) {}
    }
}
Output

Enter text (enter & to end): 
Code

import java.io.*;
public class IOStreamsExample {
    public static void main(String args[]) throws IOException {
        File file = new File("D:/myFile.txt");
        FileReader reader = new FileReader(file);
        char chars[] = new char[(int) file.length()];
        reader.read(chars);
        
        File out = new File("D:/CopyOfmyFile.txt");
        FileWriter writer = new FileWriter(out);
        writer.write(chars);
        writer.flush();
        System.out.println("Data successfully written in the specified file");
    }
}
Output

Data successfully written in the specified file
Code

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

public class FirstApp extends Application {
    @Override
    public void start(Stage primaryStage) {
        Button btn = new Button();
        btn.setText("Say 'Hello World'");
        btn.setOnAction(new EventHandler<ActionEvent>() {
            public void handle(ActionEvent event) {
                System.out.println("Hello World!");
            }
        });
        StackPane root = new StackPane();
        root.getChildren().add(btn);
        Scene scene = new Scene(root, 300, 250);
        primaryStage.setTitle("Hello World!");
        primaryStage.setScene(scene);
        primaryStage.show();
    }
    public static void main(String[] args) { launch(args); }
}
GUI Output Mockup

Hello World!
Code

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.scene.text.*;
import javafx.stage.Stage;

public class TextExample extends Application {
    @Override
    public void start(Stage primaryStage) {
        Text text = new Text();
        text.setText("Hello !! Welcome to JavaFX");
        text.setFill(Color.BLUE);
        text.setStrokeWidth(2);
        text.setStroke(Color.RED);
        text.setFont(Font.font("Comic Sans MS", FontWeight.BOLD, FontPosture.REGULAR, 30));
        StackPane root = new StackPane();
        root.getChildren().add(text);
        Scene scene = new Scene(root, 600, 400);
        primaryStage.setTitle("Text Example");
        primaryStage.setScene(scene);
        primaryStage.show();
    }
    public static void main(String[] args) { launch(args); }
}
GUI Output Mockup

Text Example
Hello !! Welcome to JavaFX
Code

import javafx.application.Application;
import javafx.scene.*;
import javafx.scene.paint.Color;
import javafx.scene.shape.*;
import javafx.stage.Stage;

public class ShapeExample extends Application {
    @Override
    public void start(Stage primaryStage) {
        Group group = new Group();
        Rectangle rect = new Rectangle();
        rect.setX(10); rect.setY(10); rect.setWidth(100); rect.setHeight(100);
        rect.setArcHeight(35); rect.setArcWidth(35); rect.setFill(Color.RED);
        
        Circle circle = new Circle();
        circle.setCenterX(300); circle.setCenterY(200); circle.setRadius(100);
        circle.setFill(Color.GREEN);
        
        group.getChildren().addAll(rect, circle);
        Scene scene = new Scene(group, 600, 400);
        primaryStage.setTitle("2D Shape Example");
        primaryStage.setScene(scene);
        primaryStage.show();
    }
    public static void main(String[] args) { launch(args); }
}
GUI Output Mockup

2D Shape Example
Code

import javafx.application.Application;
import javafx.scene.*;
import javafx.scene.paint.Color;
import javafx.scene.shape.*;
import javafx.stage.Stage;

public class Shapes3DExample extends Application {
    @Override
    public void start(Stage primaryStage) throws Exception {
        Box box1 = new Box();
        box1.setHeight(100); box1.setWidth(100); box1.setDepth(400);
        box1.setTranslateX(200); box1.setTranslateY(200); box1.setTranslateZ(200);
        
        Cylinder cyn = new Cylinder();
        cyn.setRadius(80); cyn.setHeight(200);
        cyn.setTranslateX(400); cyn.setTranslateY(250);
        
        PerspectiveCamera camera = new PerspectiveCamera();
        camera.setTranslateX(100); camera.setTranslateY(100); camera.setTranslateZ(50);
        
        Group root = new Group();
        root.getChildren().addAll(box1, cyn);
        Scene scene = new Scene(root, 450, 350, Color.LIMEGREEN);
        scene.setCamera(camera);
        primaryStage.setScene(scene);
        primaryStage.setTitle("3DShape Example");
        primaryStage.show();
    }
    public static void main(String[] args) { launch(args); }
}
GUI Output Mockup

3DShape Example
Code

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;

public class GridPaneExample extends Application {
    @Override
    public void start(Stage primaryStage) throws Exception {
        Label first_name = new Label("First Name");
        Label last_name = new Label("Last Name");
        TextField tf1 = new TextField();
        TextField tf2 = new TextField();
        Button Submit = new Button("Submit");
        
        GridPane root = new GridPane();
        root.addRow(0, first_name, tf1);
        root.addRow(1, last_name, tf2);
        root.addRow(2, Submit);
        
        Scene scene = new Scene(root, 400, 200);
        primaryStage.setTitle("GridPane Layout");
        primaryStage.setScene(scene);
        primaryStage.show();
    }
    public static void main(String[] args) { launch(args); }
}
GUI Output Mockup

GridPane Layout
Code

import javafx.application.Application;
import javafx.scene.*;
import javafx.scene.effect.ImageInput;
import javafx.scene.image.Image;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;

public class ImageInputExample extends Application {
    @Override
    public void start(Stage primaryStage) throws Exception {
        Image img = new Image("https://upload.wikimedia.org/wikipedia/commons/e/e3/Animhorse.gif");
        ImageInput imginput = new ImageInput();
        Rectangle rect = new Rectangle();
        
        imginput.setSource(img);
        imginput.setX(20); imginput.setY(100);
        rect.setEffect(imginput);
        
        Group root = new Group();
        root.getChildren().add(rect);
        Scene scene = new Scene(root, 530, 500, Color.BLACK);
        primaryStage.setScene(scene);
        primaryStage.setTitle("ImageInput Example");
        primaryStage.show();
    }
    public static void main(String[] args) { launch(args); }
}
GUI Output Mockup

ImageInput Example
Running Horse
Code

import javafx.application.Application;
import javafx.animation.FadeTransition;
import javafx.scene.*;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.util.Duration;
import javafx.stage.Stage;

public class AnimationExample extends Application{
    @Override
    public void start(Stage primaryStage) throws Exception {
        Circle cir = new Circle(250, 120, 80);
        cir.setFill(Color.RED);
        cir.setStroke(Color.BLACK);
        
        FadeTransition fade = new FadeTransition();
        fade.setDuration(Duration.millis(5000));
        fade.setFromValue(10);
        fade.setToValue(0.1);
        fade.setCycleCount(1000);
        fade.setAutoReverse(true);
        fade.setNode(cir);
        fade.play();
        
        Group root = new Group();
        root.getChildren().addAll(cir);
        Scene scene = new Scene(root, 500, 250, Color.WHEAT);
        primaryStage.setScene(scene);
        primaryStage.setTitle("Transition example");
        primaryStage.show();
    }
    public static void main(String[] args) { launch(args); }
}
GUI Output Mockup

Transition example
Code

import javafx.application.Application;
import javafx.scene.*;
import javafx.scene.control.Label;
import javafx.scene.paint.Color;
import javafx.scene.text.*;
import javafx.stage.Stage;

public class JavafxLabel extends Application {
    public void start(Stage stage) {
        Label label = new Label("Sample label");
        Font font = Font.font("Brush Script MT", FontWeight.BOLD, FontPosture.REGULAR, 25);
        label.setFont(font);
        label.setTextFill(Color.BROWN);
        label.setTranslateX(10); label.setTranslateY(10);
        
        Group root = new Group();
        root.getChildren().add(label);
        Scene scene = new Scene(root, 400, 300, Color.BEIGE);
        stage.setTitle("Label Example");
        stage.setScene(scene);
        stage.show();
    }
    public static void main(String args[]) { launch(args); }
}
GUI Output Mockup

Label Example
Sample label
Code

import javafx.application.Application;
import javafx.event.*;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.HBox;
import javafx.scene.paint.Color;
import javafx.stage.Stage;

public class JavafxTextfield extends Application {
    public void start(Stage stage) {
        TextField textField1 = new TextField();
        TextField textField2 = new TextField();
        Label label1 = new Label("Enter Text: ");
        Label label2 = new Label("Entered Text: ");
        Button btn = new Button("Click");
        
        btn.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent arg0) {
                textField2.setText(textField1.getText());
            }
        });
        
        HBox box = new HBox(5);
        box.setPadding(new Insets(25, 5, 5, 50));
        box.getChildren().addAll(label1, textField1, label2, textField2, btn);
        
        Scene scene = new Scene(box, 595, 150, Color.BEIGE);
        stage.setTitle("Text Field Example");
        stage.setScene(scene);
        stage.show();
    }
    public static void main(String args[]) { launch(args); }
}
GUI Output Mockup

Text Field Example
Code

import javafx.application.Application;
import javafx.collections.*;
import javafx.event.*;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.VBox;
import javafx.scene.text.*;
import javafx.stage.Stage;

public class JavafxListview extends Application {
    public void start(Stage stage) {
        Label label = new Label("Educational qualification:");
        Label label2 = new Label();
        Font font = Font.font("verdana", FontWeight.BOLD, FontPosture.REGULAR, 12);
        label.setFont(font);
        
        ObservableList<String> names = FXCollections.observableArrayList(
            "Engineering", "MCA", "MBA", "Graduation", "MTECH", "Mphil", "Phd");
        ListView<String> listView = new ListView<String>(names);
        listView.setMaxSize(200, 160);
        
        Button btn = new Button("Select Course");
        btn.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent arg0) {
                label2.setText(listView.getItems().toString());
            }
        });
        
        VBox layout = new VBox(10);
        layout.setPadding(new Insets(5, 5, 5, 50));
        layout.getChildren().addAll(label, listView, btn, label2);
        
        Scene scene = new Scene(layout, 400, 300);
        stage.setTitle("List View Example");
        stage.setScene(scene);
        stage.show();
    }
    public static void main(String args[]) { launch(args); }
}
GUI Output Mockup

List View Example
Code

import javafx.application.Application;
import javafx.scene.*;
import javafx.scene.control.Slider;
import javafx.stage.Stage;

public class SliderExample extends Application {
    public void start(Stage stage) {
        Group root = new Group();
        Scene scene = new Scene(root, 600, 400);
        stage.setScene(scene);
        stage.setTitle("Slider Sample");
        
        Slider slider = new Slider();
        root.getChildren().add(slider);
        
        stage.show();
    }
    public static void main(String[] args) { launch(args); }
}
GUI Output Mockup

Slider Sample
Code (PlayAudio)

import java.io.File;
import javafx.application.Application;
import javafx.scene.media.*;
import javafx.stage.Stage;

public class PlayAudio extends Application {
    @Override
    public void start(Stage primaryStage) throws Exception {
        String path = "C:\\Users\\malay\\Downloads\\test.mp3";
        Media media = new Media(new File(path).toURI().toString());
        MediaPlayer mediaPlayer = new MediaPlayer(media);
        mediaPlayer.setAutoPlay(true);
        primaryStage.setTitle("Playing Audio");
        primaryStage.show();
    }
    public static void main(String[] args) { launch(args); }
}

Code (PlayVideo)

import java.io.File;
import javafx.application.Application;
import javafx.scene.*;
import javafx.scene.media.*;
import javafx.stage.Stage;

public class PlayVideo extends Application {
    @Override
    public void start(Stage primaryStage) throws Exception {
        String path = "C:\\Users\\malay\\Downloads\\test.mp4";
        Media media = new Media(new File(path).toURI().toString());
        MediaPlayer mediaPlayer = new MediaPlayer(media);
        MediaView mediaView = new MediaView(mediaPlayer);
        mediaPlayer.setAutoPlay(true);
        
        Group root = new Group();
        root.getChildren().add(mediaView);
        Scene scene = new Scene(root, 500, 400);
        
        primaryStage.setScene(scene);
        primaryStage.setTitle("Playing video");
        primaryStage.show();
    }
    public static void main(String[] args) { launch(args); }
}
GUI Output Mockup

Playing video
Video element placeholder
GOHEL MANTHAN - February 27, 2026
‹
›
Home

Creating innovative solutions for a connected world.

Email On

manthangohel04@gmail.com

This website was designed , developed and maintenance by GOHEL MANTHAN © 2026