Hello/Namaste everyone, this is our channel to teach , explore and learn Java language for all you guys in absolutely free .
We share our experience , knowledge and learnings in free in this channel about Java programming from basic . All you need to do is study step wise step and proceed further with your efforts and code in your life .
Hoping you guys will enjoy learn with us .
Sayonara,Good Luck
We share our experience , knowledge and learnings in free in this channel about Java programming from basic . All you need to do is study step wise step and proceed further with your efforts and code in your life .
Hoping you guys will enjoy learn with us .
Sayonara,Good Luck
public class Main {
public static void main(String [] args)
{
{System.out.println("Hello My code world Family,this is my first post");}
}
}
/* Every line of code that runs in Java must be inside a class.
And the class name should always start with an uppercase first letter.
In our example, we named the class Main.
*/
// The name of the java file must match the class name.
// The main() method is required and you will see it in every Java program:
// For now, just remember that every Java program has a class name which must match the filename, and that every program must contain the main() method.
// Inside the main() method, we can use the println() method to print a line of text to the screen:
public class Main {
public static void main(String [] args)
{
{System.out.println("Hello K T ❤ bhai ");}
{System.out.println("Hello Naresh bhai! ");}
{System.out.print("Mahima ");}
{System.out.print("Antriksh !");}
}
}/* here main difference is println or print word.. Println mean next line and print mean continue line. */
❤1
public class Main{
public static void main(String [] args){
{System.out.println(5+7);}
}
}
// output = 12
/* In Java, there are different types of variables, for example:
String - stores text, such as "Hello". String values are surrounded by double quotes
int - stores integers (whole numbers), without decimals, such as 123 or -123
float - stores floating point numbers, with decimals, such as 19.99 or -19.99
char - stores single characters, such as 'a' or 'B'. Char values are surrounded by single quotes
boolean - stores values with two states: true or false
*/
// output = Royal, Royal 115
String - stores text, such as "Hello". String values are surrounded by double quotes
int - stores integers (whole numbers), without decimals, such as 123 or -123
float - stores floating point numbers, with decimals, such as 19.99 or -19.99
char - stores single characters, such as 'a' or 'B'. Char values are surrounded by single quotes
boolean - stores values with two states: true or false
*/
public class Main
{
public static void main(String [] args)
{
String name;
name= "Royal";
{System.out.println(name);}
int a,b,c;
a=55;
b=60;
c=a+b;
{System.out.println(name + c);}
}
}
// output = Royal, Royal 115
int myNum = 5;
float myFloatNum = 5.99f;
char myLetter = 'D';
boolean myBool = true;
String myText = "Hello";
String firstName = "Royal ";
String lastName = "Riv";
String fullName = firstName + lastName;
System.out.println(fullName);
//output= Royal Riv
/* One Value to Multiple Variables
You can also assign the same value to multiple variables in one line:
*/
public class Main {
public static void main(String[] args) {
int a,b,c;
a=b=c=30;
System.out.println(a+b+c);
}
}
//output=90
All Java variables must be identified with unique names.
These unique names are called identifiers.
Identifiers can be short names (like x and y) or more descriptive names (age, sum, totalVolume).
Note: It is recommended to use descriptive names in order to create understandable and maintainable code:
Example--
int m = 60;
// Good
int minutesPerHour = 60;
The general rules for naming variables are:
Names can contain letters, digits, underscores, and dollar signs
Names must begin with a letter
Names should start with a lowercase letter, and cannot contain whitespace
Names can also begin with $ and _
Names are case-sensitive ("myVar" and "myvar" are different variables)
Reserved words (like Java keywords, such as int or boolean) cannot be used as names
These unique names are called identifiers.
Identifiers can be short names (like x and y) or more descriptive names (age, sum, totalVolume).
Note: It is recommended to use descriptive names in order to create understandable and maintainable code:
Example--
int m = 60;
// not so easy to understand what m actually is
// Good
int minutesPerHour = 60;
The general rules for naming variables are:
Names can contain letters, digits, underscores, and dollar signs
Names must begin with a letter
Names should start with a lowercase letter, and cannot contain whitespace
Names can also begin with $ and _
Names are case-sensitive ("myVar" and "myvar" are different variables)
Reserved words (like Java keywords, such as int or boolean) cannot be used as names
// Create integer variables
int length = 4;
int width = 6;
int area;
// Calculate the area of a rectangle
area = length * width;
// Print variables
System.out.println("Length is: " + length);
System.out.println("Width is: " + width);
System.out.println("Area of the rectangle is: " + area);
There are eight primitive data types in Java:
Data Type Size Description
byte ➡ 1 byte➡ Stores whole numbers from -128 to 127
short ➡2 bytes ➡Stores whole numbers from -32,768 to 32,767
int ➡4 bytes ➡ Stores whole numbers from -2,147,483,648 to 2,147,483,647
long ➡8 bytes ➡Stores whole numbers from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
float ➡4 bytes➡ Stores fractional numbers. Sufficient for storing 6 to 7 decimal digits
double➡ 8 bytes ➡Stores fractional numbers. Sufficient for storing 15 decimal digits
boolean ➡1 bit➡ Stores true or false values
char ➡2 bytes ➡Stores a single character/letter or ASCII valuesimport java.util.Scanner;
public class Main{
public static void main(String[]args)
{
Scanner X= new Scanner(System.in);
{System.out.print("Your name pls: ");}
String name;
name=X.next();
{System.out.print("Hey "+name+" Welcome🤗,\nPlease Enter Group Code: ");}
int code;
code=X.nextInt();
if(code==1010){
System.out.println("Correct Code,Group is open for you✔.");
}else{
System.out.println("Sorry, Wrong Code ❌");
}
}
}