forked from dipraj-howlader/java-other-advance
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 54ced17
Showing
18 changed files
with
381 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package Access_modifier; | ||
|
||
public class A { | ||
public void display() { | ||
System.out.println("HI I am private"); | ||
} | ||
protected void display2() { | ||
System.out.println("Hi I am protected"); | ||
} | ||
|
||
void nothing() { | ||
System.out.println("Default, We can only use in Same package"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package Access_modifier; | ||
|
||
public class B { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package Access_modifier; | ||
|
||
public class C { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package Access_modifier; | ||
|
||
public class test { | ||
public static void main(String[] args) { | ||
A a = new A(); | ||
a.display(); | ||
a.display2(); | ||
a.nothing(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package Access_modifier2; | ||
|
||
import Access_modifier.A; | ||
|
||
public class CC extends A { | ||
public static void main(String[] args) { | ||
CC aa= new CC(); | ||
aa.display(); | ||
aa.display2(); | ||
// aa.nothing(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package ExpressionHandaling; | ||
|
||
import java.io.File; | ||
|
||
public class A { | ||
|
||
// expection handaling | ||
// - Runtime Error means expection | ||
|
||
int x = 10; | ||
int y = 0; | ||
int z= x / y; | ||
// Arithmetic expection | ||
|
||
String name = null; | ||
char name2 = name.charAt(0); | ||
//Null pointer expection | ||
|
||
String name3 = "Dipraj"; | ||
char name4 = name3.charAt(9); | ||
// String Index Out Of Bounds Expection | ||
|
||
int num = Integer.parseInt("DIPURAJ"); | ||
// NumberFormet expection | ||
|
||
File file = new File("../..///"); | ||
//File not Found expection | ||
|
||
int[] a = new int[5]; | ||
a[5] = 32; | ||
//Array INdex Out of bOund expection | ||
|
||
// What is expection handling | ||
// Handling runtime ERROR | ||
|
||
// try | ||
// catch | ||
// finally | ||
// throw | ||
// throws | ||
//this keywords are used to handle expection | ||
|
||
try { | ||
|
||
//code you want to monitor | ||
// or maybe the code can show expection error | ||
//if any expection will have found than try will throw it to the FIRST CATCH | ||
} | ||
catch( /* expection type e1 */ ) { | ||
//Exception handler for expection | ||
} | ||
catch( /* expection type e2 */ ) | ||
{ | ||
//Exception handler for expection //Exception handler for expection | ||
} | ||
finally { | ||
// block of code to be executed after try block | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package ExpressionHandaling; | ||
|
||
public class ExpectionDemo { | ||
public static void main(String[] args) { | ||
|
||
try { | ||
int x = 10; | ||
int y = 0; | ||
int result = x/y; | ||
System.out.println(result); | ||
} | ||
|
||
catch(ArrayIndexOutOfBoundsException e) { | ||
System.out.println("Expection : "+e); | ||
} | ||
catch(ArithmeticException e) { | ||
System.out.println("Expection : "+e); | ||
} | ||
|
||
finally { | ||
System.out.println("Vai jani nah ki vul hocie"); | ||
} | ||
|
||
|
||
System.out.println("Last line of the program"); | ||
|
||
//Another | ||
|
||
try { | ||
int [] a = new int[4]; | ||
a[4] = 5; | ||
|
||
} | ||
catch(ArrayIndexOutOfBoundsException e1) { | ||
System.out.println("Expection : "+e1); | ||
} | ||
catch(Exception e2) { | ||
System.out.println("Expection : "+e2); | ||
} | ||
finally { | ||
System.out.println("Last line of the program"); | ||
} | ||
|
||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package HashSett; | ||
|
||
import java.util.HashSet; | ||
|
||
public class HashSetDemo { | ||
public static void main(String[] args) { | ||
|
||
HashSet<String> fruits = new HashSet<String>(); | ||
|
||
fruits.add("Alu"); | ||
fruits.add("Orange"); | ||
fruits.add("Banana"); | ||
|
||
System.out.println(fruits); | ||
System.out.println(fruits.size()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package Hashmap; | ||
|
||
import java.util.HashMap; | ||
|
||
public class Hashmapp { | ||
public static void main(String[] args) { | ||
|
||
HashMap<Integer, String> customar = new HashMap<Integer, String>(); | ||
|
||
//put get | ||
customar.put(101, "Dipraj"); | ||
customar.put(102, "Sunu"); | ||
customar.put(130, "Anu"); | ||
|
||
|
||
System.out.println(customar.get(102)); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package LinkedList; | ||
|
||
import java.util.LinkedList; | ||
|
||
public class LinkEDLIST { | ||
|
||
public static void main(String[] args) { | ||
|
||
LinkedList<String> countryName = new LinkedList<String>(); | ||
|
||
countryName.add("Bangladesh"); | ||
countryName.add("India"); | ||
countryName.add("Pakistan"); | ||
countryName.add("China"); | ||
|
||
countryName.add(4, "Japan"); | ||
countryName.add(5, "Argentina"); | ||
|
||
countryName.addFirst("USA"); | ||
countryName.addLast("Afganistan"); | ||
|
||
for(String x : countryName) { | ||
System.out.println(x); | ||
} | ||
|
||
countryName.remove(5); | ||
countryName.removeFirst(); | ||
|
||
|
||
System.out.println(countryName); | ||
System.out.println("Size of the list : " + countryName.size()); | ||
|
||
System.out.println( "5 " + "Element is : "+countryName.get(5)); | ||
|
||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package LinkedList; | ||
|
||
public class StudentList { | ||
|
||
String name ,className; | ||
int id; | ||
|
||
StudentList(int id, String name, String className){ | ||
this.id = id; | ||
this.name = name; | ||
this.className = className; | ||
|
||
} | ||
|
||
@Override | ||
|
||
public String toString(){ | ||
return "ID : " + id + ", Name : " + name + ", Class : " + className; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package LinkedList; | ||
|
||
import java.util.LinkedList; | ||
|
||
public class StudentListDemo { | ||
public static void main(String[] args) { | ||
// student link list | ||
|
||
LinkedList<StudentList> list = new LinkedList<StudentList>(); | ||
|
||
|
||
// student create | ||
|
||
StudentList s1 = new StudentList(1, "Dipraj", "XI"); | ||
StudentList s2 = new StudentList(2, "Sun", "XII"); | ||
StudentList s3 = new StudentList(3 , "Ayaon", "V"); | ||
StudentList s4 = new StudentList(4, "Avro", "I"); | ||
|
||
// adding student | ||
|
||
list.add(s1); | ||
list.add(s2); | ||
list.add(s3); | ||
list.add(s4); | ||
|
||
for(StudentList o : list) { | ||
System.out.println(o); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package StringComparison; | ||
|
||
public class Compare1 { | ||
|
||
public static void main(String[] args) { | ||
//equals() | ||
//Compares the original content of the string | ||
|
||
String password1 = "Dipraj"; | ||
String password2 = "Dipraj"; | ||
String pass3 = new String("Dipraj"); | ||
String pass4 = new String("Dipraj"); | ||
|
||
System.out.println(pass3.equals(pass4)); | ||
// == compare the reference of the objects not the value | ||
System.out.println(password1 == password2); //true | ||
System.out.println(password1 == pass3); // false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package ToStringMethod; | ||
|
||
public class Person { | ||
|
||
// to string method | ||
String name; | ||
int age; | ||
Person(String name, int age ){ | ||
this.age = age; | ||
this.name = name; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Name : " + name + "\n" + "Age : "+ age; | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package ToStringMethod; | ||
|
||
public class test { | ||
public static void main(String[] args) { | ||
|
||
Person p1 =new Person("Dipraj",56); | ||
Person p2 = new Person("Minhaj", 89); | ||
System.out.println(p1); // toString Method | ||
System.out.println(p2); //toString method | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package TypeCasting; | ||
|
||
public class A { | ||
// to convert data type from one to another | ||
|
||
public static void main(String[] args) { | ||
int x = 10; | ||
double y = x; //implicit type casting | ||
// Widening | ||
|
||
|
||
|
||
double z=12.5; | ||
int c = (int) z; // explicit type casting | ||
//narrowing | ||
|
||
// not primitive type casting | ||
// 1. Upcasting | ||
// 2. downcasting | ||
|
||
Person p = new Teacher(); // upcasting | ||
p.display(); | ||
|
||
Teacher t = (Teacher) new Person(); | ||
t.display(); //compile error | ||
|
||
System.out.println(y +" " + c ); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package TypeCasting; | ||
|
||
public class Person { | ||
|
||
// super | ||
|
||
void display() { | ||
System.out.println("Perosn class"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package TypeCasting; | ||
|
||
public class Teacher extends Person { | ||
//sub | ||
|
||
@Override | ||
void display() { | ||
System.out.println("Teacher class"); | ||
} | ||
|
||
} |