Skip to content

Commit 525c10e

Browse files
Add files via upload
0 parents  commit 525c10e

File tree

12 files changed

+384
-0
lines changed

12 files changed

+384
-0
lines changed

FileHANDLING/IF_FILE_EXIST.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package FileHANDLING;
2+
import java.io.*;
3+
4+
public class IF_FILE_EXIST {
5+
public static void main(String[] args) {
6+
try {
7+
File obj= new File("C:File2.txt");
8+
if(obj.createNewFile()) {
9+
System.out.println("file created: "+obj.getName());
10+
System.out.println("Absolute Path: "+obj.getAbsolutePath());
11+
System.out.println("Write: "+obj.canWrite());
12+
System.out.println("Read: "+obj.canRead());
13+
}
14+
else
15+
System.out.println("file already exists.");
16+
}
17+
catch(IOException e)
18+
{
19+
System.out.println("an error occured.");
20+
e.printStackTrace();
21+
}
22+
23+
}
24+
}

FileHANDLING/READbyte.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package FileHANDLING;
2+
import java.io.FileInputStream;
3+
4+
public class READbyte {
5+
public static void main(String args[]){
6+
try{
7+
FileInputStream o= new FileInputStream("C:File1.txt");
8+
int i=o.read();
9+
System.out.print((char)i);
10+
11+
12+
i=0;
13+
while((i=o.read())!=-1){
14+
System.out.print((char)i);
15+
}
16+
17+
o.close();
18+
}catch(Exception e) {
19+
System.out.println(e);
20+
21+
} } }
22+
23+
24+

FileHANDLING/WRITEbyte.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package FileHANDLING;
2+
3+
import java.io.FileOutputStream;
4+
5+
public class WRITEbyte {
6+
public static void main(String args[]){
7+
try{
8+
FileOutputStream o=new FileOutputStream("C:File1.txt");
9+
10+
o.write(65);
11+
12+
String s="(This is the file writing in bytes.)";
13+
byte b[]=s.getBytes();
14+
o.write(b);
15+
o.close();
16+
System.out.println("SUCCESS");
17+
}
18+
catch(Exception e) {
19+
System.out.println(e);
20+
}
21+
} }

InterfaceINjava/BBQnation.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package InterfaceINjava;
2+
3+
4+
interface Veg{
5+
void PaneerTikka();
6+
}
7+
interface NonVeg {
8+
void ChickenTikka();
9+
void Biryani();
10+
void PaneerTikka();
11+
}
12+
public class BBQnation implements NonVeg , Veg {
13+
14+
public void ChickenTikka() {
15+
System.out.println("Eating Chicken Tikka");
16+
}
17+
public void Biryani() {
18+
System.out.println("Eating Biryani");
19+
}
20+
public void PaneerTikka() {
21+
System.out.println("Eating Paneer Tikka");
22+
}
23+
public void Dessert() {
24+
System.out.println("Eating Choco Lava Cake");
25+
}
26+
public static void main(String[] arg) {
27+
BBQnation o = new BBQnation();
28+
o.ChickenTikka();
29+
o.PaneerTikka();
30+
o.Biryani();
31+
o.Dessert();
32+
}
33+
}
34+
35+
36+
//methods are public / abstract /void by default and variables are public/ static / final

InterfaceINjava/Bird.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package InterfaceINjava;
2+
3+
4+
interface Animal {
5+
void eat();
6+
void sleep();
7+
}
8+
public class Bird implements Animal{
9+
public void eat(){
10+
System.out.println("Hey , i'm monkey loves to eat banana");
11+
}
12+
public void sleep(){
13+
System.out.println("Hey , i'm monkey loves to sleep on trees");
14+
}
15+
public void fly() {
16+
System.out.println("Hey , i'm bird and love to fly in the sky ");
17+
}
18+
public static void main(String[] arg) {
19+
Bird o = new Bird();
20+
o.eat();
21+
o.sleep();
22+
o.fly();
23+
}
24+
}
25+

InterfaceINjava/Dominos.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package InterfaceINjava;
2+
3+
4+
interface Pizza{
5+
void VegPizza();
6+
void NonVegPizza();
7+
}
8+
interface Sides extends Pizza{
9+
void Snacks();
10+
}
11+
interface Offers extends Sides{
12+
void Select();
13+
}
14+
public class Dominos implements Offers{
15+
public void VegPizza() {
16+
System.out.println("Veg Pizza : Farmhouse , Paneer Makhni , Peppy Paneer , Veg Loaded ");
17+
}
18+
public void NonVegPizza()
19+
{
20+
System.out.println("Non Veg Pizza : Non Veg Loaded , Chicken Dominator , Pepper Barbecue");
21+
}
22+
public void Snacks()
23+
{
24+
System.out.println("Snacks : Chicken wings , Burger , White Sauce Pasta , Shots ");
25+
}
26+
public void Select()
27+
{
28+
System.out.println(" Everyday Value offers : 2 regular@199 each ");
29+
}
30+
31+
public static void main(String[] args) {
32+
Dominos o = new Dominos();
33+
o.VegPizza();
34+
o.NonVegPizza();
35+
o.Snacks();
36+
o.Select();
37+
38+
39+
}
40+
41+
}
42+

InterfaceINjava/StudyMaterial.java

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package InterfaceINjava;
2+
3+
4+
interface Vehicle {
5+
void changeGear(int a);
6+
void speedUp(int a);
7+
void applyBrakes(int a);
8+
}
9+
10+
class Bicycle implements Vehicle{
11+
12+
int speed = 3;
13+
int gear;
14+
15+
public void changeGear(int newGear){
16+
gear = newGear;
17+
}
18+
19+
public void speedUp(int increment){
20+
speed = speed + increment;
21+
}
22+
23+
public void applyBrakes(int decrement){
24+
speed = speed - decrement;
25+
}
26+
27+
public void printStates() {
28+
System.out.println("Bicycle present state :\n"+ "speed: " + speed + " gear: " + gear);
29+
}}
30+
class Bike implements Vehicle {
31+
int speed;
32+
int gear;
33+
34+
public void changeGear(int newGear){
35+
gear = newGear;
36+
}
37+
38+
public void speedUp(int increment){
39+
speed = speed + increment;
40+
}
41+
public void applyBrakes(int decrement){
42+
speed = speed - decrement;
43+
}
44+
public void printStates() {
45+
System.out.println("Bike present state :\n"+"speed: " + speed + " gear: " + gear);
46+
}}
47+
48+
public class StudyMaterial {
49+
public static void main (String[] args) {
50+
Bicycle bicycle = new Bicycle();
51+
bicycle.changeGear(2);
52+
bicycle.speedUp(3);
53+
bicycle.applyBrakes(1);
54+
bicycle.printStates();
55+
56+
Bike bike = new Bike();
57+
bike.changeGear(1);
58+
bike.speedUp(4);
59+
bike.applyBrakes(1);
60+
bike.printStates();
61+
62+
}
63+
64+
}
65+
66+
67+

Overloading/METHOD_OVERLOAD.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package Overloading;
2+
3+
class Kulche{
4+
private String a ="Chole" ;
5+
public void start(){
6+
System.out.println(a + " Kulche");
7+
}
8+
9+
public void start(String method){
10+
this.a = method;
11+
System.out.println(a + " Kulche");
12+
}
13+
14+
}
15+
16+
public class METHOD_OVERLOAD{
17+
public static void main(String[] arg){
18+
Kulche o = new Kulche();
19+
o.start();
20+
o.start("Paneer");
21+
22+
}
23+
24+
}

Overloading/METHOD_OVERRIDE.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package Overloading;
2+
3+
class Paneer{
4+
5+
public void start(){
6+
7+
System.out.println("I love paneer tikka");
8+
9+
}
10+
11+
}
12+
13+
class Chicken extends Paneer {
14+
15+
public void start(){
16+
17+
System.out.println("I love chicken tikka ");
18+
19+
}
20+
21+
}
22+
23+
public class METHOD_OVERRIDE{
24+
public static void main(String[] arg){
25+
26+
Paneer o = new Chicken();
27+
Paneer o1 = new Paneer();
28+
o1.start();
29+
o.start();
30+
31+
}
32+
33+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package Overloading;
2+
3+
4+
5+
//Can we override java main method?
6+
//No, because the main is a static method.
7+
8+
//Can we overload java main method?
9+
//yes
10+
public class OVERLOAD_MAINmethod
11+
{
12+
public static void main(int num) {
13+
System.out.println("int * 5 = " + ( num*5) );
14+
}
15+
public static void main(int num, float var) {
16+
System.out.println("int * float = " + ( num*var) );
17+
}
18+
public static void main(String[] args) {
19+
// execution always starts from this main method
20+
main(45);
21+
main(45, 5.0f);
22+
23+
}
24+
}
25+

0 commit comments

Comments
 (0)