सीधे मुख्य सामग्री पर जाएं

संदेश

जून, 2022 की पोस्ट दिखाई जा रही हैं

#60 How to find unique reference number for any class in java |Class के लिए unique reference number

package com.sudhirtheindian2.java123 ; public class D1 { void display (){ System. out .println( this ) ; } public static void main (String[] args) { D1 d = new D1() ; System. out .println(d) ; d.display() ; } }

#59 How to use this keyword in Java | Java में this keyword का use कैसे करे

package com.sudhirtheindian2.java123 ; public class this_keyword { public static void main (String[] args) { // How to call the parameterized constructor of its own class // using this keyword //How to use this keyword in java // whenever the name of instance and local variable are the same // then our run time environment JVM gets confused that which one is // local variable of which one is instance variable // to avoid the problem we should use this keyword // How to find unique reference number for any class in java // 1 this keyword refers the current object inside // a method or constructor // // 4 It is also called parameterized constructor of its own class } }

#58 What is method overloading in Java | Compile Time Polymorphism | Method overloading क्या है?

package com.sudhirtheindian2.java123 ; //class A{ // int sum(){ // int a =10, b=20,c; // c=a+b; // return c; // } // // void sum(int x, int y){ // // double c = x+y; // System.out.println(c); // // } // void sum(int x, double y){ // double c=x+y; // System.out.println(c); // } //} //public class compileT { // public static void main(String[] args) { // // A an =new A(); // an.sum(100,10); // an.sum(100,20.63); // int sum= an.sum(); // System.out.println(sum); // What is method overloading & compile time polymorphism in java // whenever a class contain more than one method // with same name and different types of parameter // called method overloading // syntax // return type method_name(para1); // return type method_name(para1, para2); // } //} package com.sudhirtheindian2.java123 ; class A{ int sum (){ int a = 20

#57 What is Method Overriding in Java | What is Run Time Polymorphism in Java | Overriding क्या है

//package com.sudhirtheindian2.java123; //public class runPoly { // public static void main(String[] args) { // // } // // // // // // // What is method overriding & Runtime polymorphism in java // //// method overriding // //// whenever we writing method in super and sub class //// in such a way that method name and parameter must be same //// called overriding // //// syntax //// class A{ //// void display(){ //// //// } ////} //// //// class B extends A{ //// void display(){ //// //// } //// } // // package com.sudhirtheindian2.java123 ; public class runPoly { public static void main (String[] args) { } // What is method overriding & Runtime polymorphism in java // method overriding // whenever we writing method in super and sub class // in such a way that method name and parameter must be same // called overriding // syntax // class A{ // void

#56 What is Polymorphism in Java | Java में polymorphism क्या होता है ?

package com.sudhirtheindian2.java123 ; import javax.swing.* ; public class poly { public static void main (String[] args) { // What is polymorphism in java ? // poly --->>> many // morphism--->>>form // poly+morphism = many form // polymorphism is the greek word // whose meaning is same object having different behaviour // person --->>> // customer // friend // students // teacher // void person(teacher) // void person(students) // void person(friend) // void person(customer) // there are two type to achieve the polymorphism // 1 compile time polymorphism // (static polymorphism, early binding) // A polymorphism which is exists at the time of compilation // is called compile time or early time or static polymorphism // method overloading // we can achieve compile time polymorphism through

#55 What is Multiple Inheritance in Java | Java में Multiple Inheritance का use कैसे करे

package com.sudhirtheindian2.java123 ; //class A{ // void show(){ // System.out.println("this is class A"); // } // //} //class B{ // void show(){ // System.out.println("this is class B"); // } //} interface A{ void show () ; // public+abstract } interface B{ void display () ; // public+abstract } public class Multiple implements A , B { public void show (){ System. out .println( "this is interface of a and b" ) ; } public void display (){ System. out .println( "this is display" ) ; } public static void main (String[] args) { Multiple m1 = new Multiple() ; m1.show() ; m1.display() ; } // Multiple inheritance in java ? // Multiple inheritance using interface // we can achieve multiple inheritance through interface // because interface contains only abstract method // which implementation is provided by the su

#54 What is Hierarchical Inheritance in Java | Hierarchical Inheritance क्या होता है ?

package com.sudhirtheindian2.java123 ; class A{ void input (){ System. out .println( "enter your name" ) ; } } class B extends A{ void display (){ System. out .println( "my name is sudhir" ) ; } } class C extends A{ void show (){ System. out .println( "my name is abhi" ) ; } } public class hirarchy { public static void main (String[] args) { B b = new B() ; C c = new C() ; b.input() ; b.display() ; c.input() ; c.show() ; // What is hierarchical inheritance in java ? // A inheritance which contain // only one super class & multiple sub class // and all sub class directly extends super class // called hierarchial inheritance // super---> sub 1 // super---> sub 2 // super---> sub 3 // super---> sub 4 // } }

#52 What is Simple Inheritance or Single Inheritance in Java | Simple / Single Inheritance क्या है

package com.sudhirtheindian2.java123 ; // class student{ // super class // int rollNo,marks; // String name, college; // // void input(){ // System.out.println("enter the detail of student"); // } // // // // } // class sudhir extends student{ // sub class // // void display(){ // rollNo =1; // marks=40; // name ="sudhir"; // college = "IIT"; // System.out.println(rollNo+" "+name+" "+marks+" "+college); // // // } // // } //public class Simple { // public static void main(String[] args) { // sudhir s = new sudhir(); // s.input(); // s.display(); // // // // // // Simple or Single Inheritance // // What is simple / single inheritance in java ? // Simple inheritance contain only one super class and /

#53 What is Multilevel Inheritance in Java | Multilevel inheritance क्या होता है ?

package com.sudhirtheindian2.java123 ; //class A{ // int a, b, c; // void sum(){ // a=10; // b=5; // c=a+b; // System.out.println("the sum of a and b is"+c); // } // // void sub(){ // a=20; // b=5; // c=a-b; // System.out.println("the sub of a and b is"+c); // // } //} // //class B extends A{ // void multilply(){ // a=20; // b=50; // c=a*b; // System.out.println("the multiply of a and b is "+c); // } // void devision(){ // a=20; // b=10; // c=a/b; // System.out.println("the dev of a and b is "+c); // // } // //} // //class C extends B { // // void reminder(){ // a=50; // b=3; // c=a%b; // // System.out.println("the reminder of a and b is "+c); // } //} public class MuLinherit { public static void main (String[] args) { // C c = new C(); // c.de

#51 What is Inheritance in Java | Types of Inheritance in Java | Inheritance क्या होता है ?

package com.sudhirtheindian2.java123 ; public class Inheritance { public static void main (String[] args) { // What is inheritance in java ? // When one class access the property of another class is called inheritance // When we construct a new class from existing class in such // a way that the new class access all the features // & properties of existing class called inheritance // 1 In java extends keyword is used to perform inheritance // 2 We cannot access private member of class through inheritance // 3 It provides code reusability // 4 a sub class contains all the features of super class so we // should create the object of sub class // 5 method overriding only possible through inheritance // Types of Inheritance // 1 Simple or Single Inheritance // one super class & one sub class // syntax // super class --->> sub class // class A{ // super

#50 What is Interface in Java | Real life Example of Interface Vehicle & Customer

package com.sudhirtheindian2.java123 ; import java.time.temporal.ChronoUnit ; interface vehical{ String name = "honda" ; // public+static+final int speed = 100 ; void start () ; void stop () ; } public class MyCustomer implements vehical { @Override public void start (){ System. out .println( "for start the vehical , insert the key & press the start button" + name ) ; } @Override public void stop () { System. out .println( "for stop the vehical exit the key" ) ; } public static void main (String[] args) { // What is interface in java ? // 1 interface just like a class, // 2 to achieve interface in java by the help // of implements interface keyword // Notes about interface // 1 by default variable are public +static+final inside a interface // 2 by default methods are public and abstract // 3 from jdk 1.8 version interface can have defau

#49 What is Abstraction in Java | Real Life Example of Abstraction | Abstraction क्या है ?

package com.sudhirtheindian2.java123 ; abstract class Animal1{ void leg (){ System. out .println( "all animal have 4 legs" ) ; } void sleep (){ System. out .println( "all the animal sleep" ) ; } abstract void eat () ; abstract void sound () ; } class Dog1 extends Animal1{ @Override void eat () { System. out .println( "eating meet" ) ; } @Override void sound () { System. out .println( "bhow bhow......." ) ; } } class Cow1 extends Animal1{ @Override void sound (){ System. out .println( "ooooo..." ) ; } void eat (){ System. out .println( "eating grass" ) ; } } public class abstractClass { public static void main (String[] args) { // What is abstraction in java ? // abstraction is nothing but hiding the essential information // and show the only set of service // // example ---- //

#48 What is Encapsulation in Java ? Real Life Example Bank 🏦 Account | Encapsulation क्या है ?

package com.sudhirtheindian2.java123 ; import java.util.Scanner ; public class MyBank { private double balance = 2000 ; private int password ; public void deposit ( double money){ System. out .println( "Enter the password" ) ; Scanner sc = new Scanner(System. in ) ; password = sc.nextInt() ; if ( password == 1999 ){ balance = balance +money ; System. out .println( "Deposited money" +money) ; System. out .println( "tatal money is:" + balance ) ; } else { System. out .println( "wrong password try again...." ) ; } } public void withdraw ( double money){ System. out .println( "Enter the password" ) ; Scanner sc = new Scanner(System. in ) ; password = sc.nextInt() ; if ( password == 1999 ){ balance = balance -money ; System. out .println( "withdrawn money&

#47 What is difference between Static & Instance block in Java | Static & Instance block क्या है

package com.sudhirtheindian2.java123 ; public class instance_vs_static { public static void main (String[] args) { // What is difference between instance block & static block in java // Instance Block // Note -- instance block called before the constructor // 1 it deals with object // 2 executed at the time of object creation // 3 no any keyword required // 4 static & non static variable can be accessed // inside the instance block // Static Block // 1 It deals with class // 2 Executed at the time of loaded .class file in java // 3 static keyword is required // 4 only static variable can be accessed // inside the static block } }

#46 What is Super keyword in java | Super keyword क्या होता है ?

package com.sudhirtheindian2.java123 ; public class MySuperClass { public static void main (String[] args) { // What is super keyword in java // 1 super keyword refers to the objects of super class // it is used when we want to call the super class // variable , method & constructor // through subclass object // 2 whenever the super class & sub class // variable and method name both are same then // it can be used only // 3 To avoid the confusion between superclass // and sub class variable and method that have same name // we should use super keyword // super keyword is uses in 3 way // 1 variable // 2 method // 3 constructor } }

#45 What is Private Constructor in Java ? How to create private constructor in Java

package com.sudhirtheindian2.java123 ; public class PConstructor { int a ; String name ; private PConstructor (){ a = 45 ; name = "indian" ; System. out .println( a + " " + name ) ; } public static void main (String[] args) { PConstructor p = new PConstructor() ; // What is private Constructor in java ? // In java, it is possible to write a constructor as a private // but according to the rule we can not acceess // private members outside of the class } } //class B{ //// PConstructor p = new PConstructor(); //}

#44 What is Copy Constructor in Java ? Copy Constructor क्या है ? How to create Copy Constructor

package com.sudhirtheindian2.java123 ; import java.lang.constant.Constable ; public class CopyConstructor { int a ; String name ; CopyConstructor (){ a = 40 ; name = "indian" ; System. out .println( a + " " + name ) ; } CopyConstructor (CopyConstructor reference){ a = reference. a ; name =reference. name ; System. out .println( a + " " + name ) ; } public static void main (String[] args) { CopyConstructor c = new CopyConstructor() ; CopyConstructor c2 = new CopyConstructor(c) ; // What is copy constructor in java ? // whenever we pass object reference to the constructor // then it is called copy constructor } }

#43 What is Parameterized Constructor in Java ? Parameterized Constructor क्या होता है ?

package com.sudhirtheindian2.java123 ; public class ParaConstructor { int x ; String y ; ParaConstructor ( int a , String b){ x =a ; y =b ; // System.out.println(a+b); } void sum (){ System. out .println( x + y ) ; } public static void main (String[] args) { ParaConstructor pc = new ParaConstructor( 4 , "india" ) ; pc.sum() ; // What is parameterized constructor in java // a constructor through which we can pass one or more // parameters is called parameterized constructor // syntax // class A(){ // A(int a, String b){ // // } // } } }

#42 Types of Constructor in Java | What is Default Constructor in Java ?

package com.sudhirtheindian2.java123 ; public class javaConstructor { int a ; String name ; boolean f ; javaConstructor (){ a = 10 ; name = "india" ; f = true; } void display (){ System. out .println( a + " " + name + " " + f ) ; } public static void main (String[] args) { javaConstructor jc = new javaConstructor() ; jc.display() ; // Types of constructor in java ---- // and what is default constructor // 1 private constructor // 2 default constructor // 3 parametrized constructor // 4 copy constructor // what is default constructor // // a constructor which does not have any parameter // is called default constructor // syntax---- // class A{ // // A(){ // // } // } }

#41 What is Constructor in Java ? How to create Constructor ? Full Explanation about Constructor

package com.sudhirtheindian2.java123 ; public class MyConstructor { int x ; String name ; MyConstructor (){ x = 0 ; name = null; } void display (){ System. out .println( x + " " + name ) ; } public static void main (String[] args) { MyConstructor c = new MyConstructor() ; c.display() ; // What is constructor in java ? // constructor is a special type of method // whose name is same as class name // important notes for constructor-------- // 1 the main purpose of constructor is initialize the object // 2 every java class has a constructor // if you not create constructor then // java create autumatic default constructor // 3 constructor is autmatically called // at the time of object creation // 4 constructor never contain any return types // syntax // constructor name as a class name

#40 What is Class & Object in Java ? Full Explanation About Class & Object in Java

package com.sudhirtheindian2.java123 ; import java.util.Scanner ; public class OurPerson { public static void main (String[] args) { // What is class and object in java ? // and how to create class and object // Class is a group of elements having common properties and behaviour // common properties // age; // weight; // height; // behaviour // sleep(); // eat(); // run(); // important notes: // 1 class is virtual // means there is no memory for the class // class is logical // 2 object is real // there is memory for the object // types of class // 1 user defined B, Animal, Bird, Person // 2 pre defined System, String, Scanner } }

#39 Why String is Immutable in Java Language ? Java में String immutable क्यों होता है ?

package com.sudhirtheindian2.java123 ; public class string_immutable { public static void main (String[] args) { // 1 Why string is immutable in java ? // (immutable means we can not change string) // 2 How to change string in java ? // 3 what is the benefit of immutable string // 1 same object name same address so memory use minimum // 2 program execution fast // String str1 = "India" ; //1000 String str2 = "India1" ; //1000 String str3 = "India3" ; //1000 // String str = "India"; // str.concat("is great"); // System.out.println(str); } }

#38 How to use String in Java ? String का use कैसे करे ? lowercase, uppercase & equal in String

package com.sudhirtheindian2.java123 ; public class string_java { public static void main (String[] args) { // How to use String in java // 1 String is a predefined class in java // but we can also use as a datatype // 2 String are the sequence of character and // its index starts from 0 // syntax // // 1 String str1 = new String("India"); // // 2 String str2 = "India" // String str1 = new String("India"); String str2 = "India" ; System. out .println(str2.toLowerCase()) ; // if(str1.equals(str2)){ // System.out.println("yes both are equal"); // } // else { // System.out.println("no both are not equal"); // // } // difference // 1 equals // 2 length of string // 3 toupprecase // 4 tolowercase } }

#37 What is Method in Java | How to create Method in Java ? Java में Method कैसे बनाते है ?

package com.sudhirtheindian2.java123 ; public class methods { public static void main (String[] args) { // What is method in java and how to create it // method is a group or block of code // which take input from the user // ,processed it // and gives output // notes -- // 1 method run only when it will called // 2 reusability of code // type of method // predefined-- // print(); // sort(); // nextInt(); // nextFloat(); // sleep(); // concat(); // user defined // add(); // sum(); } }

#36 Write a program for 2D Array in Java | 2D Array in Java

package com.sudhirtheindian2.java123 ; import java.util.Scanner ; public class twoDarray { public static void main (String[] args) { // How to use 2D array in java int [][] a = new int [ 2 ][ 2 ] ; System. out .println( "enter your array element" ) ; Scanner scanner = new Scanner(System. in ) ; for ( int i = 0 ; i< 2 ; i++){ for ( int j= 0 ; j< 2 ; j++){ a[i][j] = scanner.nextInt() ; } } for ( int i = 0 ; i< 2 ; i++){ for ( int j= 0 ; j< 2 ; j++){ System. out .print(a[i][j]+ " " ) ; } System. out .println() ; } } }

#35 How to sorted Array in Java ? Sorting array in Java

package com.sudhirtheindian2.java123 ; import java.util.Arrays ; import java.util.Scanner ; public class sortedarray { public static void main (String[] args) { // How to sorted array in java int [] a = new int [ 5 ] ; System. out .println( "enter your array element" ) ; Scanner scanner = new Scanner(System. in ) ; for ( int i = 0 ; i< 5 ; i++){ a[i] = scanner.nextInt() ; } Arrays. sort (a) ; for ( int c:a){ System. out .print(c+ " " ) ; } } }

#34 How to use Array in Java ? Types of Array | 1D Array & 2D Array Example

package com.sudhirtheindian2.java123 ; import java.util.Scanner ; public class array_class { public static void main (String[] args) { // // How to use and print element of an array in java // What is array ? // Array is an object in java which contains similar type of data // in contiguous memory location // 1 array index starts with 0 // types of array // 1D array // 2Darray // for programmer // int[] a= {4,5,6,9,3}; // // for (int c:a){ // System.out.print(c+" "); // } // and // for user int [] a = new int [ 5 ] ; System. out .println( "enter your array element" ) ; Scanner scanner = new Scanner(System. in ) ; for ( int i = 0 ; i< 5 ; i++){ a[i]= scanner.nextInt() ; } System. out .println( "your printed array is : " ) ; for ( int d:a){ System. out .pr