Course Content
Introduction of Java
What is Java? An introduction to the Java programming language. History of Java How Java was created and its evolution over time. Features of Java Key characteristics that make Java unique and powerful. Advantages of Java The benefits of using Java for software development. Java Development Environment Setting up and getting started with Java programming. Your First Java Program Writing and running a simple Java program to understand the basics. Conclusion A summary of what we've learned about Java and its significance in the world of programming.
Java Development Kit
Introduction to JDK Setup Overview of the importance of setting up the JDK for Java development. Understanding JDK Explanation of what JDK is and its components. Difference between JDK and JRE (Java Runtime Environment). Downloading JDK Step-by-step guide on downloading the JDK from the official Oracle website. Alternative sources for downloading JDK, if applicable. Installing JDK Instructions for installing JDK on different operating systems (Windows, macOS, Linux). Troubleshooting common installation issues. Setting up Environment Variables Explanation of environment variables and their role in Java development. Instructions for setting up PATH variable to include JDK bin directory. Verifying JDK Installation Steps to verify that JDK is installed correctly on the system. Running simple commands to check JDK version and other details. Conclusion Recap of key points covered in the topic. Encouragement for further exploration and learning in Java development.
How Java Works
Java is a excessive-level, object-orientated programming language that follows the "write once, run everywhere" precept. Here is a brief evaluate of how Java works. Compilation: The Java supply code is written in a human-readable format and saved in documents with a .Java extension. This record is then compiled into bytecode through a platform-impartial Java compiler (javac) that copies this system. Bytecode: Instead of producing system-particular code, the Java compiler generates bytecode, which is a set of instructions that may be finished via the Java Virtual Machine (JVM) Bytecode isn't always platform-independent, which means that it can run on tool or operating machine on which the JVM is mounted. Processing: The JVM manages Java bytecode processing. It translates the bytecode and interprets it into gadget code that can be understood by means of the underlying hardware. This carrier permits Java applications to run on a couple of devices and systems with out change. Memory control: Java consists of automatic memory management thru rubbish series. This means that the JVM routinely allocates unused reminiscence, supporting to prevent reminiscence leaks and improving normal overall performance. Platform independence: One of the key features of Java is platform independence. Because Java packages are compiled as bytecode while they're carried out at the JVM, they can be executed on any device or running gadget that helps Java, without the need for recompilation In precis, Java works by using compiling the source code into bytecode, that's then finished through the JVM. This enables Java programs to be platform unbiased and run on a huge range of devices and operating structures.
Variable declaration
Variables in Java are bins that maintain facts values. Here is a summary of variables in Java. Declaration: Variables must be declared before they can be used in Java. This consists of naming a variable by way of specifying its facts type. Example: Java Copy the code int age of man or woman; // Declaration of an integer variable named age Initialization: A variable can also be initialized at announcement time, where a fee is assigned to the variable. Example: Java Copy the code int age = 25; // Declaring and initializing an integer variable named years with cost 25 Data Types: Java supports a number of information types for transformation, including primitive information sorts (along with int, double, char) and reference records kinds (which include String, arrays, and items). Scope: The scope of a variable refers back to the region of ​​this system in which the variable may be accessed. Variables could have local scope (restricted to a specific block of code), example scope (relative to an example of a category), or elegance scope (disbursed across all instances of a category). Name contrast conference: Variable names in Java must obey sure naming conventions. Variable names start with a length, dollar signal ($), or underscore (_), and may be accompanied by a duration, duration, greenback sign, or underscore. Additionally, variable names are case touchy. Final adjustments: Changes in Java may be detailed as very last, because of this that their cost can not be modified when they have been brought on. Garbage Collection: Memory is allotted to variables in Java dynamically, and unused memory is reclaimed mechanically with the aid of the rubbish collector, which facilitates to manipulate memory extra efficaciously In precis, variables in Java are containers for storing statistics values, together with described information kinds, scopes, and naming conventions. Ja their major
In Java, literals are represented with the aid of constant values ​​within the source code. Here is a short summary of the actual syntax in Java. 1. **Real Numbers**: Numbers represent actual numbers and can be integers, floating factor numbers, or in scientific notation. Example: - `int x = 10;` (integer) . - `double y = three.14;` (real floating-point) . - `double z = 1.23e4;` (medical notation) . 2. **Character Words**: Character phrases constitute man or woman characters enclosed in unmarried fees. Example: - `char ch = 'A';` (self individual) . 3. **String Literals**: String literals constitute a chain of characters enclosed in double fees. Example: - `String str = "Hello, World!";` (String itself); four. **Boolean Literals**: Boolean Literals represent real or false values. Example: - `boolean flag = proper;` (actual boolean) 5. **Null Literal**: A null literal represents the absence of a price or null reference. It is often used to indicate that a variable does now not currently refer to an item. Example: - `string str = null;` (self null); In summary, characters in Java are fixed values ​​used to symbolize numbers, characters, strings, Boolean values, and null references at once within the supply code. They offer an smooth manner to assign default values ​​to variables and are an crucial part of Java programming.
Type Conversion
Type conversion in Java refers back to the process of changing a value from one records kind to any other. Here is a quick review of type conversion in Java. 1. **Implicit Type Conversion**: Also called computerized kind conversion, it takes place when the cost of one records kind is robotically transformed by the compiler to any other information kind This generally occurs while the goal records type can exchange variety and precision of source facts type without data loss. Example: ```No int numInt = 10; double numDouble = numInt; // Implicit conversion from int to double ``` 2. **Explicit Type Conversion (Casting)**: Also called manual kind conversion or casting, this explicitly specifies the goal information type to which the cost have to be converted to this is important when the target information kind does not fit the range or precision of the source facts type, which can cause lack of data e.G. ```No double double double = 3.14; int numInt = ( int ) numDouble ; // Implicit conversion from double to int (Casting). ``` three. **Widening (Automatic) Conversion**: This occurs whilst the fee of a small facts set is converted to a huge statistics set. Java can extend variables because it does now not provide lack of facts. For instance, a double conversion of an int. Four. **Narrowing (Manual) Conversion**: This occurs when a price of a larger records type is converted to a smaller facts type. Explicit casting is important to reduce Java adjustments due to the fact it may cause lack of statistics. For example, if you convert a double to an int. In precis, a kind conversion in Java is an specific or implicit conversion of values ​​from one statistics kind to another. The obvious adjustments are made mechanically by com
Assignment Operator
In this lecture we are discussing: 1)Assignment operator a) = is used to assign a value to a variable b) += is used to assign a value to a variable by adding it to the existing value c) -= is used to assign a value to a variable by subtracting it from the existing value -- there are many but in this lecture we discussing only some e.g of = int num1=11; int num2=12; int result = num1 + num2; int result1=num1-num2; int result2=num1*num2; int result3=num1/num2; e.g of += int num=1; num +=1; = num = num+1; num +=5; = num = num+5; e.g of -= int num2=2; num -=1; num =num-1; num -=5; num =num-5; 2)increment and decrement operator -- there are two type of increment and decrement operator a) pre b) post -- post increment and decrement operator int num=1; num++; System.out.println(num); // 2 -- this operator is known as post increment operator num--; System.out.println(num); //1 -- this operator is know as post decrement operator -- pre increment and decrement operator int num=2; ++num; System.out.println(num);//3 --num; System.out.println(num);//2 Difference between pre and post operator e.g for that we take one example int num=5; System.out.println(num++); // 5 is print on console int num1=5; System.out.println(++num); //6 is printed on screen in post first assignment and then increment e.g int num=5; int copy; copy=num++; in this case first num=5 assign to copy then increment the num copy value is 5; in pre first increment then assignment e.g int num=5; int copy; copy = ++num; in this case first increment num value from 5 to 6 then assign to copy. copy value is 6;
Relational Operators in java
In this lecture we will learn: - Relational Operators in Java - Types of Relational Operators - The return type of relational operations Relational operators are used where we need to compare things. - We can use less than, greater than or also compare two values like they are equal or not. - In Java, equal to (=) is an assignment operator that is used to assign values. x=5 ( here, we are assigning the value 5 to the variable x). - Double equal to (==) is used to compare two values. - If we have to check the values are not equal, then we use not equal to an operator (!=). Relational Operators:- less than greater than equal to for comparison not equal to less than equal to greater than equal to - Relational operators return a boolean result after the comparison. - They are mostly used in looping and conditional statements.
Logical Operator in Java
In this lecture we will learn: - What are relational operators? - AND operator - OR operator - NOT operator If we need to combine the result of two or more relational operators, then we use logical operators. - We use logical operator in between two or more results of relational operators. - AND operator (&&), OR operator (||) and Not operator (!) are logical operators. 1) In case of AND Operator: - If both are true - true - If one is true and other is false - false - If one is false and other is true - false - If both are false - false * If first condition is false then it will not check for the another one and it will increase the execution time. Thus, because of its less time it is known as short- circuit. 2) In case of OR Operator: - If both are true - true - If one is true and other is false - true - If one is false and other is true - true - If both are false - false * If first condition is true then it will not check for the another one and it will increase the execution time. Thus, because of its less time it is known as short- circuit. 3) In case of Not Operator: - It is basically used to reverse the things. It means if result is false, it will do true. If the result is true, it will do false. * Not operator just do the opposite. - We can use as much logical operators as we want in between the relational operations.
Logical Operator in Java
In this lecture we will learn: - What are relational operators? - AND operator - OR operator - NOT operator If we need to combine the result of two or more relational operators, then we use logical operators. - We use logical operator in between two or more results of relational operators. - AND operator (&&), OR operator (||) and Not operator (!) are logical operators. 1) In case of AND Operator: - If both are true - true - If one is true and other is false - false - If one is false and other is true - false - If both are false - false * If first condition is false then it will not check for the another one and it will increase the execution time. Thus, because of its less time it is known as short- circuit. 2) In case of OR Operator: - If both are true - true - If one is true and other is false - true - If one is false and other is true - true - If both are false - false * If first condition is true then it will not check for the another one and it will increase the execution time. Thus, because of its less time it is known as short- circuit. 3) In case of Not Operator: - It is basically used to reverse the things. It means if result is false, it will do true. If the result is true, it will do false. * Not operator just do the opposite. - We can use as much logical operators as we want in between the relational operations.
If Else condition
In this lecture we are discussing: 1)What is conditional statements? 2)types of conditional statements a) if-else b) switch (next lecture) c) ternary operator (next lecture) d) nested if-else (next lecture) e) if-else-if ladder (next lecture) 3)syntax of if-else 4)example on if-else condition #1 -- conditional statement is a statement that can be true or false. -- suppose if ask student is pass. (answer yes or no) -- this type of statement of statement is conditional statement. #2 In this part we are only discussing about if-else and in next lecture we are discussing if-else-if ladder, ternary operator and switch statement. #3 syntax of if-else -- condition is either true or false after evaluation -- remember like c and c++, we cannot use number directly as condition of if-else - if(5) -- not allowed in java -- you get Type mismatch: cannot convert from int to boolean if(condition) { //code //either this part execute } else { //code //or this part execute } #4 example: if want to check a given number is even or odd then; int num=13; if(num%2==0) System.out.println("Even"); //here we not use braces for single statement {} else System.out.println("Odd"); // here we not use braces {} Note: for single statement braces is not required but for multiple statement it is required.
If else If condition
In this lecture we are discussing: 1) what is if-else-if ladder? 2) syntax of if-else-if ladder 3) example of if-else-if #1 -- if-else-if ladder is a series of if, else if or else statements that are executed based on the boolean condition. -- if else if ladder is used to test multiple conditions #2 syntax of if-else-if ladder if(condition1) { //block of code } else if(condition2){ //block of code } else if(condition3) { //block of code } else{ //block of code } Note: only one block is executed from all. If all condition is false then else part executed #3 -- check greatest number from three number. int x=8; int y=7; int z=6; if(x y && x z) System.out.println("x is greater"); else if(y z) System.out.println("y is greater"); else System.out.println("z is greater");
#14 Ternary Operator in Java
In this lecture we are discussing: 1)What is ternary operator? 2)Why do we need ternary operator? 3)Syntax of ternary operator 4)example of ternary operator #1 -- ternary operator is shorthand of if-else statement. #2 why we need ternary operator? a) to reduce the code b) to make the code more readable c) to make the code more compact #3 Syntax: variable = (condition)?value1 if condition is true :value2 if condition is false boolean result =(5 less then 6)? true :false; //result false #4 example: in if-else we can check a given number is even or odd now we code this problem by ternary operator. int num=13; String str=(num%2==0)?"Even":"Odd"; System.out.println(str); //output: Odd
#15 Switch Statement in Java
In this lecture we are discussing: 1) What is switch statement? 2) why we need switch statement? 3) What datatype can we use in switch? 4) Syntax of switch and example 5) Need of break 6) Need of default #1 -- switch statement is a multiway branch statement that allows a variable to be tested for equality against a list of values each value is called a case, and the variable being switched on is checked for each switch case. #2 if we have multiple test cases and we want to test for a particular value then we can use switch statement. At the place switch we can also use if-else-if ladder. e.g suppose user enter a your date of birth and we want to check from multiple year then in this case we can use switch case. #3 what dataType we can use in switch statement? -- the switch statement can have a number of possible execution paths. A switch works with the byte, short, char, and int primitive data types. It also works with enumerated types (discussed in Enum Types), the String class, and a few special classes that wrap certain primitive types: Character, Byte, Short, and Integer. #4 Syntax of Switch and example: switch(variable){ case x1: //code break; case x2: //code break; default: //code } example: int x=9; switch(x){ case 8: System.out.println("8"); break; case 7: System.out.println("7"); break; default: System.out.println("No match found"); } #5 Need of break -- The break statements are necessary because without them, statements in switch blocks fall through: All statements after the matching case label are executed in sequence, regardless of the expression of subsequent case labels, until a break statement is encountered. The program shows statements in a switch block that fall through. int x=5; switch(x){ case 5: System.out.println("five"); case 4: System.out.println("six); default: System.out.println("default"); } output: five six default Since, we are not using break after matching the case 5 it execute all remaining statements without check. #6 Need of default: The default section handles all values that are not explicitly handled by one of the case sections. example: int y=9; switch(y){ case 8: System.out.println("8"); break; case 7: System.out.println("7"); break; } In this case you don’t get any result because no case is match and since no default case is available so, nothing we get.
What’s new in Java Switch | Switch Statement and Expression
#16 Need For Loop in Java
In this lecture we will learn: - What are loops in Java? - Different kinds of loops - Need for loops in Java #1 Loops in Java is a feature used to execute a particular part of the program repeatedly if a given condition evaluates to be true. - We use loops, when we have to execute a same statement multiple times. - In Java, we have different types of loops:- 1. while loop 2. do while loop 3. for loop - Different type of loops have different kind of use- cases like a finite number of times or based on some condition. #2 Need of loops in Java:- - It reduce the size of the code. - Loops make an easy flow of the control. - Loops reduce the time complexity and space complexity.
#17 While Loop in Java
In this lecture we will learn: - While loop in Java - When to use the while loop? - Syntax of while loop - Nested loops Loops can be used when we have to repeat something. #1 While loop:- - While loop is used with a condition. We need to provide a condition inside the while loop. - If we will give the condition as true inside the while loop then it will infinite times. -If we do not provide any condition inside the while loop then it is known as an empty loop. - We require an iterator inside the loop to execute the statements. -- We use plus opertaor(+) for concatenation. When we have to concatenate or join two things, we simply use plus operator. - We need to put the condition inside the while loop for executing statements. We run the loop until the condition gets false. - When the condition inside the while loops get false, then after that it will not execute the statement of the block and the iterator directly jumps out of the block. - The while loop is used when the number of iterations is unknown but the terminating condition is known. - While loop is also an entry-controlled loop as the condition is checked before entering the loop. The test condition is checked first and then the control goes inside the loop. Syntax of while loop:- while(condition) { statements; } #2 Nested loops:- - We can also use a loop inside another loop statement. A loop inside another loop is known as a nested loop. - There can be any number of inner loops inside an outer loop.
#19 For Loop in Java
In this lecture we will learn: - Overview of a while loop - For loop and its point - Syntax of for loop - Nested for loops #1 -In the while loop we have three things: Initialization, Condition, and then increment. -We do these three things in different lines in a while loop. -Sometimes we do not know about the ending point, where this loop will get end. As it may end based on some conditions. #2 - In the finite loop, we know about its starting and ending. - For loop supports three different statements in one line. - We can put initialization, condition and increment in one single line in for loop. - It is mostly used when the number of iterations is fixed. - Because of the binary format computer starts from 0. - So, in general, we start from 0 and end at count-1 ie., one less than the total number of iterations. - Loops are very useful when we have to print some pattern or want to print things repeatedly. #3 Syntax of For Loop:- for(initiation; condition; incrementation or decrementation) { statements; } * init - The init expression is used for initializing a variable, and it is executed only once. * condition - It executes the condition statement for every iteration. If it evaluates the condition to be true, it executes the body of the loop. The loop will continue to run until the condition becomes false. * incr/ decr - It is the increment or decrement statement applied to the variable to update the initial expression. - First initiation and condition statement execute and then execution of statements takes place and then increment takes place at last. - We can also skip any of the three parts as per the need. #4 Nested For loops:- - We can also use nested for loops as same as while loop. Nested loops mean loop inside a loop. - Whenever the outer loop meets the condition, the inner loop is executed completely.
#20 Which Loop To Use in java
In this lecture we will learn: - Use case of for loop - Use case of while loop - Use case of do-while loop For loop:- If you know how many iterations you want to go for loop (intiliazing vaue, condition, increment or decrement) - Most of the times for loop is used. While loop:- When you need to read the file go for while loop, if the number of iterations is not known. - While loop will be used mostly when we want to read a file or read a database. - For loop can also be used as a while. Do While Loop:- If you condition get false but you want to exceute the code at least once. - It will runs one for sure whether the condition is true or false.
#21 Class And Object Theory in Java
In this lecture we will learn: - Java is an object-oriented language - What are objects? - What are classes? - How do classes and objects create? #1 Java is Object- Oriented Programming:- - In the real world, everything is an object like a pen, mouse, glass, etc. - Every object has two things: - An object knows something ( It has some properties) - An object does something( It has a behaviour) - Every object has a property and behaviour. It can also have multiple properties as well as multiple behaviours. - To create an object, first, we need to create a class. - Class act as a blueprint that contains the designing of an object. #2 - JVM creates objects in Java. - JVM creates an object but it requires a blueprint. - Thus, you create a class file that class file gets compiled to create a byte code and that byte code goes to the JVM and then JVM creates an object.
#22 Class and Object Practical in Java
In this lecture we will learn: - Class in Java - Syntax of class in Java - Creation of objects in Java - Methods in Java #1 Whatever we do in Java, we do it in a class. A class is a user-defined blueprint or prototype from which objects are created. - In a class, we have methods and variables. - Class will be created in the same java file. - We can create any number of classes in a program. - Class does not occupy memory. Syntax of a class:- class classname { methods, variables } #2 - Every object has two things: properties and methods. - When an object of a class is created, the class is said to be instantiated. All the instances share the attributes and the behavior of the class. - Action will be done with the help of methods. - We need to specify the access to methods. We will specify it as public if we want it to be called from anywhere else. - If we want the method to return any value then we need to specify its return type like int for Integer type values. - As Java is a statically typed language so you have to specify the return type in it. Syntax of method:- = access modifier return type method name() public int add() { statement; } #3 - We need an object to call a method from a different class. - Creating an object:- classname reference variable= new classname(); - reference variable is used to tell that this variable is made to establish a reference between a class. - new keyword is used to tell that we have to utilise the space for an object. - We can call a method by using the reference variable of the object. - We have to pass the values if we want some operations to be on them. - We also have to accept values in a method as well if we pass some values. For this, we have to specify parameters in a method based on the type of passed values.
#23 JDK JRE JVM in Java
In this lecture we will learn: - What is JVM? - What is JDK? - What is JRE? - Importance and uses of JVM, JRE, and JDK. #1 To compile the Java code, we need a tool and that tool is known as JDK ( Java Development Kit). - Byte code runs on a machine so we have to convert the java code into the byte code. - On installing the JDK, we get both updated JRE and JVM. #2 JVM stands for Java Virtually Machine. - JVM is the space where you execute the code. - JVM is used to make the Java language a platform- independent. - You have to compile the code through JDK and then run the code through JVM. - JVM is platform dependent and it needs to be built for a particular OS. - JVM is platform-dependent. #3 JRE stands for Java Runtime Environment. - JRE contains all the in-built classes and other extra files and libraries that we can use in our code. - JRE validates the byte code. - JRE loads a class. - If you use extra libraries, and you also need an environment. An additional layer is present above the OS known as JRE. #4 - JVM is a part of JRE. JRE includes JVM and libraries. JVM - Java Virutal Machine JRE - Java Runtime Environment - For development purposes, you need to install JDK (Java Development Kit) which consists of JRE and JVM.
#24 Methods in Java
In this lecture we will learn: - Method in Java - Use of methods in Java - Main method in Java - return type in methods - Syntax of method #1 A method in Java or Java Method is a collection of statements that perform some specific task and return the result to the caller. - Methods in Java allow us to reuse the code without retyping code. - In Java, we create the components with the help of classes. - Every class has a behavior and it is defined through the method. - Behaviour or method is defined with the round brackets (). - For every method, we also have to specify the type of access to it. - Method does some tasks and it also returns something. - We can call methods by creating an object. - We can pass also pass values in a method. - We can also put conditions inside the method like with the help of if..else. - return keyword stops the execution of a method as it does not execute the further statements after it. #2 -- void is used when we do not want a method to return something. -- String is used to return a string value. -- int is used to return an integer value. - Main method is the start of execution from where the program begins. #3 The syntax for method:- class Computer { public void playMusic() { System.out.println("Music Playing.."); } }
#25 Method Overloading in Java
In this lecture we will learn: - Parameters of a method - Method overloading in Java - When does method overloading happen? - Different ways of method overloading in Java #1 It is not compulsory that a class should have methods and variables. It will be empty also. - The parameters that except the values in a method should be equal to the parameters that we pass in a method to call it. - As it might create a problem if the parameters excepted by the method are not equal to the number of values passed. - So, to overcome this problem we do overloading. - As we can have two methods we the same name but different parameters. - Either the number of parameters or the type of parameters should be different. - Method with the same name and parameters but with different return types will also not work. The return type does not matter here. Method name and parameters matter only. #2 Method overloading:- In Java, there can be more than one method with the same name but the number of parameters or type of parameters should be different. - Method overloading is also known as Compile-time Polymorphism, Static Polymorphism, or Early binding in Java. - In Method overloading compared to parent argument, child argument will get the highest priority. #3 Different ways of Method Overloading in Java:- 1. Changing the number of parameters - Method overloading can be achieved by changing the number of parameters while passing to different methods. 2. Changing Data Types of the Arguments - If methods have the same name but have different parameter types then also methods are considered as overloaded. 3. Changing the Order of the Parameters of Methods - By rearranging the parameters of two or more overloaded methods.
#26 Stack And Heap in Java
In this lecture we are discussing: 1) Memory management in java and typed of categories to store data in memory. 2)What is stack ? 3)What is heap ? 4) where instance variable and local variable is allocated? #1 In java we are managing our managing our memory using two data structure stack and heap. two categories to store data in memory: 1) Stack data structure 2) heap data structure #2 Stack is data structure which follow LIFO(Last in First Out) principle. #3 heap is data structure which is used to store data in form of object and object is a collection of data and method. #4 class Student{ int instVariable; //store in object and object created in heap public static void main(String []args){ int localVariable=0; //local variable store in stack frame of method in stack area. Student st=new Student(); //st is reference variable store address of new Student() object } public int add(int num1,int num2){ return num1+num2; } } -- instance variable stored in object and object are in heap therefore we can say that instance variable created in heap. -- method declaration and definition is present in object but actual implementation present in stack frame of stack. -- local variable created in stack during call of method. -- stack frame of called method is present in stack area. -- st is reference variable created inside the current stack frame and it is reference variable store address of student object created in heap area. -- new Student() create object in heap area and pointed by his reference variable.
#27 Need of an Array in Java
In this lecture we are discussing: 1)What is an Array ? 2)Why do we need array? 3)Simple variable declaration vs Array variable declaration #1 -- An array is collection of similar type of data and store in contagious memory. -- e.g marks is collection of different marks obtained by 4 student then {24,25,26,27} is that marks then this marks store in contagious manner in memory. #2 Why so we need array? -- suppose we want to create five variable for student marks -- int m1=24; int m2=25; int m3=26; int m4=27; int m5=28; -- it is quite tedious to store multiple value in multiple variable and remember the marks. -- now one reason is that to create single variable which can store multiple value and access by its index. #3 Simple variable declaration vs Array variable declaration -- for creating normal variable int num; boolean result=true; -- for creating array variable int nums []; or int []nums; -- both are acceptable to declare array variable
#29 Multi Dimensional Array in Java
In this lecture we are discussing: 1)what is multidimensional array? 2)Why do we need multidimension array? 3)How to create multidimension array? 4)How to access element of multidimension array? 5)how to use enhanced for loop and simple loop in multidimension array to traverse array element? #1 what is multidimension array? -- simple we can say it is array of array ------------- | 1 | 2 | 3 | ------------- | 4 | 5 | 6 | ------------- Above is example of 2-d array which has 2 rows and 3 columns. -- it seems to look like a bigger array consist two single dimension array. -- just like we have 3-d array and array might be n-dimension. #2 Why do we need multidimension array? -- to solve some matrix problem to solve grid problem #3 How to create multidimension in java? -- different Ways to create array in java a)Literal notation Literal notation: int [][]arr = {{1, 2, 3},{4,5,6}}; b)Object notation int [][]nums=new int[2][3]; -- general syntax for object notation: -- dataType [][]arrayName=new dataType[rows][columns]; #4 how to access element of multidimension array element? let we create 2d array arr int [][]arr = {{1, 2, 3},{4,5,6}}; ------------- | 1 | 2 | 3 | ------------- | 4 | 5 | 6 | ------------- -- there are two rows whose index are 0,1 and columns are 0,1,2. -- want to access 2 which are at row 0 and columns 1 -- System.out.println(arr[0][1]); //give 2 simple if you want to access element at ith row and jth column then; arr[i][j]; //it is value at that position #5 How to use enhanced for loop for array name arr: -- using for loop traverse all element -- arr.length give number of rows and arr[0].length give number of column in first row for(int i=0;i arr.length;i++){ for(int j=0;j arr[0].length;j++){ System.out.print(arr[i][j]+" "); } System.out.println(); } using enhanced for loop: for(int x[]: arr){ for(int y:x){ System.out.print(y+" "); } System.out.println(); } general syntax for enhanced for-loop for(dataType singleDimension[]: twoDimension){ for(dataType element: singleDimension){ System.out.println(element); } }
#30 jagged and 3D Array in Java
In this lecture we are discussing: 1)What if array of array of different size ? 2)Jagged array concept 3)If i donot know column size of array 4)traverse the array using for loop and enhance loop #1 Suppose we want to create a 2d dimensional array such that it has 5 rows but we donot know for each row we need different size for column. for that we go for array of array of different size ------------- | 1 | 2 | 3 | --------------------- | 4 | 5 | 6 | 7 | 8 | ------------------------- | 1 | 5 | 9 | 2 | 4 | 7 | ------------------------- in above diagram we have three rows and first row has 3 elements second row has 5 elements and third row has 6 elements. #2#3 jagged array concept come in java 8 -- Jagged array is a multidimensional array where member arrays are of different size. For example, we can create a 2D array where first array is of 3 elements, and is of 4 elements. Following is the example demonstrating the concept of jagged array. syntax to create -- int nums[][]=new int[3][]; nums[0] =new int[3]; nums[1] =new int[5]; nums[2] =new int[6]; initalize value in array using random()method present in Math class for(int i=0;i nums.length;i++){ for(int j=0;j nums[i].length;j++){ nums[i][j]=(int)(Math.random()*10); } } #5 Traverse using for loop : for(int i=0;i nums.length;i++){ for(int j=0;j nums[i].length;j++){ System.out.print(nums[i][j]+" "); } } Traverse using enhanced for loop: for(int x[]:nums){ for(int y:x){ System.out.println(y); } } Note: Just like 2-d jagged array we can create 3-d , 4-d jagged array for cursoity: int num[][][]=new int[3][][]; num[0]=new int[2][]; num[1]=new int[3][]; num[2]=new int[4][]; num[0][0]=new int[2]; num[0][1]=new int[3]; num[1][0]=new int[4]; num[1][1]=new int[5]; num[1][2]=new int[6]; num[2][0]=new int[7]; num[2][1]=new int[8]; num[2][2]=new int[9]; num[2][3]=new int[10]; Intialize the array: for(int i=0;i num.length;i++){ for(int j=0;j num[i].length;j++){ for(int k=0;k num[i][j].length;k++){ num[i][j][k]=(int)(Math.random()*10); } } } Traverse the element of array: for(int i=0;i num.length;i++){ for(int j=0;j num[i].length;j++){ for(int k=0;k num[i][j].length;k++){ System.out.print(num[i][j][k]+" "); } } }
Threads in Java
Java Course [Free]- #Gift for Students
About Lesson

In this video we will learn:

– Naming Convention Rules in Java

– Camel casing in Java

– What is Sanke casing?

– Advantages of naming convention




Naming Convention Rules:-

A naming convention is a rule to follow as you decide what to name your identifiers such as class, package, variable, constant, method, etc.

– A class name should start with a capital letter.

e.g.,  public class Calc

– Variable names and methods start from a small letter

e.g.,  marks, show()

– Interface also starts with capital letters.

e.g.,  Runnable

– Constants have all letters capitalized of a word.

e.g.,  PIE, BRAND

– Packages contains lowercase letters. Multiple words can be joined by using the dot(.).

e.g., java.util, java.lang



Camel Casing:- We combine words as the first letter of every word should be in uppercase.

e.g.,  HelloWorld, MyFirstClass

– Mostly Java developers work on camel casing.


Snake Casing:- We combine different words using an underscore (_) in between them.

e.g.,  Hello_world, my_first_class



Advantages of the naming convention:-

– These conventions make the code more readable.

– It helps us to distinguish between different things.