Initial Checkin

This commit is contained in:
Joe Tretter
2023-03-02 18:06:10 -06:00
commit c1a00eea1f
19 changed files with 3550 additions and 0 deletions

View File

@@ -0,0 +1,44 @@
/*
Compile:
javac PostgreSqlExample.java
Run:
java -cp postgresql-42.5.4.jar;. PostgreSqlExample
*/
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class PostgreSqlExample {
public static void main(String[] args) {
try (Connection connection = DriverManager.getConnection("jdbc:postgresql://192.168.10.138:5432/example", "postgres", "postgres")) {
System.out.println("Java JDBC PostgreSQL Example");
// When this class first attempts to establish a connection, it automatically loads any JDBC 4.0 drivers found within
// the class path. Note that your application must manually load any JDBC drivers prior to version 4.0.
// Class.forName("org.postgresql.Driver");
System.out.println("Connected to PostgreSQL database!");
Statement statement = connection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
statement.setFetchSize(10);
System.out.println("Reading records.");
//ResultSet resultSet = statement.executeQuery("SELECT * FROM test1 a, test1 b, test1 c, test1 d, test1 e, test1 f, test1 g, test1 h, test1 i, test1 j limit (10)");
ResultSet resultSet = statement.executeQuery("SELECT * FROM test1 a, test1 b, test1 c, test1 d, test1 e, test1 f, test1 g, test1 h, test1 i, test1 j");
while (resultSet.next()) {
System.out.print(resultSet.getInt(1));
System.out.println("-"+ resultSet.getString(2));
}
} /*catch (ClassNotFoundException e) {
System.out.println("PostgreSQL JDBC driver not found.");
e.printStackTrace();
}*/ catch (SQLException e) {
System.out.println("Connection failure.");
e.printStackTrace();
}
}
}

BIN
DB/PostgreSqlExample.class Normal file

Binary file not shown.

42
DB/PostgreSqlExample.java Normal file
View File

@@ -0,0 +1,42 @@
/*
Compile:
javac PostgreSqlExample.java
Run:
java -cp postgresql-42.5.4.jar;. PostgreSqlExample
*/
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class PostgreSqlExample {
public static void main(String[] args) {
try (Connection connection = DriverManager.getConnection("jdbc:postgresql://192.168.10.138:5432/example", "postgres", "postgres")) {
System.out.println("Java JDBC PostgreSQL Example");
System.out.println("Connected to PostgreSQL database!");
Statement statement = connection.createStatement();
// For huge resultset the following two lines do the trick:
statement.setFetchSize(100);
connection.setAutoCommit(false);
System.out.println("Reading records.");
//ResultSet resultSet = statement.executeQuery("SELECT * FROM test1 a, test1 b, test1 c, test1 d, test1 e, test1 f, test1 g, test1 h, test1 i, test1 j limit (10)");
// Produce HUGE resultest
ResultSet resultSet = statement.executeQuery("SELECT * FROM test1 a, test1 b, test1 c, test1 d, test1 e, test1 f, test1 g, test1 h, test1 i, test1 j");
while (resultSet.next()) {
System.out.print(resultSet.getInt(1));
System.out.println("-"+ resultSet.getString(2));
}
} catch (SQLException e) {
System.out.println("Connection failure.");
e.printStackTrace();
}
}
}

BIN
DB/postgresql-42.5.4.jar Normal file

Binary file not shown.

BIN
FinalFlag1.class Normal file

Binary file not shown.

9
FinalFlag1.java Normal file
View File

@@ -0,0 +1,9 @@
class FinalFlag1{
private String x;
public FinalFlag1(){
x="Final?";
}
public final void test(){
System.out.println(x);
}
}

20
HashMapTest1.java Normal file
View File

@@ -0,0 +1,20 @@
import java.util.*;
public class HashMapTest1 {
public static void main(String []args) {
String string1= "ABFED";
String string2= "AFBHI";
HashMap<Character,Boolean> hm1 = new HashMap<>();
for (char theChar : string1.toCharArray()){
hm1.put(theChar ,false);
}
for (char theChar : string2.toCharArray()){
if (hm1.containsKey(theChar)) {
System.out.print(theChar);
}
}
}
}

BIN
LinkedList1.class Normal file

Binary file not shown.

57
LinkedList1.java Normal file
View File

@@ -0,0 +1,57 @@
public class LinkedList1 {
public static void main(String []args) {
MyLinkedListElement le1 = new MyLinkedListElement();
le1.setData("Data1");
MyLinkedListElement le2 = new MyLinkedListElement();
le2.setData("Data2");
le1.setNextElement(le2);
MyLinkedListElement le3 = new MyLinkedListElement();
le3.setData("Data3");
le2.setNextElement(le3);
MyLinkedListElement x = new MyLinkedListElement();
x.setData("DataX");
le1.setNextElement(x);
x.setNextElement(le2);
eleTest(le1);
}
public static void eleTest(MyLinkedListElement ele){
while (ele != null){
System.out.println(ele.getData());
ele = ele.getNextElement();
}
}
}
class MyLinkedListElement {
private String data;
private MyLinkedListElement nextElement;
public MyLinkedListElement getNextElement() {
return nextElement;
}
public void setNextElement(MyLinkedListElement nextElement) {
this.nextElement = nextElement;
}
public String getData() {
return data;
}
public void setData(String data) {
this.data = data;
}
}

BIN
MyLinkedListElement.class Normal file

Binary file not shown.

29
NF Normal file
View File

@@ -0,0 +1,29 @@
00000000: cafe babe 0000 0037 0020 0a00 0700 1108 .......7. ......
00000010: 0012 0900 0600 1309 0014 0015 0a00 1600 ................
00000020: 1707 0018 0700 1901 0001 7801 0012 4c6a ..........x...Lj
00000030: 6176 612f 6c61 6e67 2f53 7472 696e 673b ava/lang/String;
00000040: 0100 063c 696e 6974 3e01 0003 2829 5601 ...<init>...()V.
00000050: 0004 436f 6465 0100 0f4c 696e 654e 756d ..Code...LineNum
00000060: 6265 7254 6162 6c65 0100 0474 6573 7401 berTable...test.
00000070: 000a 536f 7572 6365 4669 6c65 0100 0f46 ..SourceFile...F
00000080: 696e 616c 466c 6167 312e 6a61 7661 0c00 inalFlag1.java..
00000090: 0a00 0b01 0006 4669 6e61 6c3f 0c00 0800 ......Final?....
000000a0: 0907 001a 0c00 1b00 1c07 001d 0c00 1e00 ................
000000b0: 1f01 000a 4669 6e61 6c46 6c61 6731 0100 ....FinalFlag1..
000000c0: 106a 6176 612f 6c61 6e67 2f4f 626a 6563 .java/lang/Objec
000000d0: 7401 0010 6a61 7661 2f6c 616e 672f 5379 t...java/lang/Sy
000000e0: 7374 656d 0100 036f 7574 0100 154c 6a61 stem...out...Lja
000000f0: 7661 2f69 6f2f 5072 696e 7453 7472 6561 va/io/PrintStrea
00000100: 6d3b 0100 136a 6176 612f 696f 2f50 7269 m;...java/io/Pri
00000110: 6e74 5374 7265 616d 0100 0770 7269 6e74 ntStream...print
00000120: 6c6e 0100 1528 4c6a 6176 612f 6c61 6e67 ln...(Ljava/lang
00000130: 2f53 7472 696e 673b 2956 0020 0006 0007 /String;)V. ....
00000140: 0000 0001 0002 0008 0009 0000 0002 0001 ................
00000150: 000a 000b 0001 000c 0000 002b 0002 0001 ...........+....
00000160: 0000 000b 2ab7 0001 2a12 02b5 0003 b100 ....*...*.......
00000170: 0000 0100 0d00 0000 0e00 0300 0000 0300 ................
00000180: 0400 0400 0a00 0500 0100 0e00 0b00 0100 ................
00000190: 0c00 0000 2700 0200 0100 0000 0bb2 0004 ....'...........
000001a0: 2ab4 0003 b600 05b1 0000 0001 000d 0000 *...............
000001b0: 000a 0002 0000 0007 000a 0008 0001 000f ................
000001c0: 0000 0002 0010 ......

19
RefAndVal1.java Normal file
View File

@@ -0,0 +1,19 @@
public class RefAndVal1 {
public static void main(String[] argv ){
int i=7;
String s="Hello";
String[] sa ={"HelAlo"};
test (i,s,sa);
System.out.println(i);
System.out.println(s);
System.out.println(sa[0]);
}
public static void test(int i, String s, String[] sa){
i +=7;
s += "X";
sa[0] += "X";
}
}

BIN
RefAndVal2.class Normal file

Binary file not shown.

12
RefAndVal2.java Normal file
View File

@@ -0,0 +1,12 @@
public class RefAndVal2 {
public static void main(String[] argv ){
String s="Hello";
test (s);
System.out.println(s);
}
public static String test( String s){
s += "X";
return s;
}
}

BIN
RefAndVal3.class Normal file

Binary file not shown.

25
RefAndVal3.java Normal file
View File

@@ -0,0 +1,25 @@
public class RefAndVal3 {
public static void main(String[] argv ){
String s="HHH";
String t=s;
System.out.println("A: _" + s + "_ -> " + (t.equals(s)) + "/" + (t==s));
s="H".substring(0)+"H"+"H";
System.out.println("B: _" + s + "_ -> " + (t.equals(s)) + "/" + (t==s));
s="HHH".replace("HHH", "HHH");
System.out.println("C: _" + s + "_ -> " + (t.equals(s)) + "/" + (t==s));
s="H"+"H".concat("H");
System.out.println("D: _" + s + "_ -> " + (t.equals(s)) + "/" + (t==s));
s="H" + "H" + "H";
System.out.println("E: _" + s + "_ -> " + (t.equals(s)) + "/" + (t==s));
s="HHH".concat("");
System.out.println("F: _" + s + "_ -> " + (t.equals(s)) + "/" + (t==s));
s="HHH".replace("", "");
System.out.println("G: _" + s + "_ -> " + (t.equals(s)) + "/" + (t==s));
}
}

3243
RefAndVal4.java Normal file

File diff suppressed because it is too large Load Diff

21
SetTest1.java Normal file
View File

@@ -0,0 +1,21 @@
import java.util.*;
class SetTest1{
public static void main(String []args) {
String string1= "ABFED";
String string2= "AFBHI";
Set<Character> set1 = string2CharSet(string1);
set1.retainAll(string2CharSet(string2));
System.out.println(set1.toString());
}
private static Set<Character> string2CharSet(String s1) {
Set<Character> set1=new HashSet<Character>();
Character[] cha1 = s1.chars().mapToObj(c -> (char) c).toArray(Character[]::new);
set1.addAll(Arrays.asList(cha1));
return set1;
}
}

29
WF Normal file
View File

@@ -0,0 +1,29 @@
00000000: cafe babe 0000 0037 0020 0a00 0700 1108 .......7. ......
00000010: 0012 0900 0600 1309 0014 0015 0a00 1600 ................
00000020: 1707 0018 0700 1901 0001 7801 0012 4c6a ..........x...Lj
00000030: 6176 612f 6c61 6e67 2f53 7472 696e 673b ava/lang/String;
00000040: 0100 063c 696e 6974 3e01 0003 2829 5601 ...<init>...()V.
00000050: 0004 436f 6465 0100 0f4c 696e 654e 756d ..Code...LineNum
00000060: 6265 7254 6162 6c65 0100 0474 6573 7401 berTable...test.
00000070: 000a 536f 7572 6365 4669 6c65 0100 0f46 ..SourceFile...F
00000080: 696e 616c 466c 6167 312e 6a61 7661 0c00 inalFlag1.java..
00000090: 0a00 0b01 0006 4669 6e61 6c3f 0c00 0800 ......Final?....
000000a0: 0907 001a 0c00 1b00 1c07 001d 0c00 1e00 ................
000000b0: 1f01 000a 4669 6e61 6c46 6c61 6731 0100 ....FinalFlag1..
000000c0: 106a 6176 612f 6c61 6e67 2f4f 626a 6563 .java/lang/Objec
000000d0: 7401 0010 6a61 7661 2f6c 616e 672f 5379 t...java/lang/Sy
000000e0: 7374 656d 0100 036f 7574 0100 154c 6a61 stem...out...Lja
000000f0: 7661 2f69 6f2f 5072 696e 7453 7472 6561 va/io/PrintStrea
00000100: 6d3b 0100 136a 6176 612f 696f 2f50 7269 m;...java/io/Pri
00000110: 6e74 5374 7265 616d 0100 0770 7269 6e74 ntStream...print
00000120: 6c6e 0100 1528 4c6a 6176 612f 6c61 6e67 ln...(Ljava/lang
00000130: 2f53 7472 696e 673b 2956 0020 0006 0007 /String;)V. ....
00000140: 0000 0001 0002 0008 0009 0000 0002 0001 ................
00000150: 000a 000b 0001 000c 0000 002b 0002 0001 ...........+....
00000160: 0000 000b 2ab7 0001 2a12 02b5 0003 b100 ....*...*.......
00000170: 0000 0100 0d00 0000 0e00 0300 0000 0300 ................
00000180: 0400 0400 0a00 0500 1100 0e00 0b00 0100 ................
00000190: 0c00 0000 2700 0200 0100 0000 0bb2 0004 ....'...........
000001a0: 2ab4 0003 b600 05b1 0000 0001 000d 0000 *...............
000001b0: 000a 0002 0000 0007 000a 0008 0001 000f ................
000001c0: 0000 0002 0010 ......