├── .gitignore ├── .vscode └── launch.json ├── README.md ├── basics ├── ArithmeticOp.java ├── ArmstrongImpl.java ├── FactImpl.java ├── HelloWorld.java ├── NarrowCastExample.java ├── StudentImpl.java ├── controlstatements │ ├── EnhancedFor.java │ ├── Ifstmt.java │ ├── NestedIf.java │ ├── SwitchCase.java │ └── WhileExam.java ├── datatype │ ├── Datatype.java │ ├── NarrowCastExample.java │ └── TypeConv.java └── variables │ ├── Cricketer.java │ ├── CricketerImpl.java │ ├── InstanceVar.java │ └── StaticVar.java └── notes ├── Control statements.pptx ├── Java Type Casting.pptx └── operators,expressions,control stmts.pptx /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | 4 | # Log file 5 | *.log 6 | 7 | # BlueJ files 8 | *.ctxt 9 | 10 | # Mobile Tools for Java (J2ME) 11 | .mtj.tmp/ 12 | 13 | # Package Files # 14 | *.jar 15 | *.war 16 | *.nar 17 | *.ear 18 | *.zip 19 | *.tar.gz 20 | *.rar 21 | 22 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 23 | hs_err_pid* 24 | replay_pid* 25 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "configurations": [ 3 | { 4 | "type": "java", 5 | "name": "WhileExam", 6 | "request": "launch", 7 | "mainClass": "basics.controlstatements.WhileExam", 8 | "projectName": "OOP-using-Java_b9476530" 9 | }, 10 | { 11 | "type": "java", 12 | "name": "SwitchCase", 13 | "request": "launch", 14 | "mainClass": "basics.controlstatements.SwitchCase", 15 | "projectName": "OOP-using-Java_b9476530" 16 | }, 17 | { 18 | "type": "java", 19 | "name": "Datatype", 20 | "request": "launch", 21 | "mainClass": "basics.datatype.Datatype", 22 | "projectName": "OOP-using-Java_b9476530" 23 | }, 24 | { 25 | "type": "java", 26 | "name": "CricketerImpl", 27 | "request": "launch", 28 | "mainClass": "basics.variables.CricketerImpl", 29 | "projectName": "OOP-using-Java_b9476530" 30 | }, 31 | { 32 | "type": "java", 33 | "name": "InstanceVar", 34 | "request": "launch", 35 | "mainClass": "basics.variables.InstanceVar", 36 | "projectName": "OOP-using-Java_b9476530" 37 | }, 38 | { 39 | "type": "java", 40 | "name": "NestedIf", 41 | "request": "launch", 42 | "mainClass": "basics.controlstatements.NestedIf", 43 | "projectName": "OOP-using-Java_b9476530" 44 | }, 45 | { 46 | "type": "java", 47 | "name": "Ifstmt", 48 | "request": "launch", 49 | "mainClass": "basics.controlstatements.Ifstmt", 50 | "projectName": "OOP-using-Java_b9476530" 51 | }, 52 | { 53 | "type": "java", 54 | "name": "NarrowCastExample", 55 | "request": "launch", 56 | "mainClass": "basics.NarrowCastExample", 57 | "projectName": "OOP-using-Java_b9476530" 58 | }, 59 | { 60 | "type": "java", 61 | "name": "TypeConv", 62 | "request": "launch", 63 | "mainClass": "basics.TypeConv", 64 | "projectName": "OOP-using-Java_b9476530" 65 | }, 66 | { 67 | "type": "java", 68 | "name": "ArmstrongImpl", 69 | "request": "launch", 70 | "mainClass": "basics.ArmstrongImpl", 71 | "projectName": "OOP-using-Java_b9476530" 72 | }, 73 | { 74 | "type": "java", 75 | "name": "FactImpl", 76 | "request": "launch", 77 | "mainClass": "basics.FactImpl", 78 | "projectName": "OOP-using-Java_b9476530" 79 | }, 80 | { 81 | "type": "java", 82 | "name": "StudentImpl", 83 | "request": "launch", 84 | "mainClass": "basics.StudentImpl", 85 | "projectName": "OOP-using-Java_b9476530" 86 | }, 87 | { 88 | "type": "java", 89 | "name": "ArithmeticOp", 90 | "request": "launch", 91 | "mainClass": "basics.ArithmeticOp", 92 | "projectName": "OOP-using-Java_b9476530" 93 | }, 94 | { 95 | "name": "gcc.exe - Build and debug active file", 96 | "type": "cppdbg", 97 | "request": "launch", 98 | "program": "${fileDirname}\\${fileBasenameNoExtension}.exe", 99 | "args": [], 100 | "stopAtEntry": false, 101 | "cwd": "${fileDirname}", 102 | "environment": [], 103 | "externalConsole": true, 104 | "MIMode": "gdb", 105 | "miDebuggerPath": "E:\\CodeBlocks\\MinGW\\bin\\gdb.exe", 106 | "setupCommands": [ 107 | { 108 | "description": "Enable pretty-printing for gdb", 109 | "text": "-enable-pretty-printing", 110 | "ignoreFailures": true 111 | } 112 | ], 113 | "preLaunchTask": "C/C++: gcc.exe build active file" 114 | }, 115 | { 116 | "name": "gcc build & run active file", 117 | "type": "cppdbg", 118 | "request": "launch", 119 | "program": "${fileDirname}\\${fileBasenameNoExtension}.exe", 120 | "args": [], 121 | "stopAtEntry": false, 122 | "cwd": "${fileDirname}", 123 | "environment": [], 124 | "externalConsole": false, 125 | "MIMode": "gdb", 126 | "miDebuggerPath": "E:\\CodeBlocks\\MinGW\\bin\\gdb.exe", 127 | "setupCommands": [ 128 | { 129 | "description": "Enable pretty-printing for gdb", 130 | "text": "-enable-pretty-printing", 131 | "ignoreFailures": true 132 | } 133 | ], 134 | "preLaunchTask": "gcc build & run active file" 135 | } 136 | ] 137 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # OOP-Using-Java 2 | Object Oriented Programming Using JAVA 3 | Java_Lab 4 | -------------------------------------------------------------------------------- /basics/ArithmeticOp.java: -------------------------------------------------------------------------------- 1 | package basics; 2 | import java.util.*; 3 | class ArithmeticOp{ 4 | public static void main(String[] args){ 5 | Scanner sc=new Scanner(System.in); 6 | System.out.println("enter the two integers"); 7 | int a=sc.nextInt(); 8 | int b=sc.nextInt(); 9 | sc.close(); 10 | Arith a1=new Arith(a,b); 11 | a1.add(); 12 | a1.sub(); 13 | } 14 | } 15 | class Arith{ 16 | int n1,n2; 17 | Arith(int a,int b){ 18 | this.n1=a; 19 | this.n2=b; 20 | } 21 | void add(){ 22 | System.out.println("addition result:"+(n1+n2)); 23 | } 24 | void sub(){ 25 | System.out.println("subtraction result:"+(n1-n2)); 26 | } 27 | } -------------------------------------------------------------------------------- /basics/ArmstrongImpl.java: -------------------------------------------------------------------------------- 1 | package basics; 2 | import java.util.*; 3 | public class ArmstrongImpl { 4 | //armstrong number logic 5 | public static void main(String[] ar){ 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 | int rem=orn%10; 13 | sum+=rem*rem*rem; 14 | orn/=10; 15 | 16 | } 17 | if(sum==n){ 18 | System.out.println("armstrong number"); 19 | }else{ 20 | System.out.println("not armstrong number"); 21 | } 22 | sc.close(); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /basics/FactImpl.java: -------------------------------------------------------------------------------- 1 | package basics; 2 | import java.io.*; 3 | 4 | public class FactImpl { 5 | public static void main(String[] args) throws IOException{ 6 | int f=1; 7 | BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); 8 | System.out.println("enter the number to find the factorial"); 9 | int n=Integer.parseInt(br.readLine()); 10 | for(int i=1;i<=n;i++){ 11 | f=f*i; 12 | } 13 | System.out.println("factorial of "+n+" is "+f); 14 | } 15 | } 16 | 17 | -------------------------------------------------------------------------------- /basics/HelloWorld.java: -------------------------------------------------------------------------------- 1 | package basics; 2 | class HelloWorld{ 3 | public static void main(String[] args){ 4 | System.out.println("Hello there welcome to java"); 5 | } 6 | } -------------------------------------------------------------------------------- /basics/NarrowCastExample.java: -------------------------------------------------------------------------------- 1 | package basics; 2 | 3 | public class NarrowCastExample { 4 | public static void main(String[] args) { 5 | int marks=70; 6 | double dmarks=(double)marks; 7 | System.out.println(marks); 8 | System.out.println(dmarks); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /basics/StudentImpl.java: -------------------------------------------------------------------------------- 1 | package basics; 2 | 3 | public class StudentImpl { 4 | public static void main(String[] args){ 5 | Student s = new Student("james","1232"); 6 | s.display(); 7 | } 8 | } 9 | class Student{ 10 | String nam,rn; 11 | Student(String name,String rno){ 12 | nam=name; 13 | rn=rno; 14 | } 15 | public void display(){ 16 | System.out.printf("Welcome %s rno is %s \n",nam,rn); 17 | 18 | } 19 | } -------------------------------------------------------------------------------- /basics/controlstatements/EnhancedFor.java: -------------------------------------------------------------------------------- 1 | class EnhancedFor{ 2 | public static void main(String[] ar){ 3 | int[] marks={10,20,30,40,50}; 4 | for(int i:marks){ 5 | System.out.println("marks are"+i); 6 | } 7 | } 8 | } -------------------------------------------------------------------------------- /basics/controlstatements/Ifstmt.java: -------------------------------------------------------------------------------- 1 | package basics.controlstatements; 2 | import java.util.*; 3 | public class Ifstmt { 4 | public static void main(String[] ar){ 5 | Scanner sc=new Scanner(System.in); 6 | System.out.println("enter the age"); 7 | int age=sc.nextInt(); 8 | if(age>=18){ 9 | System.out.println("You are allowed to vote"); 10 | } 11 | else{ 12 | System.out.println("You are not eligible"); 13 | } 14 | sc.close(); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /basics/controlstatements/NestedIf.java: -------------------------------------------------------------------------------- 1 | package basics.controlstatements; 2 | 3 | public class NestedIf { 4 | public static void main(String[] args){ 5 | java.util.Scanner sc=new java.util.Scanner(System.in); 6 | System.out.println("enter your favorite iconic character:"); 7 | String act=sc.nextLine(); 8 | if(act.equals("Iron Man")){ 9 | System.out.println("Great choice"); 10 | System.out.println("enter"+act+"real name"); 11 | String reall=sc.nextLine(); 12 | if(reall.equalsIgnoreCase("tony stark")){ 13 | System.out.println("Cool actor"); 14 | } 15 | }else{ 16 | System.out.println(act); 17 | } 18 | sc.close(); 19 | 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /basics/controlstatements/SwitchCase.java: -------------------------------------------------------------------------------- 1 | package basics.controlstatements; 2 | import java.util.*; 3 | public class SwitchCase { 4 | public static void main(String[] args) { 5 | int a=4,b=2; 6 | Scanner sc=new Scanner(System.in); 7 | System.out.println("******"); 8 | System.out.println("*ARITHMETIC OPERATIONS***"); 9 | System.out.println("1. Add"); 10 | System.out.println("2. Sub"); 11 | System.out.println("3. Mul"); 12 | System.out.println("4. Div"); 13 | System.out.println("enter your choice"); 14 | int ch=sc.nextInt(); 15 | switch(ch){ 16 | case 1-> System.out.println("addition result is"+(a+b)); 17 | case 2-> System.out.println("subtraction result is"+(a-b)); 18 | case 3-> System.out.println("multiplication result is"+(a*b)); 19 | case 4-> System.out.println("division result is"+(a/b)); 20 | default -> System.out.println("give proper option"); 21 | } 22 | sc.close(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /basics/controlstatements/WhileExam.java: -------------------------------------------------------------------------------- 1 | package basics.controlstatements; 2 | import java.util.*; 3 | /** 4 | * Java program to accept input and store in arrays 5 | */ 6 | public class WhileExam { 7 | public static void main(String[] p){ 8 | Scanner sc=new Scanner(System.in); 9 | int i=0; 10 | System.out.println("enter the limit"); 11 | int n=sc.nextInt(); 12 | System.out.println("enter the marks"); 13 | int marks[]=new int[n]; 14 | while(i