What is difference between length and length() method in java ?

length() : In String class we have length() method which is used to return the number of characters in string.
For example :
String str = “Hello World”;
System.out.println(str.length());
Str.length() will return 11 characters including space.

length : we have length instance variable in arrays which will return the number of

Read More

Explain about main() method in java ?

Main() method is starting point of execution for all java applications. String args[] are array of string objects we need to pass from command line arguments. Every Java application must have at-least one main method.

public static void main(String[] args) {}

Read More

What is encapsulation in Java?

The process of wrapping or putting up of data in to a single unit class and keeps data safe from misuse is called encapsulation.

Through encapsulation we can hide and protect the data stored in java objects. Java supports encapsulation through access control. There are four access control modifiers in java

Read More

What is an object in Object Oriented Programming ?

An Object is instance of class. A class defines type of object. Each object belongs to some class. Every object contains state and behavior. State is determined by value of attributes and behavior is called method. Objects are also called as an instance.

To instantiate the class we declare with the

Read More

What is ASCII Code and Unicode?

ASCII stands for American Standard code for Information Interchange. ASCII character range is 0 to 255. We can’t add more characters to the ASCII Character set. ASCII character set supports only English. That is the reason, if we see C language we can write c language only in English we

Read More

What is constructor in java ?

A constructor is a special method used to initialize objects in java.

We use constructors to initialize all variables in the class when an object is created. As and when an object is created it is initialized automatically with the help of constructor in java.

We have three types of constructors

  1. Default Constructor
  2. No-arg

    Read More

Why main() method is public, static and void in java ?

public : “public” is an access specifier which can be used outside the class. When main method is declared public it means it can be used outside class.

static : To call a method we require object. Sometimes it may be required to call a method without the help of object.

Read More

What is method in java ?

It contains the executable body that can be applied to the specific object of the class. Method includes method name, parameters or arguments and return type and a body of executable code.

Methods can have multiple arguments. Separate with commas when we have multiple arguments.

Syntax :-

type methodName(Argument List) {
// code
Read More

What is a class in Object Oriented Programming ?

Classes are fundamental or basic unit in Object Oriented Programming. A class is kind of blueprint or template for objects. Class defines variables, methods. A class tells what type of objects we are creating.

For example take Department class tells us we can create department type objects. We can create any

Read More