संदेश

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

#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 } }

#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(); //}

#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(){ // // } // } }...

#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 } }

#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...

#33 How to use Ternary Operator in Java ? Ternary Operater क्या होता है ?

package com.sudhirtheindian2.java123 ; public class ternary_operator { public static void main (String[] args) { // How to use ternary operator in java // syntax // (?:) (a>b>c) // find the greatest number among a,b and c int a= 2 , b= 3 , c= 400 ; int result= (a>b)?(a>c?a:c):(b>c?b:c) ; System. out .println(result) ; } }

#32 How to use Assignment Operator (=, +=, -=) in Java | Assignment Operator क्या होता है ?

package com.sudhirtheindian2.java123 ; public class assignment_operator { public static void main (String[] args) { // How to use assignment operator in java // simple assignment operator // 1 = // compound assignment operator // 2+= // 3-= // multiple value increment decrement int a= 10 ; // a+=5;// a=a+5=10+5=15 // System.out.println(a); // a-=2;// a=a-2=10-2=8 // a=a-2; System. out .println(a) ; } }

#31 How to use Increment / Decrement in Java | Increment /decrement operator क्या होता है ?

package com.sudhirtheindian2.java123 ; public class increment_decrement_operator { public static void main (String[] args) { // How to use increment decrement operator in java // increment or decrement one value only // increment operator // 1 pre increment ++a // 2 post increment a++ // decrement operator // 1 pre decrement --a // 2 post decrement a-- int a= 10 ; // System.out.println(++a); // System.out.println(a++); // System.out.println(a++); // System.out.println(--a); System. out .println(a--) ; System. out .println(a--) ; } }

#30 How to use logical operators in Java | Logical Operator(&& ,|| and ! ) क्या होता है ?

package com.sudhirtheindian2.java123 ; public class logical_operator { public static void main (String[] args) { // How to use logical operator in java // 1 && logical and operator // 2 || logical or operator // 3 != logical not operator int a= 5 , b = 10 ; // System.out.println(a==b && a>b); //5==10 5>10 // System.out.println(a==b || b>a); // 5==10 10>5 System. out .println(!(a==b) || a>b) ; } }

#29 How to use Relational Operator in Java | Relational Operator क्या है ?

package com.sudhirtheindian2.java123 ; public class relational_operator { public static void main (String[] args) { // How to use relational operator in java // 1 == // 2!= // 3> // 4< // 5<= // 6>= int a = 5 , b= 10 ; System. out .println(a==b) ; //5==10 System. out .println(a!=b) ; //5!=10 System. out .println(a>b) ; //5>10 System. out .println(a<b) ; //5<10 System. out .println(a<=b) ; //5<=10 System. out .println(a>=b) ; //5>=10 } }

#28 How to make a Calculator in Java ? Java में Calculator कैसे बनायें ?

package com.sudhirtheindian2.java123 ; import java.util.Scanner ; public class calculater { public static void main (String[] args) { // How to make a calculater in java language int a , b , c , choice ; System. out .println( "enter two number" ) ; Scanner scanner = new Scanner(System. in ) ; System. out .println( "enter your first number" ) ; a=scanner.nextInt() ; System. out .println( "enter your second number" ) ; b=scanner.nextInt() ; System. out .println( "enter your choice" ) ; choice= scanner.nextInt() ; switch (choice){ case 1 : c=a+b ; System. out .println( "addition " +c) ; break; case 2 : c=a-b ; System. out .println( "subtraction " +c) ; break; case 3 : c=a*b ; System. out ...

#27 What is operator in Java ? Arithmetic Operator with Calculator's example

package com.sudhirtheindian2.java123 ; import java.util.Scanner ; public class arithmetic_operator { public static void main (String[] args) { // What is operator and arithmetic operator with calculater example // operator // operator is a symbol that is used to perform // operatons according to user requirement // types of operator // arithmetic_operator // relational oprator // logical operator // arithmetic operator example int a , b , c , choice ; System. out .println( "enter the two number" ) ; Scanner scanner = new Scanner(System. in ) ; a= scanner.nextInt() ; b= scanner.nextInt() ; System. out .println( "enter your choice" ) ; choice= scanner.nextInt() ; switch (choice){ case 1 : c=a+b ; System. out .println( "addition " +c) ; break; case 2 : ...

#26 How to use Switch case statement in Java | Java में Switch case का use कैसे करे ?

package com.sudhirtheindian2.java123 ; public class Switch { public static void main (String[] args) { // How to use switch case statement in java // switch is a multiple choice decision making selection // statement , it used when we want to select // only one case out of multiple cases // syntax // switch (expression){ // case 1: // statement 1 // break; // case 2: // statement 2 // case 3: // statement 3 // case m : // statement m; // // // default: // default ; switch ( 35 ){ case 1 : System. out .println( "this is right value" ) ; break; case 2 : System. out .println( "this is very good" ) ; break; case 3 : System. out .println( "this is india" )...

#24 How to use for each loop in java | java में for each loop का use कैसे करे ?

package com.sudhirtheindian2.java123 ; public class foreach { public static void main (String[] args) { // How to use forEach loop in java // syntax -- // for(datatype var1:arrayvarname){ // // statement // } int []a = { 4 , 5 , 3 , 6 } ; for ( int a1 : a){ System. out .println(a1) ; } } }

#23 How to use do while loop in java | Do While loop ka use java में कैसे करे ?

package com.sudhirtheindian2.java123 ; import java.util.Scanner ; public class whileloop { public static void main (String[] args) { // How to use while loop in java // syntax--- // while(condition){ // //code // } System. out .println( "enter the number" ) ; Scanner scanner = new Scanner(System. in ) ; int num = scanner.nextInt() ; while (num>= 0 ){ if (num% 2 == 0 ){ System. out .println( "even number" ) ; break; } else { System. out .println( "odd number" ) ; break; } } } }

#22 How to use While Loop in Java | Odd Even Program in java using While Loop

package com.sudhirtheindian2.java123 ; import java.util.Scanner ; public class whileloop { public static void main (String[] args) { // How to use while loop in java // syntax--- // while(condition){ // //code // } System. out .println( "enter the number" ) ; Scanner scanner = new Scanner(System. in ) ; int num = scanner.nextInt() ; while (num>= 0 ){ if (num% 2 == 0 ){ System. out .println( "even number" ) ; break; } else { System. out .println( "odd number" ) ; break; } } } }

#21 Types of Looping Control Statement in Java | For,While,dowhile &ForEach Loop in java

  package com.sudhirtheindian2.java123 ; import java.util.Scanner ; public class looping_statement_for_loop { public static void main (String[] args) { // Types of looping statements in java // and write a program using for loop // 1 for // 2 while //// 3 do while //// 4 for each //// // whenever we want to repeat certain statement several times // then we should write those statements inside loop body // use of for loop // syntax // for(initialization; condition; inrement/decrement){ //// code // } // print a table without for loop and with for loop System. out .println( "enter the table number" ) ; Scanner scanner = new Scanner(System. in ) ; int num = scanner.nextInt() ; // for (int i =1; i<=10; i++){ // System.out.println(i*num); // } System. out .println(num* 1 ) ; System. out .println(num* 2 ) ; ...

#20 How to Write Program using Nested if in java ? Java me Nested if क्या होता है ?

चित्र
  package com.sudhirtheindian2.java123 ; public class nested_if_else { public static void main (String[] args) { // How to write a program using nested if else // Whenever we define if else block inside another if else // block called nested_if_else // syntax // if(condition 1) // { // if(condition 1A){ // // } // else{ // // } // // } // else{ // // if(codition 2){ // // } // else{ // // } // } // greatest number find among 3 number program int a= 20 , b= 30 , c= 10 ; if (a>b){ if (a>c){ System. out .println( "maximum number is :" +a) ; } else { System. out .println( "maximum number is :" +b) ; } } else { if (b>c){ System. out .println( "maximum number is :...

#19 How to Write Program Real Life based Using else if in java ? ELSE IF in Java

चित्र
  package com.sudhirtheindian2.java123 ; import java.util.Scanner ; public class Else_if_statement { public static void main (String[] args) { // How to write a program using else if in java // It is used when we have only one if block, // multiple else if block and at the last else block // syntax // if(condition1) // { //// statement 1 // } // else if(condition2){ //// statement 2 // } // else if(condition3){ ////// statement 2 //// } // else{ //// statement 3 // // } int marks ; System. out .println( "enter your marks" ) ; // 70 - 100 group A // 70 - 60 group B // 60 - 50 group C // 40 - 50 group D // 40> group E Scanner scanner = new Scanner(System. in ) ; marks= scanner.nextInt() ; if (marks>= 70 && marks<= 100 ){ System. out .prin...

#18 How to Write Real Life Based Program using if else in Java ? IF ELSE Statement in Java

चित्र
  package com.sudhirtheindian2.java123 ; import java.util.Scanner ; public class if_else { public static void main (String[] args) { // How to write a real life based program using if else in java // voting program int age ; System. out .println( "enter your age" ) ; Scanner scanner = new Scanner(System. in ) ; age= scanner.nextInt() ; if (age>= 18 ){ System. out .println( "yes you can vote" ) ; } else { System. out .println( "no you can not vote" ) ; } } }

#17 How to Write Real Life Based Program Using If Statement in java ? Use of If Statement

चित्र
  package com.sudhirtheindian2.java123 ; import java.util.Scanner ; public class if_Statement_program { public static void main (String[] args) { // How to write a real life based program for if statement in java // if statement // it is used when we want to test a single condition // syntax // if(condition) // { // statement // } int age ; Scanner scanner = new Scanner(System. in ) ; age= scanner.nextInt() ; if (age> 18 ){ System. out .println( "yes you can vote" ) ; } // } }

#16 Types of Control Flow Statement in Java | Conditional, Looping & Transfer Statement in Java

चित्र
  package com.sudhirtheindian2.java123 ; import java.util.Scanner ; public class types_of_conditional_flow_statement { public static void main (String[] args) { // Types of control flow statement // and how to use if statement in java // control flow statement // 1 conditional statement // 2 looping statement // 3 transfer statement // conditional statements types // 1 if statement // 2 if else statement // 3 else if statement // 4 nested if statement // 5 switch case statement // 1 if statement // it is used when we want to test a single condition // syntax // if(condition) // { // statement // } // program for if statement System. out .println( "enter the password" ) ; Scanner scanner = new Scanner(System. in ) ; int password= scanner.nextInt() ; if (password== 1000 ){ System. out .println( "...

#15 What is Identifier in Java Language ? Difference Between Identifier & Variable in Java

चित्र
  package com.sudhirtheindian2.java123 ; public class identifier { public static void main (String[] args) { // What is identifier in java // identifier refer to the name of variable ,methods, // classes etc // int a; a is identifier // void k1() ; k1 is method as identifier // class A; A is class as identifier // instance B ; B is instance as identifier // } }

#14 What is Variable in Java ? Types of Variable ? Use of Local , Static ,Instance & Final Variable

चित्र
  package com.sudhirtheindian2.java123 ; import java.util.Scanner ; public class variable { int a = 10 ; public static void main (String[] args) { // What is variable and types of variable in java // 1 variable is the name of memory location where // we stored different types of value // 2 without variable name we can not store value // types of variable // // 1 local // 2 static // 3 instance // 4 final //local variable // 1 under the block { } // 2 without making object we can access local variable // static variable // 1 with static keyword // 2 without making object we can access static variable // instance // 1 under the class // 2 outside of method or block // 3 without making object we can not access instance variable // final // we can not change final variable value } }

#13 What is Keyword in Java | 50 keyword in Java programming Language with Example

चित्र
  package com.sudhirtheindian2.java123 ; public class keyword { public static void main (String[] args) { // What is keyword and how many keyword in java ? // keyword are the registered word whose meaning is already // defined in the java compiler // 1 we can not use keyword for our personal use // int int =1; we can not use int as variable name int a = 2 ; // int int =2; // 2 keyword are case sensitive // int - ---- INT // int a = 1 // inT a =3 // 50 keyword in java language // // byte ,short ,int, long, float, double, void ,char, boolean, if // else ,for , do, while, break, continue, default ,private, protected // public, extends ,implements ,final ,finally ,try, throw, throws // static, volatile, import, class, interface, new, native, instanceof // package ,return, this ,super, switch, case // assert ,abstract ,transient ,synchr...

#12 What is DataType in Java | Types of DataType | Primitive & Non - Primitive DataType Example

चित्र
  package com.sudhirtheindian2.java123 ; public class datatype { public static void main (String[] args) { // What is datatype and its type // datatype specifie the different type of value // that are stored on the variable // type of datatype // 1 premitive // 2 non-premitive // premitive // (1) numeric // byte 1 // short 2 // int 4 // long 8 // double 8 // float 4 // 2 non numeric // char 2 // bolean 1 bit(true/false) // non premitive // class // array // string // } }

#10 What is Compilation and Execution Process in Java Language | Logic Behind Java Code

चित्र
  package com.sudhirtheindian2.java123 ; public class compilation_and_executatio_process { public static void main (String[] args) { // What is compilation_and_execution_process in java // 1 FirstProgram.java ----source code // 2 javac ----------java compiler // (when we submit source code to java compiler // then java compiler(javac) compile the source code // and make byte code) // 3 FirstProgram.class ------- byte code // the length of .class is 8 bits = 1 bytes // so we call byte code // we can not understand byte code // byte code provide security // 4 JVM(java virtual machine) // for interprate the bytecode // we send jvm // jvm interprate the bytecode // jvm can understand byte code // 5 output // after interprating jvm provides output of code } }

#3 What is History of java Language ? java का इतिहास क्या है ?

चित्र
  package com.sudhirtheindian2.java123 ; public class history_of_java { public static void main (String[] args) { // what is history of java // 5 points about history of java // 1 starting name of java was ----- oak // 2 oak was the simble of different country and also // name of some comapany and it was exist already // 3 the name of coffee in indonesia was java // so jamses goslin named java // 4 we can see the symble of java is coffee tea // 5 extention of java language is .java } }

#2 What is Syntax of Java Language | Why static in java ? Explanation of Every Code in Java

चित्र
  package com.sudhirtheindian2.java123 ; class syntax_of_java { public static void main (String[] arg) { System. out .println( "hi" ) ; // 1- create a class and provide name // example- syntax_of_java is class name // 2- { open curley bracket // 3-} close culey bracket // 4 class has method, here main is method name // main method - program execution start from here and end // starting and ending point of the program is main method // 5 why main method is public ? // jvm(java virtual machine) run the program outside so // main method is public // if main method is not public then jvm can not run the program // 6 why main method is static ? // without making object of this class // we can execute code written in main method // 7 why main method is void ? // there is no requirement to return anything // 8 main(String[] arg...