Java Course
Java Course
Java Features
=>Simple
Java is easy to learn and its syntax is simple(verbose) You can just read it
through
clean, easy to understand.
The confusing and ambiguous concepts of C++ are either left out in java or they
have been
re-implemented in cleaner way.
=>High Performance
Although java is an interpreted language it is designed to support "just-in-time"
compilers, which dynamically compile bytecodes to machine code
If nothing works as expected in java we can raise a ticket and the oracle team will
go through it
if many tickets have been raised on same thing and will notify us in particular
release on
particular enhancement has been coming up if something can be done on that issue.
So if something doesn't work it will surely rectify in future releases.Its a High
performance language and always evolving
=>Secure
java can be used to develop virus-free systems
It is secured because it runs in machine sandbox to prevent any activity from
untrusted sources
No use of explicit pointers unlike C
As pointers locate the memory location no data manipulation malicious so they can't
change
the content in memory location
=>Robust
java checks the code during compilation time and run time
Compilation means if we have some syntactical errors then like missing : at the end
of the statement
then it will prompt us regarding the issue in compilation time and asks us to
correct it
Once everything is as expected then it will compile and create the class file
Java completely takes care of the memory allocation and releasing which makes java
more
robust unlike in other programming languages
Java by itself does garbage collection=> when a memory is not used by our program
it will clean
up by itself you don't need to write particularly a clean up code
=>portable
Applications written on one platform of java can be easily ported to another
platform as it
is platform independent
=>Dynamic
Many objects are evaluated at runtime and the execution is carried out not only
during compile time
Eg:Runtime Polymorphism
=>Distributed
RMI(Remote method invocation).EJB(Enterprise java beans) etc. are used for creating
=>Multi-threaded
Thread is a task in a process/program
Multi-threading is multiple tasks running or executing at the same instance of time
=>Object oriented
Java is an ooLanguage. Everything is performed using "objects". Java can be easily
since it is based on the object model
Java code (.java) => Javac compiler =>Byte Code(.class) => JVM =>windows,ubuntu,mac
OS
The JRE does not contain tools and utilities such as compilers or debuggers for
developing applets and application
rt.jar would have something like string class and other classes
To just run a class file we need JRE but as developer we need JDK
Compile-time Environment
public static void main =>entry point for our application/class file
Static => To declare any method as static , the main adv of static method is there
is no need to create object to
invoke the static method. We need not create instance
void =>is the return type of the method, it means it doesn't return any value
String[] args => used for command line argument we can give as many strings as we
want
jshell = >its not for production use just to test what can be the output for
particular command would be
MODIFIERS => is a word or phrase or clause that describes and changes or modifies
the meaning of another word or phrase in some way like (public, private )
Eg: policeman , traffic policeman
traffic is the modifier
Modifiers
/ \
Access Non-access
Access control modifiers =>(this is what drives the encapsulation factor of object
oriented paradigm)
We control the access of all these components that means encapsulated
Java provides a number of access control modifiers to set access level for classes,
variables,methods,constructors
The 4 access levels are-
1)Default =>Visible to package(com.edureka)= without any access modifier
package com.edureka
classs helloworld(){
}
Non-Access Modifiers
Java privides a no. of non-access modifiers to provide additional functionalities
to a class, variable,method,
constructor
1)Static: the static modifier for calling methods and variables without aan
object to which it belongs
Variables
These are memory locations which are reserved to store values means while declaring
a variable
we reserve memory
There are 3 types of variables
Variables
/ | \
local instance class/static
1) Local :local to our method it has only local scope not accessible out of the
method it was created in
This is where garbage collection for java is useful once we loose control out of
the method then garbage
will kick in and clean up the variable/memory location
=>Local vars are declared in methods,contstructors,or blocks and are visible only
in these 3
=>These are created when execution enters a these 3
These are implemented at stack level internally
There is no default value for local variables, so local variables should be
declared and an initial
value should be assigned before the first use
3)Class variables are declared with the static keyword inside a class, but it is
created outside a
method, constructor or a block
Class variables are declared as constants i.e. variables never change from their
initial value
Static variables are stored in the static memory
It is rare to use static variables other than declared final and used as either
public or
private constants
Created when the program starts and destroyed when the program stops
Static vars are declared public since they must be available for users of the class
Static vars can be accessed by calling with the class name - ClassName.VariableName
Instance is one per object and staic is one per class