Hello World/Graphical

<lang java> import javax.swing.*;

class helloGUI { private helloGUI() { JFrame.setDefaultLookAndFeelDecorated(true); JFrame penc=new JFrame("Elveda"); penc.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JLabel yaz=new JLabel("Goodbye, World!"); penc.getContentPane().add(yaz); penc.pack(); penc.setVisible(true); } public static void main(String[] args) { new helloGUI(); } } </lang>

Hello world/Newline omission

<lang java> class noNewline { public static void main(String[] args) { System.out.print("Goodbye, World!"); } } </lang>

Loops/While

<lang java> class whileLoop { public static void main(String[] args) { int i=1024; while (i>0) { System.out.println(i); i=i/2; } } } </lang>

Loops/Nested

<lang java> /* package whatever; // don't place package name! */

import java.util.*; import java.lang.*; import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */ class Ideone { public static void main (String[] args) throws java.lang.Exception { int i,j; int[][] ar=new int[20][20]; Random rast=new Random(); for (i=0; i<20; i++) { for (j=0; j<20; j++) { ar[i][j]=rast.nextInt(20)+1; } } System.out.println("R C"); for (i=0; i<20; i++) { for (j=0; j<20; j++) { if (ar[i][j]==20) { System.out.println(i+" "+j); break; } } } // your code goes here } } </lang>

Loops/N plus one half

<lang java> /* package whatever; // don't place package name! */

import java.util.*; import java.lang.*; import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */ class Ideone { public static void main (String[] args) throws java.lang.Exception { for (int i=1; i<=10; i++) { System.out.print(i); if (i!=10) System.out.print(", "); else System.out.println(); } // your code goes here } } </lang java>