ore java by mr kisan
C
---------------Day 1 7th July
2022-------------------------------------------------------
In java there are 3 basic java programming elements are there. -
class, Interface and Enum
ithout using a class or a Interface or a Enum we cannot write a java
w
program
we have 4 access modifiers - public, private, protected, and default
se of access modifiers - it provides the access restrictions which will
u
enhances the data security
syntax - set of rules to follow when writing the java.
yntax to write class -
s
<Access Modifier> class <class Name>{
----logic----
----logic----
}
lass is a key word - there are 50 key words - every key word starts
c
with small letters
java is case sensitive.
example of class
public class demo {
- -------logic--------
--------logic------
}
syntax of interface
Access Modifier> interface <interface name> {
<
--------logic--------
--------logic------
}
g:
e
public interface firstInterface{
--------logic--------
--------logic------}
yntax of Enum
s
<Access modifiers> enum <enum name>{
- -------logic--------
--------logic------}
g:
e
public Enum firstEnum{
- -------logic--------
--------logic------}
-----------------Day 2 8th July 2022--------------
der to learn OOPS - Encapsulation, inheritance, polymorphism and
O
abstraction
e will use interface element when applying the concepts of
W
abstraction
hen projects have universal constants (Fixed values) we will use
W
Enum
hen we create a project using IDE, in we will have two folders a)
W
JRE (Java runtime environment) b) src
) in src folder we will have multiple pacakges and each package
b
consist of similar class, interface and Enum.
Each package is module
ostly we will use class about 90%
m
then interface about 8 to 10%
and Enum less than 2%
----------------------------Day 3 11th July 2022---------------------------
we can use only two access modifiers for a calss [public and default]
inside a class we can write variables, methods, create objects and
blocks
extension of class, interface and Enum will be .java
yntax of java method
s
<access modifiers > <return type> <Method Name> ()
{
--------
--------
(Method Body) //functionality // implementation
}
for a java method we can use any access modifiers
- --------------------Day 4 12th July 2022----------------------------------
java method is a place where we will write the business logic i.e any
kind of operation
hat is return type -> we will have 4 types the we can return [1) void
w
2) all the 8 primitive data types 3) Classes 4) Objects]
primitive data types [int, byte, short, long, float, double, char,
8
boolean]
void means that the method will not return anything
If we dont write any access modifiers for a method then it is a default
method
) How many methods we can write inside the class.
Q
-> any number of methods we can write inside the class
) When will a java method will be executed
Q
--> A java method will be executed only if we are calling the method
) how to call a java method
Q
--> we need to call the java method with the help of it's respective
class object.
) How to create a class object
Q
-->we need to create a class object with the help of "new" keyword
and initialize that object with the help of a constructor(Constructor
name will be same as class name)
lassA aobj=new ClassA();
C
ClassB bobj=new ClassB();
ClassC cobj=new ClassC();
In java there is a method which will executed automatically and it is
known as main method
) Every java program starts with the main() method and end with the
1
main() method
2) If we want to write a java program then writing the main() is
mandatory
3) main() will be executed automatically no need to call it
yntax of main method
S
public static void main(String []args)
{
}
---------------Day 5 Tue 13th July 2022-------------------------------
o run the java program we need to perform 2 steps
T
1) compilation the program
2) running the program
hat do you mean my compilation --> checking the code whether the
w
program follows the syntax of the java language
who will compile ---> java compiler will compile the program
ow do we know that our java program has been compiled
h
successfully---> java copiler will generate a .class file then we will
know that compilation is done successfully
e cannot understand the .class file because it consist of byte code
w
instructions and it can only be understood by the machines in our
scenario that machine is java virtual machine (JVM). The .class file
which is generated we should provide that as input to jvm that is
known as running
if we ant to see the output of our java program we need to perform two
steps
1) compilation
it is done by java compiler
the command is javac [Link]
compilations means checking the code whether we have written
according to the java language syntax or not
fter successful compilation java compiler is going to generate .class
a
file
we cannot understand that .class file because it consist of byte code
instructions whehc is understandable only by the machine [In our
scenario that machine is JVM]
) Running
2
it is done by jvm (java virtual machine)
the command is java [Link]
whenever we are providing the generated .class file as an input to the
JVM, it is going to check weather thee byte code instructions are
correct or not
--> if those are correct we will be getting our output, if wrong we will
get an error
----------------Day 6 14th july---------------
- ----------------Day 7 15th July---------------
In java there are two types of java classes
1) predefined classes
2) User defined Classes
Every predefined java class starts with the capital letter
very java User defined class starts with BOTH small and capital
E
letters. But it is highly recommended that to start the java class with
the capital letter
In java there are two types of methods
1) predefined methods
2) user defined methods
very java pre defined method always starts with small letters
E
Java user defined methods can start with both small and capital letters
ow both the methods (predefined and user defined) both are of two
N
types
a) parameterized methods
b) Non parameterized methods
e should never initialize a variable at the time of declaration If I am
w
writing the variable as a parameter
on parametrized method
N
void method1()
{
//logic
}
arametrized method
p
void method2(int a)
{
// logic
// valid
// parametrized method since the variable a is initialized but it is
not decalred since it is being // // used as a parameter
}
parametrized method
void method3(int a=5)
{
// logic
// Invalid
// parametrized method since the variable a is initialized as well
as decalred and being
// used as a parameter
}
- ------------------Day 8 16th july--------------------------
Q) How to pass values for the parameters which are present in a
method ?
--> we need to pass the values for the parameters whenever we are
calling a method.
- ------------------Day 9 18th July --------------------------------
Except void , any other return type, we have to mention the return type
as well
------------------Day 10 19th july-------------
Only installation of java and eclipse was done on this date
- ----------------Day 11 20th july---------------
Interview question based on java 8 will be asked in any java interview
os of the companies uss java 11 and some companies uses 8 and
M
they are also migating to java 11
Companies prefer to work on the most stable of version of java and
that is why companies work on java 11. they will migrate to java 16
maybe in near future
Difference between the java c, c++, Java
eveloped By Dennis Ritchie, Bjarne Stroustrup, James Gosling
D
model POP (Procedure oriented programming language), OOP
(Object oriented programming language), OOP (Object oriented
programming language) access modifiers are not available in
procedure oriented programming languages. It is available only in
Object oriented programming language. OOPS mainy concentrate on
data security while procedure oriented programming language focus
on step by step execution of the lines. for eg we can method 2 from
method 1 in object oriented programming language but we cannot do
such thing in procedure oriented programming [Link] 1 will
executr then method 2. POPL don't change their rules even if there is
some security problems
Platform Dependency Platform Dependent, Platform Dependent,
Platform Independent (WORA) (Write Once Run Anywhere)
Keywords 32, 63, 50 [true, false and null are not keywords. They are
values]
hen two classes are present in different packages we have to use
W
import statement.