book done
This commit is contained in:
parent
ee560b550b
commit
2fdc9e494c
|
@ -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;
|
Binary file not shown.
|
@ -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));
|
||||
}
|
||||
}
|
Binary file not shown.
|
@ -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);
|
||||
}
|
||||
}
|
Binary file not shown.
|
@ -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("."));
|
||||
}
|
||||
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Binary file not shown.
|
@ -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");
|
||||
}
|
||||
}
|
||||
}
|
Binary file not shown.
|
@ -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");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
kjgldkjgldkjg
|
Binary file not shown.
|
@ -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));
|
||||
}
|
||||
}
|
Binary file not shown.
Binary file not shown.
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
Binary file not shown.
|
@ -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 ! ");
|
||||
}
|
||||
}
|
Binary file not shown.
|
@ -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();
|
||||
}
|
||||
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
@ -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.
|
Loading…
Reference in New Issue