├── About Java ├── Arithmetic.java ├── ArithmeticExcept.java ├── Armstrong.java ├── CallingClass.java ├── CommonElement.java ├── CompExcep.java ├── Concatenate.java ├── EnhancedFor.java ├── ExcepHandle.java ├── Except1.java ├── Factorial.java ├── FavSuperHero.java ├── Hello.java ├── Hierarchical.java ├── If.java ├── IronMan.java ├── IterateArray.java ├── Movie.java ├── MovieImp.java ├── MultiDimArray.java ├── MultiHierarchy.java ├── MultiplicationTable.java ├── NarrowCast.java ├── NestedIf.java ├── Overload.java ├── Override.java ├── PackCR.java ├── README.md ├── Scan.java ├── SciFic.java ├── StringBuff.java ├── StringBuil.java ├── StringMethods.java ├── StringOp02.java ├── StringOp1.java ├── StringOp2.java ├── StudentDetails.java ├── SuperHero.java ├── SwitchCase.java ├── TryResources.java ├── TypeCasting.java ├── TypeConversion.java ├── WhileLoop.java ├── Wrapper.java ├── addition.java ├── addsub.java └── subtraction.java /About Java: -------------------------------------------------------------------------------- 1 | Java is an Object Oriented based programming language used in creating applications. 2 | -------------------------------------------------------------------------------- /Arithmetic.java: -------------------------------------------------------------------------------- 1 | class Arithmetic 2 | { 3 | public static void main (String[] args) 4 | { 5 | int a=5,b=25; 6 | System.out.println("Addition of "+a+" & "+b+" is "+(a+b)); 7 | System.out.println("Subtraction of "+a+" & "+b+" is "+(a-b)); 8 | System.out.println("Multiplication of "+a+" & "+b+" is "+(a*b)); 9 | System.out.println("Division of "+a+" & "+b+" is "+(a/b)); 10 | System.out.println("Qoutient of "+a+" & "+b+" is "+(a%b)); 11 | } 12 | } -------------------------------------------------------------------------------- /ArithmeticExcept.java: -------------------------------------------------------------------------------- 1 | class ArithmeticExcept 2 | { 3 | public static void main(String[] args) 4 | { 5 | try 6 | { 7 | int num=10/0; 8 | System.out.println(num); 9 | } 10 | catch(ArithmeticException ae) 11 | { 12 | System.out.println(ae); 13 | } 14 | catch(Exception e) 15 | { 16 | System.out.println("Parent class Exception handler."+e); 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /Armstrong.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | public class Armstrong 3 | { 4 | public static void main(String[] ar) 5 | { 6 | int sum=0,n,orn; 7 | Scanner sc=new Scanner(System.in); 8 | System.out.println("Enter the number:"); 9 | n=sc.nextInt(); 10 | orn=n; 11 | while(orn!=0) 12 | { 13 | int rem=orn%10; 14 | sum+=rem*rem*rem; 15 | orn/=10; 16 | } 17 | if (sum==n) 18 | { 19 | System.out.println("Armstrong Number!"); 20 | } 21 | else 22 | { 23 | System.out.println("Not Armstrong Number"); 24 | } 25 | sc.close(); 26 | } 27 | } -------------------------------------------------------------------------------- /CallingClass.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | public class CallingClass 3 | { 4 | public static void main(String[] ar) 5 | { 6 | int sum=0,n,orn; 7 | Scanner sc=new Scanner(System.in); 8 | Factorial f=new Factorial(); 9 | Factorial.main(null); 10 | System.out.println("\nEnter the number to check if it is Armstrong or not:"); 11 | n=sc.nextInt(); 12 | orn=n; 13 | while(orn!=0) 14 | { 15 | int rem=orn%10; 16 | sum+=rem*rem*rem; 17 | orn/=10; 18 | } 19 | if (sum==n) 20 | { 21 | System.out.println("Armstrong Number!"); 22 | } 23 | else 24 | { 25 | System.out.println("Not Armstrong Number"); 26 | } 27 | sc.close(); 28 | } 29 | } -------------------------------------------------------------------------------- /CommonElement.java: -------------------------------------------------------------------------------- 1 | public class CommonElement 2 | { 3 | int [] arr3={4,7,3,9,2}; 4 | public static void main(String[] ar) 5 | { 6 | int [] arr1={4,7,3,9,2}; 7 | int [] arr2={3,2,12,9,40,32,4}; 8 | for (int i=0;i clz=Class.forName(className); 9 | System.out.println("Class loaded successfully:"+clz.getName()); 10 | } 11 | catch (ClassNotFoundException e) 12 | { 13 | System.out.println("Class not found:"+className); 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /Concatenate.java: -------------------------------------------------------------------------------- 1 | class Concatenate 2 | { 3 | public static void main(String[] ar) 4 | { 5 | String first="Java "; 6 | String second="Lab"; 7 | String complete=first.concat(second); 8 | System.out.println(complete); 9 | String str1="James "; 10 | String str2="Gosling"; 11 | String auth=str1+str2; 12 | System.out.println(auth); 13 | } 14 | } -------------------------------------------------------------------------------- /EnhancedFor.java: -------------------------------------------------------------------------------- 1 | class EnhancedFor 2 | { 3 | public static void main(String[] ar) 4 | { 5 | int[] marks={10,20,30,40,50}; 6 | for(int i:marks) 7 | { 8 | System.out.println("Marks are:"+i); 9 | } 10 | } 11 | } -------------------------------------------------------------------------------- /ExcepHandle.java: -------------------------------------------------------------------------------- 1 | class ExcepHandle 2 | { 3 | public static void main(String[] args) 4 | { 5 | try 6 | { 7 | int data=50/0; 8 | System.out.println(data); 9 | } 10 | catch(Exception e) 11 | { 12 | System.out.println(e); 13 | System.out.println("Don't divide by zero."); 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /Except1.java: -------------------------------------------------------------------------------- 1 | class Except1 2 | { 3 | public static void main(String[] ar) 4 | { 5 | int data=50/0; 6 | System.out.println(data); 7 | } 8 | } -------------------------------------------------------------------------------- /Factorial.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | public class Factorial 3 | { 4 | public static void main(String[] ar) 5 | { 6 | int f=1; 7 | Scanner sc=new Scanner(System.in); 8 | System.out.println("Enter the number to get it's factorial:"); 9 | int n=sc.nextInt(); 10 | for (int i=1;i<=n;i++) 11 | { 12 | f=f*i; 13 | } 14 | System.out.println("Factorial of "+n+" is "+f); 15 | } 16 | } -------------------------------------------------------------------------------- /FavSuperHero.java: -------------------------------------------------------------------------------- 1 | class FavSuperHero 2 | { 3 | public static void main(String[] args) 4 | { 5 | IronMan im=new IronMan("Iron Man", "Fly" , "Jovial" , 55 , "Avengers"); 6 | im.display(); 7 | } 8 | } -------------------------------------------------------------------------------- /Hello.java: -------------------------------------------------------------------------------- 1 | class Hello 2 | { 3 | public static void main(String[] args) 4 | { 5 | System.out.println("Hello World!"); 6 | } 7 | } -------------------------------------------------------------------------------- /Hierarchical.java: -------------------------------------------------------------------------------- 1 | class SuperHero 2 | { 3 | String name; 4 | String power; 5 | public SuperHero(String name, String power) 6 | { 7 | this.name=name; 8 | this.power=power; 9 | } 10 | public void usePower() 11 | { 12 | System.out.println(name+" uses "+power); 13 | } 14 | } 15 | 16 | class IronMan extends SuperHero 17 | { 18 | public IronMan(String name) 19 | { 20 | super(name," advanced technology."); 21 | } 22 | } 23 | 24 | class SpiderMan extends SuperHero 25 | { 26 | public SpiderMan(String name) 27 | { 28 | super(name," web-slinging and spider-like abilities. "); 29 | } 30 | } 31 | 32 | public class Hierarchical 33 | { 34 | public static void main(String[] args) 35 | { 36 | IronMan im=new IronMan("Iron Man"); 37 | SpiderMan sm=new SpiderMan("Spiderman"); 38 | im.usePower(); 39 | sm.usePower(); 40 | } 41 | } -------------------------------------------------------------------------------- /If.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | public class If 3 | { 4 | public static void main(String[] ar) 5 | { 6 | Scanner sc=new Scanner(System.in); 7 | System.out.println("Enter your age:"); 8 | int age = sc.nextInt(); 9 | if(age>=18) 10 | { 11 | System.out.println("You are eligible to vote!"); 12 | } 13 | else 14 | { 15 | System.out.println("You aren't eligible to vote!"); 16 | } 17 | sc.close(); 18 | } 19 | } -------------------------------------------------------------------------------- /IronMan.java: -------------------------------------------------------------------------------- 1 | class IronMan extends SuperHero 2 | { 3 | String mov; 4 | IronMan (String name, String power, String bhvr, int age, String movie) 5 | { 6 | super(name,power,bhvr,age); 7 | this.mov=movie; 8 | } 9 | void display() 10 | { 11 | super.display(); 12 | System.out.println("Movie name :"+mov); 13 | } 14 | } -------------------------------------------------------------------------------- /IterateArray.java: -------------------------------------------------------------------------------- 1 | class IterateArray 2 | { 3 | public static void main(String[] ar) 4 | { 5 | int[] arr={1,2,4,5,6,7}; 6 | CommonElement co=new CommonElement(); 7 | System.out.println("Array 3 :"); 8 | for(int l:co.arr3) 9 | { 10 | System.out.println(l); 11 | } 12 | System.out.println("Common elements :"); 13 | CommonElement.main(null); 14 | System.out.println("Elements to be iterated are:"); 15 | for (int i=0;i System.out.println("Sum: "+(a+b)); 19 | case 2 -> System.out.println("Difference: "+(a-b)); 20 | case 3 -> System.out.println("Product: "+(a*b)); 21 | case 4 -> System.out.println("Quotient: "+(a/b)); 22 | default -> System.out.println("Choose an appropriate option."); 23 | } 24 | sc.close(); 25 | } 26 | } -------------------------------------------------------------------------------- /TryResources.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | class TryResources 3 | { 4 | public static void main(String[] args) 5 | { 6 | try(Scanner sc=new Scanner(System.in)) 7 | { 8 | System.out.println("Enter nr:"); 9 | int nr=sc.nextInt(); 10 | System.out.println("Enter dr:"); 11 | int dr=sc.nextInt(); 12 | int result=nr/dr; 13 | System.out.println("Result of division :"+result); 14 | } 15 | catch (ArithmeticException e) 16 | { 17 | System.out.println("Error : Division by zero is not allowed."); 18 | } 19 | catch (Exception e) 20 | { 21 | System.out.println("Error:"+e.getMessage()); 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /TypeCasting.java: -------------------------------------------------------------------------------- 1 | class TypeCasting 2 | { 3 | public static void main(String[] ar) 4 | { 5 | int marks=80; 6 | long lmv=marks; 7 | System.out.println("Integer value "+marks); 8 | System.out.println("Long value "+lmv); 9 | /*float d=129.345; 10 | double inm=d;*/ 11 | double d=129.345; 12 | int inm=(int)d; 13 | System.out.println("Double value "+d); 14 | System.out.println("Integer value "+inm); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /TypeConversion.java: -------------------------------------------------------------------------------- 1 | public class TypeConversion 2 | { 3 | public static void main(String[] ar) 4 | { 5 | int rno=81; 6 | double rnn=rno; 7 | System.out.println(rno); 8 | System.out.println(rnn); 9 | } 10 | } -------------------------------------------------------------------------------- /WhileLoop.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | public class WhileLoop 3 | { 4 | public static void main(String[] ar) 5 | { 6 | Scanner sc=new Scanner(System.in); 7 | int i=0; 8 | System.out.println("Enter the limit of the array:"); 9 | int n=sc.nextInt(); 10 | System.out.println("Enter the marks:"); 11 | int marks[]=new int[n]; 12 | while(i