book done

This commit is contained in:
marguesto 2022-06-21 02:55:55 +02:00
parent ee560b550b
commit 2fdc9e494c
34 changed files with 389 additions and 0 deletions

2
.org Normal file
View File

@ -0,0 +1,2 @@
#+title: Org

5
ImageAscii.java Normal file
View File

@ -0,0 +1,5 @@
import java.awt.Color;
import java.awt.image.BufferedImage;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;

BIN
ch10/Gain.class Normal file

Binary file not shown.

31
ch10/Gain.java Normal file
View File

@ -0,0 +1,31 @@
import java.io.*;
enum Transport{
CAR(65), TRUCK(55), AIRPLANE(600), TRAIN(70), BOAT(22);
private int speed;
Transport(int s) { speed = s; }
int getSpeed() { return speed;}
}
class Gain{
public static void main(String[] args) {
PrintWriter pw = new PrintWriter(System.out, true); // true for flashing on
int i = 10;
double d = 123.65;
Transport tp, tp2, tp3;
tp = Transport.AIRPLANE;
tp2 = Transport.BOAT;
tp3 = Transport.TRAIN;
System.out.println(tp.compareTo(tp2));
System.out.println(tp2.compareTo(tp));
System.out.println(tp.compareTo(tp));
pw.println("using a printwriter");
pw.println(i);
pw.println(d);
pw.println(i + " + " + d + " is " + (i+d));
}
}

BIN
ch10/Lain.class Normal file

Binary file not shown.

13
ch10/Lain.java Normal file
View File

@ -0,0 +1,13 @@
import java.io.*;
class Lain{
public static void main(String[] args) throws IOException {
byte[] data = new byte[10];
int b;
b = 'x';
System.out.println("haeeeeeeeeeeey");
System.out.write(b);
}
}

BIN
ch10/Pain.class Normal file

Binary file not shown.

16
ch10/Pain.java Normal file
View File

@ -0,0 +1,16 @@
import java.io.*;
class Pain{
public static void main(String[] args) throws IOException {
char c; // int if we are using byteStreaming and char bc its charachter Sreamer
String str;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter Lines: and . to stop");
do {
str = br.readLine(); // readLine
System.out.println(str);
} while(! str.equals("."));
}
}

BIN
ch10/ReadBytes.class Normal file

Binary file not shown.

BIN
ch10/Transport.class Normal file

Binary file not shown.

BIN
ch10/ahmed.class Normal file

Binary file not shown.

BIN
ch10/cat.class Normal file

Binary file not shown.

36
ch10/cat.java Normal file
View File

@ -0,0 +1,36 @@
import java.io.*;
class cat{
public static void main(String[] args) {
int i;
FileInputStream fin = null;
if(args.length != 1) { // not like C2, this at least has to equal one (not two)
System.out.println("Usage: cat filename");
return;
}
try{
fin = new FileInputStream(args[0]);
} catch(FileNotFoundException ex){
System.out.println("File not found");
return;
}
try {
do{
i = fin.read();
if(i != -1) System.out.print((char) i);
} while (i != -1);
} catch(IOException ex ) {
System.out.println("Error reading the file");
}
finally{
try{
if(fin != null) fin.close();
} catch(IOException ex) {
System.out.println("error prining the file");
}
}
}
}

BIN
ch10/dub.class Normal file

Binary file not shown.

21
ch10/dub.java Normal file
View File

@ -0,0 +1,21 @@
import java.io.*;
class dub{
public static void main(String[] args) throws IOException {
int i;
if(args.length != 2) {
System.out.println("Usage: dub InputFile OutputFile");
return;
}
try(FileInputStream fin = new FileInputStream(args[0]);
FileOutputStream fout = new FileOutputStream(args[1])
){
do {
i = fin.read();
if(i != -1) fout.write(i);
} while(i != -1);
} catch( IOException ex ) {
System.out.println("IO Error");
}
}
}

BIN
ch10/ed.class Normal file

Binary file not shown.

24
ch10/ed.java Normal file
View File

@ -0,0 +1,24 @@
import java.io.*;
class ed {
public static void main(String[] args) {
String str;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter stop to quit");
try(FileWriter fw = new FileWriter("edFile")) {
do{
str = br.readLine();
if (str.compareTo("stop") == 0 ) break;
str = str + "\r\n"; // new line?
fw.write(str);
} while (str.compareTo("stop") == 0 );
} catch (IOException ex) {
System.out.println("Error");
}
}
}

1
ch10/edFile Normal file
View File

@ -0,0 +1 @@
kjgldkjgldkjg

BIN
ch10/hab.class Normal file

Binary file not shown.

28
ch10/hab.java Normal file
View File

@ -0,0 +1,28 @@
import java.io.*;
class ahmed {
void keep() {
System.out.println("ps");
}
}
class mahmoud extends ahmed {
void keep() {
System.out.println("jfsn");
}
}
class hab{
public static void main(String[] args) {
ahmed ls = new ahmed();
ls.keep();
mahmoud mem = new mahmoud();
mem.keep();
System.out.println(mem instanceof mahmoud);
System.out.println(mem instanceof ahmed);
System.out.println(ls instanceof mahmoud);
System.out.println(Integer.valueOf(434));
}
}

BIN
ch10/mahmoud.class Normal file

Binary file not shown.

BIN
ch9/Hab.class Normal file

Binary file not shown.

20
ch9/Hab.java Normal file
View File

@ -0,0 +1,20 @@
import java.io.IOException;
class Hab {
public static char prompt(String S) throws java.io.IOException {
System.out.print(S + ": ");
return(char) System.in.read();
}
public static void main(String[] args) {
char ch;
try{
ch = prompt("Enter a letter");
} catch(java.io.IOException ex) {
System.out.println("IOEx occured");
ch = 'X';
}
System.out.println("you pressed" + ch);
}
}

46
ch9/Interface.java Normal file
View File

@ -0,0 +1,46 @@
public interface MotherFucker {
public int getUserID();
default int getAdminID() {
return 1;
}
}
class MotherFuckerClass implements MotherFucker {
public int getUserID(){
return 0;
}
}
interface Const {
int MIN = 0;
int MAX = 10;
String ERRORMSG = "Boundary Error";
}
public interface Series{
int getNext();
void reset();
void setStart(int x);
}
class ByTwos implements Series {
int start;
int val;
ByTwos() {
start=0;
val=0;
}
public int getNext() { // it has to be public
val +=2;
return val;
}
public void reset() {
val = start;
}
public void setStart(int x) {
start = x;
val = x;
}
}

BIN
ch9/Lain.class Normal file

Binary file not shown.

65
ch9/Lain.java Normal file
View File

@ -0,0 +1,65 @@
class Rose extends Throwable{
static void GetIt() {
System.out.println("haeeeeey");
}
}
class Randy extends Rose {
}
class Lain{
public static void main(String[] args) {
Rose RoseObj = new Rose();
int num[] = { 13 ,34325 , 423, 42 , 53554};
int dom[] = { 13 ,4938 , 0, 2 , 4};
int dom2[] = { 13 ,4938 , 1, 2 , 4};
try {
throw RoseObj;
} catch (Rose ex) {
System.out.println("haeeey");
}
try {
for(int i=0; i< num.length; i++) {
try {
System.out.println(num[i]/ dom[i]);
} catch (ArithmeticException ex) {
System.out.println("can't divide by zero");
}
catch(Throwable ex) {
System.out.println("Some Error Happened");
}
}
} catch(ArithmeticException ex ) {
System.out.println("can't divide by zero");
} catch(Throwable ex) {
System.out.println("haeey");
}
for(int i=0; i< num.length; i++) {
try {
System.out.println(num[i]/ dom[i]);
} catch (ArithmeticException ex) {
System.out.println("can't divide by zero");
}
catch(Throwable ex) {
System.out.println("Some Error Happened");
}
}
//int nums[] = new int[4];
//
//try {
//nums[10] = 7;
//System.out.println(nums[0]);
//} catch(ArrayIndexOutOfBoundsException ex) {
//System.out.println("Array index out of boiund");
//}
//
System.out.println("Haeeeey ! ");
}
}

BIN
ch9/Package.class Normal file

Binary file not shown.

9
ch9/Package.java Normal file
View File

@ -0,0 +1,9 @@
import bookpack.*;
class Package{
static public void main(String[] args) {
System.out.println("lmaooooo ");
Book b = new Book("lolita", "nabokov", 1970);
b.show();
}
}

BIN
ch9/Randy.class Normal file

Binary file not shown.

BIN
ch9/Rose.class Normal file

Binary file not shown.

0
ch9/Try.java Normal file
View File

BIN
ch9/bookpack/Book.class Normal file

Binary file not shown.

28
ch9/bookpack/Book.java Normal file
View File

@ -0,0 +1,28 @@
package bookpack;
public class Book {
private String title;
private String author;
private int PubDate;
public Book(String t, String a, int d) {
title=t;
author=a;
PubDate=d;
}
public void show(){
System.out.println(title);
System.out.println(author);
System.out.print(PubDate);
System.out.println();
}
public static void main(String[] args) {
Book books[] = new Book[2]; // to intialize an array
books[0] = new Book("king kana", "ksjlfj", 4);
books[1] = new Book("king lama", "ksjlfj", 4);
for(Book b: books) b.show();
}
}

44
java.org Normal file
View File

@ -0,0 +1,44 @@
#+title: Java
* TODO Java [4/4]
** [X] streams
** [X] Enums
** [X] Autoboxing - Chapter 12
:LOGBOOK:
CLOCK: [2022-06-20 h 22:50]--[2022-06-20 h 23:15] => 0:25
Clock: [2022-06-20 h 20:59]--[2022-06-20 h 21:24] => 0:25
CLOCK: [2022-06-20 h 20:29]--[2022-06-20 h 20:54] => 0:25
:END:
** [X] generics - chapter 13
* general
** Overload: Different Parameters
** overrid: Same Parameters
* inheritance
* packages
* IO
** Byte Streams
*** in the top of the byte sream: InputStream and OutputStream they can .
*** System.in is an object of type InputStream.
*** System.out and System.err are objs of PrintStream.
** Characher Streams
*** Chars
**** BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); // System.in is an InputStream not a Reader so, InputStreamReader helps to convert it.
**** PrintWriter
*** Files
**** FileWriter
**** FilerReader
** FILES
*** FileInputStream
*** FileOutputStream
* Features
** Enums
** AutoBoxing and auto-unboxing
** Annotations
* Generics
** works only with Reference types aka clases.
** Types differ based on theri type arguments
** generic methods use the generic type as their paramters // it can be defined in a non-generic class.