Basics about Core Java

 Core Java

-   Three basic elements in Java:
1) Class: 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
2) Interface: An interface in Java is a blueprint of a class. It has static constants and abstract methods.

The interface in Java is a mechanism to achieve abstraction. There can be only abstract methods in the Java interface, not method body. It is used to achieve abstraction and multiple inheritance.

In other words, you can say that interfaces can have abstract methods and variables. It cannot have a method body.


3). Enum: An enum type is a special data type that enables for a variable to be a set of predefined constants. The variable must be equal to one of the values that have been predefined for it.

Explanation of 'public static void main(String[] args)' :




-Public: Because it should be available to all other classes which are present in project.

-Static:  Because we  can call static method directly with the help of class name if the main method is not declared as static we cant call main() without creating an object.

-Void: Because every java program should start from main(). so main() should not return anything.

-Main: It is just a name.

-Strint[]args: Main() is a prarmeterised method which is having only one partameter i.e. string array which will accept any kind of  data. This is called  Java command line arguments.


Variables:
Variable provide identity to memory location. Using variables we can process the information easily.

 Identifiers: 
-Java identifiers can start with a-z, A-Z, $,_ .
-We can use numbers also in identifier names. Any number between 0-9.
-An identifier will never start with a number.
-We can use only 2 symbols $ and _.
-There should not be any space between identifier.
-There is no restriction for any identifier length.
-We can take java class names as identifier name but it is not highly recommended.
-We can not take java language keywords as identifiers name.


 Seperators:
1. ; (semicolons): It is used to terminate the statement.
2. , (comma): It is used for seperation of variables & parameters.
3. . (fullstop): It is used in calling a method & for defining package name.
4. () (round brackets): It is used for passing method parameter & for passing conditions in     control statements.
5. {}(Curly Brackets): It is used to represent a block of code.
6. [](Square Brackets): IT is used to represent an array.

How to call Static Method:
    We can call static method directly with the help of class name. 

How to call Default Method:
    We can call default method to creating new object of class and then call.



Comments

Popular posts from this blog

OOP's Concepts

Data types and Variables