Java Lessons Basic
Java Lessons Basic
2. Create Java project --> create package under SRC (source) --> create class under package
2.a) While creating class 'method stubs' will be ''public static void main (String[]args)
Java
=====
Package --> Class --> method(method means a code which performs some action)
==========
comment says what is the purpose of this class or method.... It just comments something. It is only
documenting what you want to say about it. It is not executed.
=====================
First Method
============
Second Method
=============
==================
Method One
-----------
/*
*/
Method two
--------------
=========
Box on the right side of eclipse which gives index kind of view of class, method etc. If we click on this,
the curson will go directly to it.
========
If we type 'System.' in Java it will show what are methods available in System class
===========================
https://www.learnjavaonline.org/en/Variables_and_Types
Although Java is object oriented, not all types are objects. It is built on top of basic variable types called
primitives.
package MyPackage;
/*
short my_variable=10;
float my_decimal=(float)4.5;
double my_double=11.56;
char my_char='A';
boolean is_true=false;
System.out.println(my_variable);
System.out.println(my_decimal);
System.out.println(my_double);
System.out.println(my_char);
System.out.println(is_true);
}
https://www.youtube.com/watch?v=qgMH6jOOFOE&list=PLS1QulWo1RIbfTjQvTdj8Y6yy
q4R7g-Al&index=5
package lesson1;
import java.util.Scanner;
What I learned?
String – it allows to add some text (example: hi there, how are you?)
https://www.youtube.com/watch?v=ss7BtLrbxp4&list=PLS1QulWo1RIbfTjQvTdj8Y6yyq4R7g-Al&index=6
For Addition
package lesson1;
import java.util.Scanner;
int x, y, answer;
x = 20;
y = 30;
answer = x + y;
For Subtraction
double x, y, answer;
x = 20;
y = 30;
answer = x / y;
Method One
int x = 10;
x = x + 1;
System.out.println(x);
Answer is 11
Method One
public static void main(String[] args) {
int x = 10;
x++; (This is called post increment operation)
System.out.println(x);
Answer is 11
Another Option
int x = 10;
System.out.println(x++);
System.out.println(x); (this is called pro post implementation)
}
So this is ass follows:
int x = 10;
x = x + 5 (one method)
Notes:
Here in the first example, the program is executed because the value
of ‘x’ is 10. But in the second operation only the second program is
executed because the value of ‘x’ is not 10.
== is equal to
!= is not equal to
> is greater than
< is less than
>= is greater than or equal to
<= is less than or equal to