2947 (input)

byte/short/int/long/float/double/string/char eingabe-/input-class in java:

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

//package iotool
//readByte
//readShort
//readInt
//readLong
//readFloat
//readDouble
//readString
//readChar

public class eingabe {

//read-Byte-Methode	
	public static byte readByte(String inText) {

			byte        	bZahl ;
			BufferedReader br;

//Eingabepuffer für eine Dateneingabe neu erstellen
		  	br = new BufferedReader(new InputStreamReader(System.in));
		  	bZahl = 0;
		  	System.out.print(inText);
		  	try {
				bZahl= Byte.parseByte(br.readLine());
		  	} 
		  	catch (NumberFormatException e) {
				System.out.println("Exception geworfen, kein Byte.");
		  	} 
		  	catch (IOException e) {
				e.printStackTrace();
		  	}	
			return bZahl;
	}

//read-Short-Methode	
	public static short readShort(String inText) {

			short        	sZahl ;
			BufferedReader br;

//Eingabepuffer für eine Dateneingabe neu erstellen
		  	br = new BufferedReader(new InputStreamReader(System.in));
		  	sZahl = 0;
		  	System.out.print(inText);
		  	try {
				sZahl= Short.parseShort(br.readLine());
		  	} 
		  	catch (NumberFormatException e) {
				System.out.println("Exception geworfen, kein Short.");
		  	} 
		  	catch (IOException e) {
				e.printStackTrace();
		  	}	
			return sZahl;
	}

//read-Integer-Methode	
	public static int readInt(String inText) {

			int        	iZahl ;
			BufferedReader br;

//Eingabepuffer für eine Dateneingabe neu erstellen
		  	br = new BufferedReader(new InputStreamReader(System.in));
			iZahl = 0;
		  	System.out.print(inText);
		  	try {
				iZahl= Integer.parseInt(br.readLine());
		  	} 
		  	catch (NumberFormatException e) {
				System.out.println("Exception geworfen, kein Integer.");
		  	} 
		  	catch (IOException e) {
				e.printStackTrace();
		  	}	
			return iZahl;
	}

//read-Long-Methode	
	public static long readLong(String inText) {

			long        	lZahl ;
			BufferedReader br;

//Eingabepuffer für eine Dateneingabe neu erstellen
		  	br = new BufferedReader(new InputStreamReader(System.in));
		  	lZahl = 0;
		  	System.out.print(inText);
		  	try {
				lZahl= Long.parseLong(br.readLine());
		  	} 
		  	catch (NumberFormatException e) {
				System.out.println("Exception geworfen, kein Long.");
		  	} 
		  	catch (IOException e) {
				e.printStackTrace();
		  	}	
			return lZahl;
	}

//read-Float-Methode	
	public static float readFloat(String inText) {
	 
			float   fZahl ;
			BufferedReader br;

//Eingabepuffer für eine Dateneingabe neu erstellen
		  	br = new BufferedReader(new InputStreamReader(System.in));
		  	fZahl = 0;
		  	System.out.print(inText);
		  	try {
				fZahl= Float.parseFloat(br.readLine());
		  	} 
		  	catch (NumberFormatException e) {
				System.out.println("Exception geworfen, kein float.");
		  	} 
		  	catch (IOException e) {
				e.printStackTrace();
		  	}	
			return fZahl;
	}

//read-Double-Methode	
	public static double readDouble(String inText) {
	 
			double   dZahl ;
			BufferedReader br;

//Eingabepuffer für eine Dateneingabe neu erstellen
		  	br = new BufferedReader(new InputStreamReader(System.in));
		  	dZahl = 0;
		  	System.out.print(inText);
		  	try {
				dZahl= Double.parseDouble(br.readLine());
		  	} 
		  	catch (NumberFormatException e) {
				System.out.println("Exception geworfen, kein double.");
		  	} 
		  	catch (IOException e) {
				e.printStackTrace();
		  	}	
			return dZahl;
	}

//read-String-Methode	
	public static String readString(String inText) {
		
		  String   sText ;
		  BufferedReader br;

//Eingabepuffer für eine Dateneingabe neu erstellen
	  	br = new BufferedReader(new InputStreamReader(System.in));
	  	
	  	sText = "";
	  	System.out.print(inText);
	  	try {
	  		 sText= (br.readLine());
		  }
	  	catch (IOException e) {
			 e.printStackTrace();
		  }	
		  return sText;
	}

//read-Character-Methode
	public static char readChar(String inText) {

		   char  cZeichen ='0';
		   System.out.print(inText);
		   try {
		   		do{
		   			cZeichen =(char) System.in.read();
		   		}
		   		while(cZeichen == '\n' | cZeichen =='\r');
		   }
		   catch (IOException e) {
          	e.printStackTrace();
		   }	   
		   return cZeichen;
	}
}
//found @ coderz-home.de, modified by ewing 20150131

2943 (backwards)

even beginners should understand this little piece of java-code, that turns a given string right to left.

class backwards {
	public static void main(String[] args) {
		String s = "", charout = "";
		int l = 0, i = 0, position = 0;
		s = eingabe.readString("String:");
		l = s.length();
		for (i=l;i>0;i--) {
			charout = s.substring (i-1,i);
			System.out.print(charout);
		}
		System.out.println();
	}	
}

2928 (java class version checker)

the following code will check a java class for validity and version.

import java.io.*;

public class cvc {
    public static void main(String[] args) throws IOException {
        for (int i = 0; i < args.length; i++)
            checkClassVersion(args[i]);
    }

    private static void checkClassVersion(String filename)
        throws IOException
    {
        DataInputStream in = new DataInputStream
         (new FileInputStream(filename));

        int magic = in.readInt();
        if(magic != 0xcafebabe) {
          System.out.println(filename + " is not a valid class!");;
        }
        int minor = in.readUnsignedShort();
        int major = in.readUnsignedShort();
        System.out.println(filename + ": " + major + " . " + minor);
        in.close();
    }
}
/*
major  minor Java platform version 
45       3           1.0
45       3           1.1
46       0           1.2
47       0           1.3
48       0           1.4
49       0           1.5
50       0           1.6
51       0           1.7
52       0           1.8
*/

2898 (top tags)

2 5 Ameisenbär Andrew Vachss Apache Arbeit Arzt auto beer bernie Bielefeld Bier Blog Buch bus Computer configedit dark shadow database debian Delphin Enger erlenweg evering ewing experienced involvement facebook fahrrad Fledermaus Forum Forum Bielefeld Frosch Gary Floyd Geld Giraffe google grizzly hamburg Herford Internet java Jesus Kaffee librarything Linux Love maulwurfine Maurie max mind mond money music Musik Mysql Neues Forum Enger octopus Peace Php physik psychiatrie San Francisco serverproject serverproject.de sister double happiness slitaz Spinne tag telefon typo3 vachss windmühle work www xmas

your first one

public class hello_world
//this is a comment: case sensitive
{
public static void main (String[] args)
{
System.out.println(“Hello World”);
//this is a comment: simple print-command, would be echo in php
}
}
unter filename ‘hello_world.java’ abspeichern
commandline:
javac hello_world.java
java hello_world

some keys

#

#


the following javaprogram reads any keypress without Enter and its output is the key and its asciivalue in brackets. as precaution jcurses has to be properly set up. ctrl-c or ‘#’ ends the program. only the input is coded, a simple System.out.println serves as output. as processing of the values nearly anything can be imagined.

import jcurses.system.InputChar;
import jcurses.system.Toolkit;

public class readchar3 {
public static void main (String[] args)
{
String st;
char ch;
int i;
st = “”;
ch = ‘ ‘;
i = 0;
while (true)
{
InputChar c = Toolkit.readCharacter();
ch = c.getCharacter();
i = (int) ch;
System.out.print (“you typed ” + ch + “(” + i + “)\n\r”);
// break on ‘#’
if (ch == ‘#’) break;
}
System.out.println (“Programm wird beendet. Verarbeitung kann beginnen.”);
}
}
—-
https://www.minds.com/blog/view/487276494029070336/some-keys
https://minds.com/ewing

body of j2_app.java

class j2_app {
public static void main (String[] args) {
int menueingabe;
char t_input;
String tabelle;
menueingabe = 0;
while (menueingabe != 5) {
do {
System.out.println (“1 Datensatz anlegen\n2 Datensatz bearbeiten\n3 Datensatz loeschen\n4 Tabelle anzeigen\n5 Programm beenden\n”);
try {
menueingabe = eingabe.readInt(“Ihre Wahl:”);
}
catch (NumberFormatException e) {
System.out.println(“NumberFormatException in main”);
}
} while ((menueingabe != 1) && (menueingabe != 2) && (menueingabe != 3) && (menueingabe != 4) && (menueingabe != 5));
if (menueingabe != 5) {
do {
System.out.println (“Tabelle:\ns server\nu user\n”);
t_input = eingabe.readChar (“Ihre Wahl:”);
} while ((t_input != (‘s’)) && (t_input != (‘u’)));
switch (t_input){
case ‘s’ : tabelle = “server”; break;
case ‘u’ : tabelle = “user”; break;
default: tabelle = “not_defined”;
System.out.println (“caught”);
}
switch (menueingabe) {
case 1: System.out.println(“eins”);
System.out.println (tabelle);
if (t_input==’s’) {
}
else {
}
break;
case 2: System.out.println (“zwei”);
System.out.println (tabelle);
if (t_input==’s’) {
}
else {
}
break;
case 3: System.out.println (“drei”);
System.out.println (tabelle);
if (t_input==’s’) {
}
else {
}
break;
case 4: System.out.println (“vier”);
System.out.println (tabelle);
if (t_input==’s’) {
}
else {
}
break;
default: System.out.println(“caught”);
}
}
System.out.println();
}
System.out.println (“Programm wird beendet”);
}
}