What is Java
Java is a programming language and a platform.
Java is a high level, robust, secured and object-oriented programming language.
Platform: Any hardware or software environment in which a program runs, is known as a platform. Since Java has its own run time environment (JRE) and API, it is called platform.
Features of Java
The Java Features given below are simple and easy to understand.
- Simple
- Object-Oriented
- Portable
- Platform independent
- Secured
Object-oriented
Java is Object-oriented programming language. Everything in Java is an object. Object-oriented means we organize our software as a combination of different types of objects that incorporates both data and behavior. |
|
Basic concepts of Oops are: |
- Object
- Class
- Inheritance
- Polymorphism
- Abstraction
- Encapsulation
Variable
Variable is name of reserved area allocated in memory. In other words, it is a name of memory location. It is a combination of "vary + able" that means its value can be changed.
Ex. int data=50;
Types of Variable
There are three types of variables in java:
- local variable
- instance variable
- static variable
1) Local Variable
A variable declared inside the method is called local variable.
2) Instance Variable
A variable declared inside the class but outside the method, is called instance variable . It is not declared as static.
3) Static variable
A variable which is declared as static is called static variable. It cannot be local.
- class A{
- int data=50;
- static int m=100;
- void method(){
- int n=90;
- } }
Data Types in Java
Data types represent the different values to be stored in the variable. In java, there are two types of data types:
- Primitive data types
- Non-primitive data types
|
Object in Java
An entity that has state and behavior is known as an object .
Class in Java
A class is a group of objects which have common properties. It is a template or blueprint from which objects are created. It is a logical entity. It can't be physical.
A class in Java can contain:
- fields
- methods
- constructors
- blocks
- nested class and interface
- class <class_name>{
- field;
- method;
- }
Method in Java
In java, a method is like function i.e. used to expose behavior of an object.
Advantage of Method
- Code Reusability
- Code Optimization
Java Keywords
The following list shows the reserved words in Java. These reserved words may not be used as constant or variable or any other identifier names.
abstract | assert | boolean | break |
byte | case | catch | char |
class | const | continue | default |
do | double | else | enum |
extends | final | finally | float |
for | goto | if | implements |
import | instanceof | int | interface |
long | native | new | package |
private | protected | public | return |
short | static | strictfp | super |
switch | synchronized | this | throw |
throws | transient | try | void |
volatile | while |
Java naming conventions for identifiers
1. Use CamelCase for most identifiers (classes, interfaces, variables, and methods).
2. Use an initial capital letter for classes and interfaces, and a lower case letter for variables and methods.
3. For named constants, use all capital letters separated by underscores.
4. Avoid using $ characters in identifiers.
Java Package
A java package is a group of similar types of classes, interfaces and sub-packages.
Package in java can be categorized in two form, built-in package and user-defined package.
|
Comments
Post a Comment