Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified JavaTestMahesh/bin/com/mahesh/abstraction/AbstractDemo.class
Binary file not shown.
Binary file not shown.
Binary file modified JavaTestMahesh/bin/com/mahesh/abstraction/ConcerteMethod.class
Binary file not shown.
Binary file modified JavaTestMahesh/bin/com/mahesh/abstraction/Demo2.class
Binary file not shown.
Binary file not shown.
Binary file modified JavaTestMahesh/bin/com/mahesh/encapsulation/Employ.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified JavaTestMahesh/bin/com/mahesh/inheritance/Car.class
Binary file not shown.
Binary file modified JavaTestMahesh/bin/com/mahesh/inheritance/Test.class
Binary file not shown.
Binary file modified JavaTestMahesh/bin/com/mahesh/inheritance/Vehicle.class
Binary file not shown.
Binary file modified JavaTestMahesh/bin/com/mahesh/interfaces/Interf.class
Binary file not shown.
Binary file not shown.
Binary file modified JavaTestMahesh/bin/com/mahesh/methods/MethodsExample.class
Binary file not shown.
12 changes: 8 additions & 4 deletions JavaTestMahesh/src/com/mahesh/abstraction/ConcerteMethod.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ abstract class AbstractDemo {
public void myMethod() {
System.out.println("Hello");
}

public abstract int anotherMethod(int a);
public void anotherMethod() {

public void anotherMethod() {
System.out.print("Inside Abstract method");
}
}

Expand All @@ -16,15 +18,17 @@ public void anotherMethod() {
}

public static void main(String args[]) {
// Can't create object of abstract class - error!
AbstractDemo obj = new ConcerteMethod();
obj.anotherMethod();
int dsa = obj.anotherMethod(32);
System.out.print("Abstract method" + dsa);
obj.myMethod();
}

@Override
public int anotherMethod(int a) {
// TODO Auto-generated method stub
return 0;
System.out.print("inside Auto-generated method stub");
return a;
}

}
16 changes: 8 additions & 8 deletions JavaTestMahesh/src/com/mahesh/abstraction/Demo1.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ class Demo2 extends Demo1 {
* don't declare abstract method of super class compiler would throw an
* error
*/
// public void disp2() {
// System.out.println("I'm overriding abstract method");
// }
public void disp2() {
System.out.println("I'm overriding abstract method");
}

public static void main(String args[]) {
Demo2 obj = new Demo2();
obj.disp1();
obj.disp2();
}

@Override
public void disp2() {
// TODO Auto-generated method stub

}
// @Override
// public void disp2() {
// // TODO Auto-generated method stub
//
// }
}
48 changes: 48 additions & 0 deletions JavaTestMahesh/src/com/mahesh/abstraction/FourWheeler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.mahesh.abstraction;

abstract class AbstractVehicle {
public abstract int speed();

public abstract int milage();

public abstract int brand();

public void color() {
System.out.println("i am in color");
}

public void engine() {
System.out.println("i am in engine");
}
}

class FourWheeler extends AbstractVehicle {
public void engine() {
System.out.println("i am in main engine");
}

public static void main(String[] args) {
System.out.println("main method");
AbstractVehicle dsds = new FourWheeler();
dsds.color();
dsds.speed();
dsds.engine();
}

@Override
public int speed() {
System.out.println("i am in speed");
return 0;
}

public int milage() {
System.out.println("i am in milage");
return 0;
}

@Override
public int brand() {
System.out.println("i am in brand");
return 0;
}
}
13 changes: 13 additions & 0 deletions JavaTestMahesh/src/com/mahesh/exceptionHandelling/ClassCast.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.mahesh.exceptionHandelling;

public class ClassCast {
public static void main(String[] args) {
try {
Object obj = new Integer(100);
System.out.println((float) obj);
} catch (ClassCastException e) {
System.out.println("Check the casting");
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.mahesh.exceptionHandelling;

class Parent {
public Parent() {
System.out.println("An instance of the Parent class was created!");
}
}

final class Child extends Parent {
public Child() {
super();
System.out.println("An instance of the Child class was created!");
}
}

public class ClassCastExceptionExample_v2 {
public static void main(String[] args) {
Parent p = new Parent();
Child ch = new Child();
p = ch; // This statement is not allowed.
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.mahesh.exceptionHandelling;

public class ClassNotFound {
private static final String CLASS_TO_LOAD = "com.mahesh.exceptionHandelling.ExceptionChecked";

public static void main(String[] args) {
try {
Class loadedClass = Class.forName(CLASS_TO_LOAD);
System.out.println("Class " + loadedClass + " found successfully!");
} catch (ClassNotFoundException ex) {
System.err.println("A ClassNotFoundException was caught: "
+ ex.getMessage());
ex.printStackTrace();
}
}
}
25 changes: 25 additions & 0 deletions JavaTestMahesh/src/com/mahesh/exceptionHandelling/Example.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.mahesh.exceptionHandelling;

public class Example {

private static String message = null;
private static String subMessage = null;

public Example(String message) {
Example.message = message;
}

static {
/* Store the first 10 characters of the input message. */
subMessage = message.substring(0, 10);
}

public String getSubMessage() {
return subMessage;
}

public static void main(String[] args) {
Example exampleClass = new Example("Test");
System.out.println(exampleClass.getSubMessage());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.mahesh.exceptionHandelling;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;

public class ExceptionChecked {
public static void main(String args[]) {
String content = "Hello Mahesh";
FileInputStream fis = null;
try {
fis = new FileInputStream("C:/Softgen/mahesh.txt");
} catch (FileNotFoundException fnfe) {
System.out.println("The specified file is not "
+ "present at the given path");
}
int k;
try {
File file = new File("C:/Softgen/mahesh.txt");
// if file doesnt exists, then create it
if (!file.exists()) {
file.createNewFile();
}

FileWriter fw = new FileWriter(file.getAbsoluteFile());
BufferedWriter bw = new BufferedWriter(fw);
bw.write(content);
bw.close();

System.out.println("Done");
while ((k = fis.read()) != -1) {
System.out.print((char) k);
}
fis.close();
} catch (IOException ioe) {
System.out.println("I/O error occurred: " + ioe);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.mahesh.exceptionHandelling;

import java.util.UUID;

class ExceptionInIntilizer {

private static String ID = null;

static {
ID = UUID.randomUUID().toString();
}
}
44 changes: 44 additions & 0 deletions JavaTestMahesh/src/com/mahesh/exceptionHandelling/Exceptions.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.mahesh.exceptionHandelling;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;

public class Exceptions {
public static void main(String args[]) throws IOException {
String content = "This is the content to write into file";
FileInputStream fis = null;
/*
* This constructor FileInputStream(File filename) throws
* FileNotFoundException which is a checked exception
*/
int k;
fis = new FileInputStream("C:/Softgen/mahesh.txt");
File file = new File("C:/Softgen/mahesh.txt");
// if file doesnt exists, then create it
if (!file.exists()) {
file.createNewFile();
}

FileWriter fw = new FileWriter(file.getAbsoluteFile());
BufferedWriter bw = new BufferedWriter(fw);
bw.write(content);
bw.close();

System.out.println("Done");
/*
* Method read() of FileInputStream class also throws a checked
* exception: IOException
*/
while ((k = fis.read()) != -1) {
System.out.print((char) k);
}

/*
* The method close() closes the file input stream It throws IOException
*/
fis.close();
}
}
19 changes: 19 additions & 0 deletions JavaTestMahesh/src/com/mahesh/exceptionHandelling/Finally.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.mahesh.exceptionHandelling;

public class Finally {
public static int myMethod() {
try {
// try block
System.out.println("Inside TRy block");
return 750;
} finally {
// finally
System.out.println("Inside Finally block");
return 30;
}
}

public static void main(String args[]) {
System.out.println(Finally.myMethod());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.mahesh.exceptionHandelling;

public class HandelIndexBound {
public static void main(String args[]) {
try {
int arr[] = { 1, 2, 3, 4, 5 };
System.out.println(arr[7]);
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println("The specified index does not exist "
+ "in array. Please correct the error.");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.mahesh.exceptionHandelling;

public class Illegal {

public static void main(String[] args) {
Percentage percentage = new Percentage(1290);
System.out.println(percentage.getValue());
}
}
12 changes: 12 additions & 0 deletions JavaTestMahesh/src/com/mahesh/exceptionHandelling/IndexBound.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.mahesh.exceptionHandelling;

public class IndexBound {
public static void main(String args[]) {
int arr[] = { 1, 2, 3, 4, 5 };
/*
* My array has only 5 elements but I'm trying to display the value of
* 8th element. It should throw ArrayIndexOutOfBoundsException
*/
System.out.println(arr[2]);
}
}
20 changes: 20 additions & 0 deletions JavaTestMahesh/src/com/mahesh/exceptionHandelling/MultiCatch.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.mahesh.exceptionHandelling;

public class MultiCatch {
public static void main(String args[]) {
try {
int a[] = new int[7];
a[3] = 30 / 10;
String dfs = null;
dfs.substring(23);
System.out.println("First print statement in try block");
} catch (ArithmeticException e) {
System.out.println("Warning: ArithmeticException");
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println("Warning: ArrayIndexOutOfBoundsException");
} catch (Exception e) {
System.out.println("Warning: Some Other exception");
}
System.out.println("Out of try-catch block...");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.mahesh.exceptionHandelling;

public class NUmberFormat {
public static void main(String args[]) {
try {
int num = Integer.parseInt("ABCD");
System.out.println(num);
} catch (NumberFormatException e) {
System.out.println("Number format exception occurred");
}
}
}
Loading