├── .gitignore ├── src ├── OOP │ ├── Abstraction │ │ ├── Vee.java │ │ ├── Car.java │ │ ├── Moto.java │ │ ├── Vechil.java │ │ └── Main.java │ ├── Encapsulation │ │ ├── Main.java │ │ └── Encapsulation.java │ ├── Inheritance │ │ ├── ParentClass.java │ │ ├── Doctors.java │ │ ├── MainWithoutConstructor.java │ │ ├── MainForStatic.java │ │ └── Students.java │ └── Polymarphism │ │ ├── ParentClass.java │ │ ├── Main.java │ │ ├── Doctors.java │ │ └── Students.java └── Basics │ ├── PrintMessage.java │ ├── Comments.java │ ├── MathmaticalOperations.java │ ├── ForLoop.java │ ├── WhileLoop.java │ ├── GettingInput.java │ ├── DoWhileLoop.java │ ├── NestedLoop.java │ ├── SwitchCondition.java │ ├── Continue_Break.java │ ├── OneDArrays.java │ ├── Inctrement_Decrement.java │ ├── Variables_DataTypes.java │ ├── IfConditions.java │ ├── Functions.java │ └── TwoDArrays.java ├── .idea ├── .gitignore ├── misc.xml ├── modules.xml └── uiDesigner.xml └── JavaProgramming.iml /.gitignore: -------------------------------------------------------------------------------- 1 | # Project exclude paths 2 | /out/ -------------------------------------------------------------------------------- /src/OOP/Abstraction/Vee.java: -------------------------------------------------------------------------------- 1 | package OOP.Abstraction; 2 | 3 | public interface Vee { 4 | void moveForward(); 5 | void moveBackward(); 6 | } 7 | -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Editor-based HTTP Client requests 5 | /httpRequests/ 6 | # Datasource local storage ignored files 7 | /dataSources/ 8 | /dataSources.local.xml 9 | -------------------------------------------------------------------------------- /src/Basics/PrintMessage.java: -------------------------------------------------------------------------------- 1 | package Basics; 2 | 3 | public class PrintMessage { //pascal 4 | 5 | 6 | public static void main(String[] args) { 7 | System.out.println("Hello World!"); 8 | } 9 | 10 | } 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/OOP/Abstraction/Car.java: -------------------------------------------------------------------------------- 1 | package OOP.Abstraction; 2 | 3 | public class Car extends Vechil{ 4 | @Override 5 | public void moveForward() { 6 | System.out.println("Press N and Move"); 7 | } 8 | 9 | @Override 10 | public void moveBackward() { 11 | System.out.println("Press R and move"); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/OOP/Abstraction/Moto.java: -------------------------------------------------------------------------------- 1 | package OOP.Abstraction; 2 | 3 | public class Moto extends Vechil{ 4 | 5 | @Override 6 | public void moveForward() { 7 | System.out.println("Press 1 and Move"); 8 | } 9 | 10 | @Override 11 | public void moveBackward() { 12 | System.out.println("Random"); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/OOP/Abstraction/Vechil.java: -------------------------------------------------------------------------------- 1 | package OOP.Abstraction; 2 | 3 | public abstract class Vechil { 4 | 5 | public abstract void moveForward(); 6 | public abstract void moveBackward(); 7 | //Can have abstract and non-abstract methods 8 | public void Print() 9 | { 10 | System.out.println("AAAA"); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/OOP/Abstraction/Main.java: -------------------------------------------------------------------------------- 1 | package OOP.Abstraction; 2 | 3 | public class Main { 4 | public static void main(String[] args) { 5 | Car car = new Car(); 6 | Moto moto = new Moto(); 7 | car.moveForward(); 8 | car.moveBackward(); 9 | moto.moveForward(); 10 | moto.moveBackward(); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/Basics/Comments.java: -------------------------------------------------------------------------------- 1 | package Basics; 2 | 3 | 4 | public class Comments { //pascal 5 | 6 | 7 | public static void main(String[] args) { 8 | //Single Line Comment 9 | System.out.println("Hello World!"); 10 | /* 11 | Multi 12 | Line 13 | Comment 14 | */ 15 | 16 | } 17 | 18 | } 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /src/OOP/Encapsulation/Main.java: -------------------------------------------------------------------------------- 1 | package OOP.Encapsulation; 2 | 3 | public class Main { 4 | public static void main(String[] args) { 5 | //Can access private property via Getters and Setters 6 | Encapsulation e = new Encapsulation(); 7 | e.setUser(123); 8 | e.setPass(11111); 9 | e.getUser(); 10 | e.getPass(); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/Basics/MathmaticalOperations.java: -------------------------------------------------------------------------------- 1 | package Basics; 2 | 3 | public class MathmaticalOperations { //pascal 4 | 5 | 6 | public static void main(String[] args) { 7 | /* 8 | Same as Math 9 | + addition 10 | - subtraction 11 | * multiplication 12 | / division 13 | % modulo 14 | */ 15 | } 16 | 17 | } 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /src/OOP/Inheritance/ParentClass.java: -------------------------------------------------------------------------------- 1 | package OOP.Inheritance; 2 | 3 | class ParentClass { 4 | protected String Name ; 5 | public static int count = 0 ; 6 | public int Id; 7 | public String Subject ; 8 | 9 | public void Print () 10 | { 11 | System.out.println(Name + " " + Id + " " + Subject ); 12 | 13 | } 14 | public void Play () 15 | { 16 | System.out.println("Can NOT Playing"); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/OOP/Polymarphism/ParentClass.java: -------------------------------------------------------------------------------- 1 | package OOP.Polymarphism; 2 | 3 | public class ParentClass { 4 | protected String Name ; 5 | public static int count = 0 ; 6 | public int Id; 7 | public String Subject ; 8 | 9 | public void Print () 10 | { 11 | System.out.println(Name + " " + Id + " " + Subject ); 12 | 13 | } 14 | public void Play () 15 | { 16 | System.out.println("Can NOT Playing"); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/OOP/Polymarphism/Main.java: -------------------------------------------------------------------------------- 1 | package OOP.Polymarphism; 2 | 3 | public class Main { 4 | public static void main(String[] args) { 5 | Students student = new Students(); 6 | Doctors doctor = new Doctors(); 7 | doctor.Name= "Ahmed" ; 8 | //Overloading 9 | doctor.Explain(); 10 | doctor.Explain(doctor.Name); 11 | 12 | //Overriding 13 | doctor.Play(); 14 | student.Play(); 15 | 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /JavaProgramming.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /src/Basics/ForLoop.java: -------------------------------------------------------------------------------- 1 | package Basics; 2 | 3 | public class ForLoop { //pascal 4 | 5 | 6 | public static void main(String[] args) { 7 | /* 8 | Loops : is repeating piece of code based on 3 Things : 9 | 1-Start 10 | 2-Condition 11 | 3-Increment or decrement value 12 | */ 13 | //Print numbers from 1 > 100 14 | for (int i =0 ; i <= 100 ; i++) 15 | System.out.println(i); 16 | } 17 | 18 | } 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /src/OOP/Inheritance/Doctors.java: -------------------------------------------------------------------------------- 1 | package OOP.Inheritance; 2 | 3 | public class Doctors extends ParentClass { 4 | //Attributes 5 | 6 | public int salary; 7 | 8 | 9 | //Methods 10 | public void Explain (String Name) 11 | { 12 | System.out.println( this.Name +" Explains now "); 13 | } 14 | 15 | //overloading 16 | public void Explain () 17 | { 18 | System.out.println(" Explains now "); 19 | } 20 | public void Countt() 21 | { 22 | count++; 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/OOP/Polymarphism/Doctors.java: -------------------------------------------------------------------------------- 1 | package OOP.Polymarphism; 2 | 3 | 4 | public class Doctors extends ParentClass { 5 | //Attributes 6 | 7 | public int salary; 8 | 9 | 10 | //Methods 11 | public void Explain (String Name) 12 | { 13 | System.out.println( this.Name +" Explains now "); 14 | } 15 | 16 | //overloading 17 | public void Explain () 18 | { 19 | System.out.println(" Explains now "); 20 | } 21 | public void Countt() 22 | { 23 | count++; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/Basics/WhileLoop.java: -------------------------------------------------------------------------------- 1 | package Basics; 2 | 3 | public class WhileLoop { //pascal 4 | 5 | 6 | public static void main(String[] args) { 7 | /* 8 | While Loop : as for : 9 | 1-Start 10 | 2-Condition 11 | 3-Increment or decrement value 12 | */ 13 | //Print numbers from 1 > 100 14 | int i = 1 ; //Start 15 | while ( i <= 100 ) //Condition 16 | { 17 | System.out.println(i); 18 | i++ ; //Increment 19 | } 20 | } 21 | 22 | } 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /src/Basics/GettingInput.java: -------------------------------------------------------------------------------- 1 | package Basics; 2 | 3 | import java.util.Scanner; 4 | 5 | public class GettingInput { //pascal 6 | 7 | 8 | public static void main(String[] args) { 9 | //Input from Scanner class >> use it to get all inputs 10 | Scanner input = new Scanner(System.in); 11 | int age = input.nextInt() ; //nextInt to get inputs from user 12 | float grade = input.nextFloat(); //nextFloat to get inputs from user 13 | String Name = input.next(); //next to get String from user 14 | 15 | } 16 | 17 | } 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /src/Basics/DoWhileLoop.java: -------------------------------------------------------------------------------- 1 | package Basics; 2 | 3 | public class DoWhileLoop { //pascal 4 | 5 | 6 | public static void main(String[] args) { 7 | /* 8 | Do While Loop : as for and while BUT do at least one iteration even condition 9 | not satisfied 10 | */ 11 | //Print numbers from 1 > 100 12 | int i = -1 ; //condition not satisfied but also will print it only one 13 | do 14 | { 15 | System.out.println(i); 16 | i++ ; //Increment 17 | } 18 | while ( i <= 100 ); //Condition 19 | } 20 | 21 | } 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /src/OOP/Encapsulation/Encapsulation.java: -------------------------------------------------------------------------------- 1 | package OOP.Encapsulation; 2 | 3 | public class Encapsulation { 4 | private int user ; 5 | private int pass ; 6 | public Encapsulation() 7 | {} 8 | public Encapsulation(int u, int p) { 9 | this.user = user; 10 | this.pass = pass; 11 | } 12 | 13 | public int getUser() { 14 | return user; 15 | } 16 | 17 | public void setUser(int user) { 18 | this.user = user; 19 | } 20 | 21 | public int getPass() { 22 | return pass; 23 | } 24 | 25 | public void setPass(int pass) { 26 | this.pass = pass; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Basics/NestedLoop.java: -------------------------------------------------------------------------------- 1 | package Basics; 2 | 3 | public class NestedLoop { //pascal 4 | 5 | 6 | public static void main(String[] args) { 7 | //Nested Loops : Need it if we will iterate in more than one thing 8 | //Ex> Print all days in weeks per month 9 | //So will need 2 loops > 1 for weeks and 1 for days 10 | 11 | for (int i = 1 ; i <= 4 ; i++) //Weeks 12 | { 13 | for (int j = 1 ; j <= 7 ; j++) //Days 14 | { 15 | System.out.println("Week: " + i + " Day: " + j); 16 | } 17 | } 18 | //try to do this example with adding year :) 19 | } 20 | 21 | } 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /src/Basics/SwitchCondition.java: -------------------------------------------------------------------------------- 1 | package Basics; 2 | 3 | public class SwitchCondition { //pascal 4 | 5 | 6 | public static void main(String[] args) { 7 | int age = 17 ; 8 | switch (age) 9 | { 10 | case 18 : 11 | System.out.println("18"); 12 | break; // To prevent continue if condition done 13 | case 25 : 14 | System.out.println("25"); 15 | break; // To prevent continue if condition done 16 | default: //as else in if 17 | System.out.println("Don't Know"); 18 | //break ; ?? Does not matter because it is final statement 19 | } 20 | } 21 | 22 | } 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /src/OOP/Inheritance/MainWithoutConstructor.java: -------------------------------------------------------------------------------- 1 | package OOP.Inheritance; 2 | 3 | public class MainWithoutConstructor { 4 | public static void main(String[] args) { 5 | //Creating Objects without Constructor 6 | Doctors doctor1 = new Doctors(); 7 | doctor1.Name ="ahmed" ; 8 | doctor1.Id = 1 ; 9 | doctor1.Subject = "Compiler" ; 10 | doctor1.salary = 500000; 11 | 12 | Doctors doctor2 = new Doctors(); 13 | doctor2.Name ="ibrahim" ; 14 | doctor2.Id = 2 ; 15 | doctor2.Subject = "Data mining" ; 16 | doctor2.salary = 600000; 17 | 18 | System.out.println(doctor1.Name); 19 | doctor1.Explain(doctor1.Name); 20 | doctor2.Explain(); 21 | 22 | 23 | 24 | 25 | 26 | 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/Basics/Continue_Break.java: -------------------------------------------------------------------------------- 1 | package Basics; 2 | 3 | import java.util.Scanner; 4 | 5 | public class Continue_Break { 6 | 7 | public static void main(String[] args) { 8 | int sum = 0 , num; 9 | Scanner input = new Scanner(System.in); 10 | for (int i = 1; i<=5 ; i++) 11 | { 12 | System.out.println("Enter Number" + i); 13 | num = input.nextInt(); 14 | if(num <0) 15 | { 16 | System.out.println("Negative Not allowed"); 17 | continue; //continue remaining iterations 18 | //break ; //Prevent remaining iterations 19 | } 20 | sum = sum+num ; 21 | } 22 | System.out.println(sum); 23 | 24 | 25 | 26 | 27 | 28 | 29 | } 30 | 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/Basics/OneDArrays.java: -------------------------------------------------------------------------------- 1 | package Basics; 2 | 3 | public class OneDArrays { //pascal 4 | 5 | 6 | public static void main(String[] args) { 7 | final int size = 5 ; 8 | int [] arr2 = new int [size] ; 9 | int [] arr = new int [size] ; 10 | arr[0]= 1 ; 11 | arr[1] = 2 ; 12 | arr[2] = 3 ; 13 | arr[3] = 4 ; 14 | arr[4] = 5 ; 15 | /* arr2 = arr ; 16 | arr[0] = 50 ; 17 | arr2[3] = 200; 18 | System.out.println(arr[3]);*/ 19 | //Swapping 20 | for (int i =0;i<=4 ; i++){ 21 | arr2[i] = arr [i]; 22 | } 23 | //print 24 | for (int i =0;i<=4 ; i++){ 25 | System.out.println(arr2[i]); 26 | } 27 | 28 | 29 | 30 | 31 | 32 | 33 | } 34 | 35 | } 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /src/Basics/Inctrement_Decrement.java: -------------------------------------------------------------------------------- 1 | package Basics; 2 | 3 | public class Inctrement_Decrement { //pascal 4 | 5 | 6 | public static void main(String[] args) { 7 | /* 8 | Increment is used to increase the value by one 9 | Decrement is used to decrease the value by one 10 | */ 11 | int x = 5 ; 12 | int y = 10 ; 13 | x++ ; // x = x + 1 ; 14 | x-- ; // x = x - 1 ; 15 | //Prefix 16 | ++x ; 17 | //Postfix 18 | x++ ; 19 | //Note : Prefix and postfix have shown in printing 20 | System.out.println(x++); //Print x then increment them 1 for next time 21 | System.out.println(++y);//Increment y then print it 22 | //Assignment Operator 23 | x += 5 ; // x = x + 5 ; //Same as all operations 24 | 25 | } 26 | 27 | } 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /src/Basics/Variables_DataTypes.java: -------------------------------------------------------------------------------- 1 | package Basics; 2 | 3 | public class Variables_DataTypes { //pascal 4 | 5 | 6 | public static void main(String[] args) { 7 | 8 | int x ; //Integers values {1,2,3,4,5,...} 9 | double y ; //Floated values {1.1,2.5,3.2,4.3,5.6,...} //Size > Float 10 | float z ; //Floated values {1.1,2.5,3.2,4.3,5.6,...} 11 | char c ; //Only One Character = 'A' , 'B' 12 | String s ; //More than one character "Ahmed" , "Mohamed" 13 | boolean bool ; //True or False only 14 | /* 15 | Write a program which creates three variables: student 16 | name, graduation year, & letter grade. Then print the 17 | three values. 18 | */ 19 | String studentName = "Ahmed" ; 20 | int graduationYear = 2020 ; 21 | String letterGrade = "A" ; 22 | //Concatenation >> String + String + String 23 | System.out.println(studentName + " " + graduationYear + " " + letterGrade); 24 | 25 | 26 | } 27 | 28 | } 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /src/OOP/Inheritance/MainForStatic.java: -------------------------------------------------------------------------------- 1 | package OOP.Inheritance; 2 | 3 | public class MainForStatic { 4 | public static void main(String[] args) { 5 | //Count without Static variable count 6 | Doctors d1 = new Doctors(); 7 | d1.Countt(); 8 | Doctors d2= new Doctors(); 9 | d2.Countt(); 10 | Doctors d3 = new Doctors(); 11 | d3.Countt(); 12 | Doctors d4 = new Doctors(); 13 | d4.Countt(); 14 | Doctors d5 = new Doctors(); 15 | d5.Countt(); 16 | Doctors d6= new Doctors(); 17 | d5.Countt(); 18 | System.out.println(Doctors.count); 19 | 20 | //Count Using Static variable count 21 | 22 | /* Students s1 = new Students("Ahmed" , 1 , "CS"); 23 | Students s2 = new Students("moahed" , 1, "CS"); 24 | Students s3 = new Students("sara" , 3 , "CS"); 25 | Students s4 = new Students("mahmoud" , 4 , "CS"); 26 | Students s5= new Students("mahmoud" , 4 );//New 27 | Students s6= new Students( );//New 28 | System.out.println(Students.count);*/ 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/Basics/IfConditions.java: -------------------------------------------------------------------------------- 1 | package Basics; 2 | 3 | public class IfConditions { //pascal 4 | 5 | 6 | public static void main(String[] args) { 7 | //Execute piece of based on condition 8 | int age = 20 ; 9 | String gender= "male" ; 10 | if (age > 18 ) 11 | System.out.println("Adult"); 12 | else if (age > 50) { 13 | System.out.println("Too Old"); 14 | } 15 | else 16 | System.out.println("Underage"); 17 | //Nested if 18 | if (age > 18 ) 19 | { 20 | if(gender.equalsIgnoreCase("male")) 21 | { 22 | System.out.println("Adult"); 23 | } 24 | } 25 | 26 | //Combining more than one condition 27 | if (age>18 && gender.equalsIgnoreCase("male")) 28 | System.out.println("Adult Male "); 29 | else if (age>18 || gender.equalsIgnoreCase("male")) { 30 | System.out.println("Adult"); 31 | } else if (!gender.equalsIgnoreCase("male")) { 32 | System.out.println("Female"); 33 | } 34 | 35 | } 36 | 37 | } 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /src/Basics/Functions.java: -------------------------------------------------------------------------------- 1 | package Basics; 2 | 3 | public class Functions { //pascal 4 | 5 | 6 | public static void main(String[] args) { 7 | 8 | int x = 5; 9 | int y = 10; 10 | //calling 11 | sum(x,y); 12 | int w = 50 ;//global 13 | w += 90 ; 14 | int ay7aga = CalcSum(10,20,30); 15 | System.out.println(ay7aga); 16 | System.out.println(CalcAvg2(ay7aga)); 17 | Print(ay7aga,CalcAvg2(ay7aga)); 18 | 19 | } 20 | //define 21 | public static int sum (int z , int q) 22 | { 23 | int res = z + q ; //local 24 | return res ; 25 | //System.out.println( number1 + number2); 26 | } 27 | 28 | public static int CalcSum(int n1 , int n2 , int n3) 29 | { 30 | return n1+ n2 +n3 ; 31 | } 32 | public static int CalcAvg1(int n1 , int n2 , int n3) 33 | { 34 | return (n1+ n2 +n3)/3 ; 35 | } 36 | public static int CalcAvg2(int ay7aga) 37 | { 38 | return ay7aga/3 ; 39 | } 40 | public static void Print (int s , int a) 41 | { 42 | System.out.println("Sum: " + s + " Avg: " +a); 43 | } 44 | 45 | 46 | } 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /src/OOP/Inheritance/Students.java: -------------------------------------------------------------------------------- 1 | package OOP.Inheritance; 2 | 3 | public class Students extends ParentClass { 4 | //attributes 5 | 6 | 7 | //methods 8 | //Default Constructor 9 | public Students () 10 | { 11 | 12 | } 13 | 14 | //Parameterized Constructor 15 | public Students (String name , int id , String subject) 16 | { 17 | this.Name =name ; 18 | this.Id = id ; 19 | this.Subject = subject ; 20 | count++; 21 | } 22 | public Students (String name , int id) 23 | { 24 | this.Name =name ; 25 | this.Id = id ; 26 | count++; 27 | } 28 | public Students (String name ) 29 | { 30 | this.Name =name ; 31 | count++; 32 | } 33 | 34 | public void Study() 35 | { 36 | System.out.println("Studying"); 37 | } 38 | //For comparing 2 object DON'T use if(obj1 == obj2) but use : 39 | public static void compare (Students s1 , Students s2) 40 | { 41 | if (s1.Name==s2.Name && s1.Id == s2.Id && s1.Subject == s2.Subject) 42 | System.out.println("======"); 43 | } 44 | //Same for Copy as Compare 45 | public static void copy (Students s1 , Students s2) 46 | { 47 | s1.Name=s2.Name ; 48 | s1.Id = s2.Id; 49 | s1.Subject = s2.Subject; 50 | 51 | } 52 | //Overriding 53 | @Override 54 | public void Play() 55 | { 56 | System.out.println("Can Play"); 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /src/OOP/Polymarphism/Students.java: -------------------------------------------------------------------------------- 1 | package OOP.Polymarphism; 2 | 3 | public class Students extends ParentClass { 4 | //attributes 5 | 6 | 7 | //methods 8 | //Default Constructor 9 | public Students () 10 | { 11 | 12 | } 13 | 14 | //Parameterized Constructor 15 | public Students (String name , int id , String subject) 16 | { 17 | this.Name =name ; 18 | this.Id = id ; 19 | this.Subject = subject ; 20 | count++; 21 | } 22 | public Students (String name , int id) 23 | { 24 | this.Name =name ; 25 | this.Id = id ; 26 | count++; 27 | } 28 | public Students (String name ) 29 | { 30 | this.Name =name ; 31 | count++; 32 | } 33 | 34 | public void Study() 35 | { 36 | System.out.println("Studying"); 37 | } 38 | //For comparing 2 object DON'T use if(obj1 == obj2) but use : 39 | public static void compare (Students s1 , Students s2) 40 | { 41 | if (s1.Name==s2.Name && s1.Id == s2.Id && s1.Subject == s2.Subject) 42 | System.out.println("======"); 43 | } 44 | //Same for Copy as Compare 45 | public static void copy (Students s1 , Students s2) 46 | { 47 | s1.Name=s2.Name ; 48 | s1.Id = s2.Id; 49 | s1.Subject = s2.Subject; 50 | 51 | } 52 | //Overriding 53 | @Override 54 | public void Play() 55 | { 56 | System.out.println("Can Play"); 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /src/Basics/TwoDArrays.java: -------------------------------------------------------------------------------- 1 | package Basics; 2 | 3 | import java.util.Scanner; 4 | 5 | public class TwoDArrays { //pascal 6 | 7 | 8 | public static void main(String[] args) { 9 | /* 10 | int [][] arr ={ {1,2,3}, 11 | {4,5,6}, 12 | {7,8,9} 13 | }; 14 | // String [][] arr2 = new String[6][7]; 15 | //System.out.println(arr2[0][0]); 16 | for (int i =0;i<=2 ; i++){ //row 17 | for (int j = 0;j<=2;j++) //columns 18 | { 19 | System.out.print(arr[i][j] + " "); 20 | } 21 | System.out.println(); 22 | } 23 | 24 | */ 25 | /* arr2 = arr ; 26 | arr[0] = 50 ; 27 | arr2[3] = 200; 28 | System.out.println(arr[3]);*/ 29 | //Swapping 30 | /* for (int i =0;i<=4 ; i++){ 31 | arr2[i] = arr [i]; 32 | } 33 | //print 34 | for (int i =0;i<=4 ; i++){ 35 | System.out.println(arr2[i]); 36 | }*/ 37 | 38 | 39 | //Example 40 | Scanner input = new Scanner(System.in); 41 | int [][] array = new int[4][4] ; 42 | int sum = 0; 43 | int dSum = 0; 44 | for (int i = 0 ; i<= 3 ;i++) //rows 45 | { 46 | for(int j =0; j<=3;j++) //column 47 | { 48 | System.out.println("Enter Number" + (i)+(j)); 49 | array[i][j]= input.nextInt(); 50 | sum += array[i][j]; 51 | if(i==j) 52 | dSum += array[i][j] ; 53 | } 54 | } 55 | System.out.println("Sum= " + sum + " Diagonal= " + dSum); 56 | 57 | 58 | 59 | 60 | 61 | } 62 | 63 | } 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /.idea/uiDesigner.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | --------------------------------------------------------------------------------