ARCHIVE.PH MIGHT ACK SOON (GLOWNIGGERS ARE AFTER ITS ADMIN)
ALWAYS USE MULTIPLE ARCHIVES AND REARCHIVE EVERYTHING (on megalodon.jp and other archivers) NOW!!!
(possibly a false alarm doey)

SNCA:Java

From Soyjak Wiki, the free ensoyclopedia
(Redirected from Java)
Jump to navigationJump to search
Why yes, Java is a gigachad.
How could you tell?
0:30
Java mascot, Duke, as an jak.

Java, also known as Jahwa is a general purpose programming language used in numerous applications, such as game development. It is used on Netflix and Google[1][2], on devices such as Android phones and Smart TVs, and on your PC for RuneScape and Minecraft. It is object oriented, and forces everything (even the program itself) to be an object. It is a very gemmy language due to its massive standard library, making it convenient to use. You probably also used it for playing Java ME[a] games on your dad's cell phone. Did you know? Java runs on your credit card.[3]

Tutorial[edit | edit source]

Java Basics
Menu
Basics
In Java, the file name must match the name of the public class. For example, if your class is public class NusoiProgram, save the file as NusoiProgram.java. This is required for the program to compile.
Boilerplate
Every simple Java program needs this structure. The program always starts with a public class and a main() method. The main() method is where the program begins execution.
public class NusoiProgram {
    public static void main(String[] args) {
        // Your code goes here
    }
}
Hello World
Here's a simple hello world app. The println() method prints text and moves to the next line automatically.
public class NusoiProgram {
    public static void main(String[] args) {
        System.out.println("Hello Saar!");
    }
}
Variables
Java uses variables to store data. Each variable has a type, like <def title="Integer">int</def> for numbers, double for decimals, and String for text. You WILL say what type of variable it is before setting it doe.
public class NusoiProgram {
    public static void main(String[] args) {
        int age = 25;
        double price = 2000.31;
        String name = "Bajeet";
        System.out.println(name + " is " + age + " years old and the price of his laptop was " + price + "rupees");
    }
}
Adding Numbers
You can read numbers from the user and add them together. import java.util.Scanner; adds the Scanner class from the package java.util into the code. The Scanner class allows you to get input from the console.
import java.util.Scanner;

public class NusoiProgram {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        System.out.print("Enter first number: ");
        int firstNumber = scanner.nextInt();

        System.out.print("Enter second number: ");
        int secondNumber = scanner.nextInt();

        System.out.println(firstNumber + " + " + secondNumber + " = " + (firstNumber + secondNumber));
    } 
}
Convert time
This is almost exactly like the previous example, but using multiplication instead. Notice how we are using print() instead of println() to get user input- this is to make the cursor be on the same line as the question.
import java.util.Scanner;

public class NusoiProgram {

    public static void main(String[] args) {
        Scanner nusoi = new Scanner(System.in);
        System.out.print("Enter time in minutes: ");
        
        int minutes = nusoi.nextInt();
        int seconds = minutes * 60;
        
        System.out.println(minutes + " minutes is " + seconds + " seconds.");
    }
}
Printf
We will introduce printf(), which is a version of print() that accepts C-style format specifiers. %d formats numeric types and %s formats strings. %n is a newline specifier.
public class NusoiProgram {
    public static void main(String[] args) {
        int age = 25;
        double price = 2000.31;
        String name = "Bajeet";
        System.out.printf("%s is %d years old and the price of his laptop was %d rupees.%n", name, age, price);
    }
}
Star pyramid
A star pyramid is a pyramid of stars. WAAAOOOOW! This script below generates it.
import java.util.Scanner;

public class NusoiProgram {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.print("Enter the number of rows: ");
        int numOfRows = input.nextInt();
        for (int i = numOfRows; i > 0; i -= 2){
            for (int j = 1; j <= i / 2; ++j) {
                System.out.print(" ");
            }
            for (int k = i; k <= numOfRows; ++k) {
                System.out.print("*");
            }
            System.out.println();
        }
    }
}
Classes, interfaces, inheritance
A class should have a constructor (which has no return type and bears the same name as the class), which is used with the keyword new to instantiate a new instance. Each Java source file can have at most one public declaration. You can make a class inherit another class's features by using a extends clause. In Java, it is only possible to extend a single class. All classes implicitly extend Object. However, you can inherit as many interfaces as you would like; an interface is essentially a set of methods. When overriding a function, indicate it is overriden with the @Override annotation.
// Base class of vehicles, which implicitly extends Object
class Vehicle {
    private String brand;
    private int year;

    public Vehicle(String brand, int year) {
        this.brand = brand;
        this.year = year;
    }

    public void displayInfo() {
        System.out.printf("Brand: %s, Year: %d%n", brand, year);
    }
}

// Interface for flying vehicles
interface Flyable {
    void fly();
}

// Interface for drivable vehicles
interface Drivable {
    void drive();
}

// Car class extends Vehicle and implements Drivable
class Car extends Vehicle implements Drivable {
    private int doors;

    public Car(String brand, int year, int doors) {
        super(brand, year); // calling Vehicle constructor
        this.doors = doors;
    }

    @Override
    public void drive() {
        System.out.printf("Driving the car with %d doors.%n", doors);
    }

    public void displayCarInfo() {
        displayInfo();
        System.out.printf("Doors: %s%n", doors);
    }
}

// Airplane class extends Vehicle and implements Flyable
class Airplane extends Vehicle implements Flyable {
    private int maxAltitude;

    public Airplane(String brand, int year, int maxAltitude) {
        super(brand, year); // calling Vehicle constructor
        this.maxAltitude = maxAltitude;
    }

    @Override
    public void fly() {
        System.out.printf("Flying the airplane at max altitude of %d metres.%n", maxAltitude);
    }

    public void displayAirplaneInfo() {
        displayInfo();
        System.out.printf("Max Altitude: %d metres.%n", maxAltitude);
    }
}

public class NusoiProgram {
    public static void main(String[] args) {
        Car car = new Car("Toyota", 2022, 4);
        Airplane airplane = new Airplane("Boeing", 2020, 35000);

        car.displayCarInfo(); // Display car details
        car.drive(); // Driving the car

        System.out.println();

        airplane.displayAirplaneInfo(); // Display airplane details
        airplane.fly(); // Flying the airplane
    }
}
GUI
This uses Swing. The code snippet below is used in this applet, but can also be used in normal desktop apps. Remember, NetBeans makes Java GUIs drag and drop, just like Visual Basic.
import java.awt.event.ActionEvent;

public class NusoiProgram {
    private void jButton1ActionPerformed(ActionEvent evt) {
         int num1 = (int) jSpinner1.getValue();
         int num2 = (int) jSpinner2.getValue();
         int calculation = num1 + num2;
         jTextField1.setText(Integer.toString(calculation));
    }
}

This uses AWT. Remember, NetBeans makes Java GUIs drag and drop.

import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.swing.JFrame;

public class NusoiProgram extends JFrame {
    public HelloWorldApp() {
        setTitle("Helo saar");
        setSize(300, 200);
        setVisible(true);
    }

    @Override
    public void paint(Graphics g) {
        g.drawString("Hello saar", 100, 100);
    }

    public static void main(String[] args) {
        HelloWorldApp instance = new HelloWorldApp();
        instance.paint(new Graphics2D());
    }
}
Next Steps
Here are some resources to continue learning Java:

Extra notes for beginners:

  • public static void main(String[] args) is the entry point of your program. Only one method with this signature is allowed. The JVM looks for a method with this exact signature to execute the program.
  • Packages organize your code. Example: package com.example; must match the folder structure com/example/. It typically is of the structure TLD, then organisation name, then subdirectories (e.g. package party.soyjak.soy; for soyjak.party/soy)
  • Print methods:
    • print() – prints text without moving to a new line.
    • println() – prints text and moves to a new line.
    • printf() – prints text with format specifiers (like in C), no newline automatically.
  • The java.lang package is always available; you don't need to import it. This package contains important globally relevant classes like String, Math, and System.
  • A public class can be used by other programs outside its package.
Final Step to Mastery



More about Java[edit | edit source]

WARNING: WORDSWORDSWORDS
This page or section is just one big wall of text.

It is based on C++, but without all the pain of pointers and other hassles. It has always been quite popular in America, with Python only overtaking it in recent years.[4] Sadly, it is also associated with 'jeets because a lot of jeets learn Java from Durgasoft. Linus Torvalds, the creator of Linux, called it an "awful language", though xe is a tranny and xis opinions don't matter.

Despite the similar name, it is not related to JavaScript (a web scripting language that many pajeets learn because it is a braindead language for retards).

Unlike C++, which is compiled directly to machine code tied to an operating system, Java is compiled into bytecode interpreted by the JVM—an intermediate virtual machine enabling platform independence, dynamic class loading, easy decompilation, and powerful runtime reflection capabilities.

One of the main boasts of Java is its "write once, run anywhere" slogan, which basically means that due to the JVM which runs on top of the operating system, there is no need to recompile code: you just have to have the .jar file and run that. Everything just runs on the JVM, so Java code is essentially platform independent. Also, Java is basically dialect-free. Most people use OpenJDK, which is an open-source development of the Java Development Kit (JDK). There are many build systems available for Java, the most common are Maven and Gradle (you should probably just use Gradle since it is simple and modern and less verbose than Maven o algo).

Java is a very 'emmy language for general use, such as making any application. You can also make 'cord bots with Java, which can be useful if you want to make a bot to spam or troll 'cord 'rannies, though you could also do this with Python. There are several popular libraries such as JDA for this. However, because of Java's high memory footprint due to its massive runtime and garbage collection (with almost no manual memory/resource management), it is less suitable for making games or operating systems with.

Unlike C and C++, Java is garbage collected which means you can just allocate memory and not have to manually deallocate it. So Java is memory safe (like Rust fellow trans queens).

A long time ago you could use Java to make applets which were like mini programs you could run in your browser. But Jews took this away from us because muh (((security))) and now we only have JeetScript. But Flash will always be a gem, and Flash ActionScript is heavily based on ECMAScript with Java-style syntax and types.

In C and C++, dereferencing a null object crashes the program due to a segmentation fault. However, in Java, dereferencing/accessing a null object throws a NullPointerException.

Example[edit | edit source]

Java applets[edit | edit source]

Screenshot of an applet running.

Java applets were miniature apps written in the Java programming language that could run in the browser by a sandboxed JVM. They were used for interactive charts, 3d games, richer ui, soyence simulations, banking, and file upload / auto refreshing things. They were quickly abandoned because they could access the user's entire computer due to the constant sandbox escaping vulnerabilities, made worse if the user had the plugin run automatically.

They were replaced with Flash quickly because you can do almost everything in Flash way more easily. There was a small push to add applet support to soyjak.st, but quickly died out because it was silly. Java still is a good programming language so don't let this deter you from using it. If you want to use Java applets securely use jRunner - no plugins o algo.

Sample applet[edit | edit source]

You can test a simple calculator applet (using cheerpj js applet runner) here. Also have a look at the below applet. This applet is a horizontal navigation bar with rollover and drop-down effects. The buttons don't actually link to anything but that is possible.

The applet packages were located in java.applet and also java.awt, with extended capabilities in javax.swing. Applets were deprecated in Java 9 even though nobody uses Java 9 or above.[b]

Java applets were proposed for addition to soyjak.party but were not supported (unlike Flash) due to potential security risks.[c]

Gallery[edit | edit source]

Citations

Notes

  1. Micro Edition, a smaller version of Java for your cell
  2. because Oracle wanted developers to bundle the JRE with each application instead because people got confused when some .jar files didn't execute due to being libraries, unlike .exe and .dll being seperate. Thoughbeit Java 9 is quite gemmy as it introduces the Java Platform Module System which allows you to explicitly control what packages are public, and in Java 25 you can directly import modules.
  3. someone getting your cookies and sending it off to HTTPbin o algo
Java
is part of a series on
Soyience™

Visit the Soyence portal for more.
"We are all just hecking star dust or something!"
Peer reviewed sources [-+]
Fields of science [-+]
Science in praxis [-+]
Theoretical branches [-+]