SNCA:Java

From Soyjak Wiki, the free ensoyclopedia
Jump to navigationJump to search
WARNING: WORDSWORDSWORDS
This page or section is just one big wall of text.
Why yes, Java is a gigachad.
How could you tell?
Java mascot, Duke, as an jak.
It's NullPointerException.
>we code hard in these cubicles

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. You probably also used it for playing Java ME[a] games on your dad's cell phone.

More about Java[edit | edit source]

It enforces the object-oriented programming paradigm, 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. It is based on C++. It is also very similar to C#, which itself is based on Java and is the language of a lot of slop game engines such as Unity and Godot. It has always been quite popular in America, with Python only overtaking it in recent years.[3] Sadly, it is also associated with Pajeets because a lot of pajeets 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.

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]

Note that in Java, the package java.lang is implicitly imported. So, writing import java.lang.*; is not necessary.

package party.soyjak.example;

import java.util.Random;

/**
 * A simple program to decide whether to ack.
 * Java 21 or higher required due to `Math.clamp` method.
 */
public class Tranny {
    private static final Random rand = new Random();

    /**
     * Determines whether the tranny should ack based on a given probability.
     *
     * @param ackProbability An integer between 0 and 100 representing the chance of acking.
     * @return True if the random probability is less than the ackProbability; otherwise, False.
     */
    private static boolean shouldAck(int ackProbability) {
        double prob = rand.nextDouble() * 100;
        return prob < Math.clamp(ackProbability, 0, 100);
    }

    /**
     * Main function that decides whether to ack or scream TRANS RIGHTS ARE HUMAN RIGHTS!!!!!!!! based on probability.
     *
     * @param args An array of command line arguments.
     * @return Whether the program executed successfully.
     */
    public static void main(String[] args) {
        if (shouldAck(41)) {
            throw new RuntimeException("ACK!!!!");
        } else {
            System.out.println("TRANS RIGHTS ARE HUMAN RIGHTS!!!!!!!!");
        }
    }
}

Java applets[edit | edit source]

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]

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.

package party.soyjak.example;

import java.awt.*;
import java.awt.event.*;
import javax.swing.JApplet;

public class SunMenuApplet extends JApplet implements MouseListener, MouseMotionListener {
    private static final int MENU_ITEM_WIDTH = 100;
    private static final int MENU_ITEM_HEIGHT = 30;
    private static final int SUB_ITEM_HEIGHT = 20;

    private final String[] menuItems = {"Imageboard", "Wiki", "Booru"};
    private final String[][] subItems = {
        {"Index", "/soy/", "rules", "pass", "bans"},
        {"Recent Changes", "Watchlist", "Notifications"},
        {"The Dailyjak", "Your shit posts"}
    };

    private int hoverMenu = -1;
    private int hoverSub = -1;

    private int getMenuIndex(int x) {
        return (x >= 0 && x < menuItems.length * MENU_ITEM_WIDTH) ? x / MENU_ITEM_WIDTH : -1;
    }

    private int getSubIndex(int y) {
        if (hoverMenu == -1) {
            return -1;
        }

        int subY = y - MENU_ITEM_HEIGHT;
        return (subY >= 0 && subY < subItems[hoverMenu].length * SUB_ITEM_HEIGHT) ? subY / SUB_ITEM_HEIGHT : -1;
    }

    @Override
    public void init() {
        addMouseListener(this);
        addMouseMotionListener(this);
    }

    @Override
    public void paint(Graphics g) {
        g.setColor(Color.LIGHT_GRAY);
        g.fillRect(0, 0, size().width, MENU_ITEM_HEIGHT);
=
        for (int i = 0; i < menuItems.length; i++) {
            int x = i * MENU_ITEM_WIDTH;

            if (i == hoverMenu) {
                g.setColor(Color.GRAY);
                g.fillRect(x, 0, MENU_ITEM_WIDTH, MENU_ITEM_HEIGHT);
            }

            g.setColor(Color.BLACK);
            g.drawRect(x, 0, MENU_ITEM_WIDTH, MENU_ITEM_HEIGHT);
            g.drawString(menuItems[i], x + 10, SUB_ITEM_HEIGHT);
        }

        if (hoverMenu != -1) {
            int menuX = hoverMenu * MENU_ITEM_WIDTH;
            int menuY = MENU_ITEM_HEIGHT;
            int subHeight = subItems[hoverMenu].length * SUB_ITEM_HEIGHT;

            g.setColor(Color.WHITE);
            g.fillRect(menuX, menuY, MENU_ITEM_WIDTH, subHeight);
            g.setColor(Color.BLACK);
            g.drawRect(menuX, menuY, MENU_ITEM_WIDTH, subHeight);

            for (int j = 0; j < subItems[hoverMenu].length; j++) {
                int y = menuY + j * SUB_ITEM_HEIGHT;

                if (j == hoverSub) {
                    g.setColor(Color.LIGHT_GRAY);
                    g.fillRect(menuX + 1, y + 1, MENU_ITEM_WIDTH - 2, SUB_ITEM_HEIGHT - 2);
                    g.setColor(Color.BLACK);
                }

                g.drawRect(menuX, y, MENU_ITEM_WIDTH, SUB_ITEM_HEIGHT);
                g.drawString(subItems[hoverMenu][j], menuX + 5, y + 15);
            }
        }
    }

    @Override
    public void mouseMoved(MouseEvent e) {
        int mx = e.getX();
        int my = e.getY();
        int newHoverMenu = getMenuIndex(mx);
        int newHoverSub = getSubIndex(my);

        if (newHoverMenu != hoverMenu || newHoverSub != hoverSub) {
            hoverMenu = newHoverMenu;
            hoverSub = newHoverSub;
            repaint();
        }
    }

    @Override
    public void mouseExited(MouseEvent e) {
        hoverMenu = -1;
        hoverSub = -1;
        repaint();
    }

    @Override
    public void mouseClicked(MouseEvent e) {
        if (hoverMenu != -1 && hoverSub != -1) {
            System.out.println("Clicked: " + subItems[hoverMenu][hoverSub]);
        }
    }

    @Override
    public void mouseDragged(MouseEvent e) {
        // Left unimplemented
    }

    @Override
    public void mouseEntered(MouseEvent e) {
        // Left unimplemented
    }

    @Override
    public void mousePressed(MouseEvent e) {
        // Left unimplemented
    }

    @Override
    public void mouseReleased(MouseEvent e) {
        // Left unimplemented
    }
}

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]

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.
  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 [-+]