How to create a Java Program -
How to create a Java Program -
*Step-1: write a syntax of Java Program
//Begining of a class name.
//Begining of a Method of Java program.
//End of a method name.
//End of the class name.
//class Class Name{}.
*Step-2: Save your program with the same ClassName.
*Step-3: compile the code with the command "JAVAC ClassName".
*Step-4 Now run the program code on command prompt with command "JAVA ClaasName".
Definition of Main words using in the program -
*Public - This word using for access outside of class.
*Static - This word is using for code, they can run itself without an object.
*Void - This word is used for does not return anything.
*Main - This word is used for the Method name entry point.
*String args[] - This word is used for passing arguments through the command line.
Some Rules for making class.
- Class names should be nouns.
- MIxed case with the first letter of each internal word capitalized.
- cannot start with numbers.
- No special character allowed except '_' & '$'.
Variables in Java programming language -
Variable is a container which holds a value. Variable assigned with a data type.
Its name for a memory location.
There are three types of variables.
- Local Variable: variable declared inside a method. We can use only inside the method. Class not aware of any variable scope inside a method. A local variable can not be defined with a Static keyword.
- Instance variable: variable declared inside a class. not declare as static. Each instantiated object of the class has a separate copy.
- Static Variable: Variable declared as static is called a static variable.IT can't be local. Create a single copy and share with all instance of a class.
*Declare a variable -
data_type_name = Value;
Ex - int x = 10;
double y = 22.3;
*Naming Convention -
No space to allowed in a variable name.
Can not start with '$' and other '_' symbol not allowed.
Variable name starts with a small letter it's not mandatory its for lengthy variables names that have more than one word do it like the following.
"int first number = 10;"
In java everything case sensitive [keywords and name].
*Data Types -
Data types are the value that can be used in Variable each type Has a different size.
there are 2 types of them.
1.Primitive Data type
2.Non-Primitive Data Type
*Operators -
*Keywords -
There is a '51' reserved word in a JAVA Programming language, which means '51' predefined meaning words present in JAVA. In Java programming language these keywords did not use for other purposes.
JAVA Control Statement -
If statement:
There are multiple 'If' condition.
'If' the condition is true then do it and condition is not true then don't do it.
Nested If Statement :
So I have a condition, the condition is true am going inside and one more 'If' condition So that It is called a Nested If condition.
If-else Statement :
So you go and check a condition if in case the condition is true the executing a block in case condition is not true that means it going to lose block.
If-else-If Statement:
A few steps of the 'if-else-if' condition if some condition or else go-to another condition.
Switch Case Introduction -
Switch case is mostly used with break statements even those it's optional.
- When we have a number of options and a number of choices and we might need to perform different tasks for each choice.
- Each case statement can have a break statement in order to stop the flow, else all of them will be executed.
- Duplicate case values are not allowed.
- Values for a case must be the same type as the switch.
Array Introduction -
The array is used to store multiple values in a single variable instead of declaring separate variables for each value.
To initiate an array define the variable type with[] square brackets.
Access the elements using the index numbers.
Looping Concepts -
For Loop:
- For loop is used to integrate a part of code several times.
- In case if the number of iteration is fixed, it is better choices to use for loop.
We have three types of 'For' loops.
- For loop
- For each
- Labeled for loop
While loop:
- While loop is used to integrate a part of the program several times for loop.
- But we will not have the iteration fixed.
- While condition verified then it will go inside the loop.
- Increment/Decrement happens inside while loop
Do-While loop:
- Similar to while, used to iterate a part of code several times, Again we will not have the fixed value for the limit.
- But at least once loop will run.
- Because this one executes the code then evaluates the condition.
Break and Continue Statement -
Break statement :
- The break is used to come out of the loop instantly.
- Whenever break encounter in a loop, control directly come out of loop gets terminated
- The break statement is used to break the loop or switch statement.
Continue statement :
- It used to loop when you need to jump to the next iteration immediately.
- Can be used in for, while and do-while loop.
Comment in Java -
- The data which we provided inside the comments we will not use the comments we will not take for compilation.
- It used to tell the compiler not the use the commented lines.
- We can use to provide some additional information or explanation forex class method and variables.
Types of Comments:
- Single line method: The single line comment is used to comment on only one line.
- Multi-line method: The multiline comment is used to comment multiline of code.
- Documentation: The documentation comment is used to create document API, you need to use java document tool.
String (It belongs to class) -
- It is a sequence of characters.
- The string is an immutable object which means, its constant and cannot be changed once it has been created.
- There are multiple ways to create a String.
- String level
- Using a new keyword
- Java string class provides a lot of methods of performing operations such as compare, concatenation, equals, split, and length.
A Way to create a String -
Learn More :
Keep it up good content ๐๐
ReplyDeleteThank-you Mam!!
DeleteNice Bro keep going on
ReplyDeleteThank you bro!!
DeleteWawwww amezing
ReplyDeleteThank you Mam!!
DeleteAmazing brother. This is called learn and teach๐๐
ReplyDeleteThank-you
DeleteAmazing brother. This is called learn and teach๐๐
ReplyDeleteThank you again vivek
Delete