Java 1st Lesson Notes
Java 1st Lesson Notes
Features of Java
The primary objective of Java programming language creati
there are also some excellent features which play an impor
buzzwords.
A list of the most important features of the Java language is
1.Simple
2.Object-Oriented
3.Portable
4.Platform independent
5.Secured
6.Robust
7.Architecture neutral
8.Interpreted
9.High Performance
10. Multithreaded
11. Distributed
12. Dynamic
Simple
Java is very easy to learn, and its syntax is simple, clean
programming language because:
o Java syntax is based on C++ (so easier for programmer
Object-oriented
Java is an object-oriented programming language. Everyt
combination of different types of objects that incorporate bo
Object-oriented programming (OOPs) is a methodology that
Basic concepts of OOPs are:
1.Object
2.Class
3.Inheritance
4.Polymorphism
5.Abstraction
6.Encapsulation
Platform Independent
Java is platform independent because it is different from o
while Java is a write once, run anywhere language. A platfor
There are two types of platforms software-based and hardw
The Java platform differs from most other platforms in the
platforms. It has two components:
1.Runtime Environment
2.API(Application Programming Interface)
Java code can be executed on multiple platforms, for exam
and converted into bytecode. This bytecode is a platform-in
Anywhere (WORA).
Secured
Java is best known for its security. With Java, we can develo
No explicit pointer
Robust
The English mining of Robust is strong. Java is robust becau
o It uses strong memory management.
application anymore.
o There are exception handling and the type checking me
Architecture-neutral
Java is architecture neutral because there are no implement
In C programming, int data type occupies 2 bytes of mem
occupies 4 bytes of memory for both 32 and 64-bit architect
Portable
Java is portable because it facilitates you to carry the Java b
High-performance
Java is faster than other traditional interpreted programmin
than a compiled language (e.g., C++). Java is an interpreted
Distributed
Java is distributed because it facilitates users to create dist
This feature of Java makes us able to access files by calling
Multi-threaded
A thread is like a separate program, executing concurrentl
threads. The main advantage of multi-threading is that it do
important for multi-media, Web applications, etc.
Dynamic
Java is a dynamic language. It supports the dynamic loading
native languages, i.e., C and C++.
Java supports dynamic compilation and automatic memory m
= x=5
+= x += 3
-= x -= 3
*= x *= 3
/= x /= 3
%= x %= 3
&= x &= 3
|= x |= 3
^= x ^= 3
>>= x >>= 3
<<= x <<= 3
== Equal to x == y
!= Not equal x != y
Java Classes/Objects
Java is an object-oriented programming language.
Everything in Java is associated with classes and
objects, along with its attributes and methods. For
example: in real life, a car is an object. The car
has attributes, such as weight and color,
and methods, such as drive and brake.
A Class is like an object constructor, or a
"blueprint" for creating objects.
Create a Class
To create a class, use the keyword class:
Create an Object
In Java, an object is created from a class. We have
already created the class named Main, so now we
can use this to create objects.
To create an object of Main, specify the class
name, followed by the object name, and use the
keyword new:
Example
Create an object called "myObj" and print the value
of x:
public class Main {
int x = 5;
Q.6.CONSTRUCTOR IN JAVA
Java Constructors
Java constructors are special types of methods that are
used to initialize an object when it is created. It has the same
name as its class and is syntactically similar to a method.
However, constructors have no explicit return type.
Typically, you will use a constructor to give initial values to the
instance variables defined by the class or to perform any other
start-up procedures required to create a fully formed object.
All classes have constructors, whether you define one or not
because Java automatically provides a default constructor that
initializes all member variables to zero. However, once you
define your constructor, the default constructor is no longer
used.
name.
Java constructors do not have a return type. Even do not
No-Args Constructor
Parameterized Constructor
1. Default Constructor
If you do not create any constructor in the class, Java provides a
default constructor that initializes the object.
3. Parameterized Constructor
A constructor with one or more arguments is called a
parameterized constructor.
Most often, you will need a constructor that accepts one or more
parameters. Parameters are added to a constructor in the same
way that they are added to a method, just declare them inside the
parentheses after the constructor's name.