Saraswat World

What are identifiers in java?

What are identifiers in java?

JAVA INTERVIEW QUESTIONS

Identifiers are names in java program. Identifiers can be class name, method name or variable name. Rules for defining identifiers in java: 1) Identifiers must start with letter, Underscore or dollar($) sign.2) Identifiers canโ€™t start with numbers .3) There is no limit on number of characters in identifier but not recommended to have more than […]

Can we define package statement after import statement in java?

Can we define package statement after import statement in java?

JAVA INTERVIEW QUESTIONS

We canโ€™t define package statement after import statement in java. Package statement must be the first statement in source file. We can have comments before the package statement

Can we have more than one package statement in source file ?

Can we have more than one package statement in source file ?

PYTHON INTERVIEW QUESTIONS

We canโ€™t have more than one package statement in source file. In any java program there can be atmost only 1 package statement. We will get compilation error if we have more than one package statement insource file.

What are packages in java?

What are packages in java?

JAVA INTERVIEW QUESTIONS

Package is a mechanism to group related classes ,interfaces and enums in to a single module. Package can be declared using the following statement : Syntax : Coding Convention : package name should be declared in small letters. package statement defines the namespace. The main use of package is: 1) To resolve naming conflicts 2) […]

What all access modifiers are allowed for top class ?

What all access modifiers are allowed for top class ?

JAVA INTERVIEW QUESTIONS

For top level class only two access modifiers are allowed. public and default. If a class is declared aspublic it is visible everywhere.If a class is declared default it is visible only in same package.If we try to give private and protected as access modifier to class we get the below compilation error.Illegal Modifier for […]

Can we have multiple classes in single file ?

Can we have multiple classes in single file ?

JAVA INTERVIEW QUESTIONS

Yes we can have multiple classes in single file but it people rarely do that and not recommended. We canhave multiple classes in File but only one class can be made public. If we try to make two classes in Filepublic we get following compilation error.โ€œThe public type must be defined in its own fileโ€

What does null mean in java?

What does null mean in java?

JAVA INTERVIEW QUESTIONS

When a reference variable doesnโ€™t point to any value it is assigned null.Example : Employee employee;In the above example employee object is not instantiate so it is pointed no where.

Explain about instanceof operator in java?

Explain about instanceof operator in java?

JAVA INTERVIEW QUESTIONS

Instanceof operator is used to test the object is of which type. Syntax : instanceof Instanceof returns true if reference expression is subtype of destination type. Instanceof returns false if reference expression is null. Example : Since a is integer object it returns true.There will be a compile time check whether reference expression is subtype […]

Difference between โ€˜IS-Aโ€™ and โ€˜HAS-Aโ€™ relationship in java?

Difference between โ€˜IS-Aโ€™ and โ€˜HAS-Aโ€™ relationship in java?

JAVA INTERVIEW QUESTIONS

IS-A RELATIONSHIP HAS- A RELATIONSHIP Is a relationship also known as inheritance Has a relationship also known as composition or aggregation. For IS-A relationship we uses extends keyword For Has a relationship we use new keyword Ex : Car is a vehicle. Ex : Car has an engine. We cannot say Car is an engine […]

What is โ€˜HAS Aโ€™โ€™ relationship in java?

What is โ€˜HAS Aโ€™โ€™ relationship in java?

JAVA INTERVIEW QUESTIONS

โ€˜Has a โ€˜ relationship is also known as โ€œcomposition or Aggregationโ€. As in inheritance we have โ€˜extendsโ€™keyword we donโ€™t have any keyword to implement โ€˜Has aโ€™ relationship in java. The main advantage ofโ€˜Has-Aโ€˜ relationship in java code reusability.

What is โ€˜IS-A โ€˜ relationship in java?

What is โ€˜IS-A โ€˜ relationship in java?

JAVA INTERVIEW QUESTIONS

โ€˜is aโ€™ relationship is also known as inheritance. We can implement โ€˜is aโ€™ relationship or inheritance in javausing extends keyword. The advantage or inheritance or is a relationship is reusability of code instead ofduplicating the code.Ex : Motor cycle is a vehicleCar is a vehicle Both car and motorcycle extends vehicle.

Explain Java Coding Standards for Constants?

Explain Java Coding Standards for Constants?

JAVA INTERVIEW QUESTIONS

Constants in java are created using static and final keywords.1) Constants contains only uppercase letters.2) If constant name is combination of two words it should be separated by underscore.143) Constant names are usually nouns.Ex:MAX_VALUE, MIN_VALUE, MAX_PRIORITY, MIN_PRIORITY

Explain Java Coding Standards for variables ?

Explain Java Coding Standards for variables ?

JAVA INTERVIEW QUESTIONS

1) Variable names should start with small letters.2) Variable names should be nouns3) Short meaningful names are recommended.4) If there are multiple words every innerword should start with Uppecase character.Ex : string,value,empName,empSalary

Explain Java Coding standards for Methods?

Explain Java Coding standards for Methods?

JAVA INTERVIEW QUESTIONS

1) Method names should start with small letters.2) Method names are usually verbs3) If method contains multiple words, every inner word should start with uppercase letter.Ex : toString()4) Method name must be combination of verb and nounEx : getCarName(),getCarNumber()

Explain Java Coding standards for interfaces?

Explain Java Coding standards for interfaces?

JAVA INTERVIEW QUESTIONS

1) Interface should start with uppercase letters2) Interfaces names should be adjectivesExample : Runnable, Serializable, Marker, Cloneable

Explain Java Coding Standards for classes or Java coding conventions for classes?

Explain Java Coding Standards for classes or Java coding conventions for classes?

JAVA INTERVIEW QUESTIONS

Sun has created Java Coding standards or Java Coding Conventions . It is recommended highly to followjava coding standards.Classnames should start with uppercase letter. Classnames names should be nouns. If Class name is ofmultiple words then the first letter of inner word must be capital letter.Ex : Employee, EmployeeDetails, ArrayList, TreeSet, HashSet

Difference between Right shift operator โ€˜>>โ€™ and Unsigned shift operator โ€˜>>>โ€™ in java?” width=”150″ height=”150″>
											</a>
				</div>



				<div class=

Difference between Right shift operator โ€˜>>โ€™ and Unsigned shift operator โ€˜>>>โ€™ in java?

JAVA INTERVIEW QUESTIONS

The right shift operator ‘>>’ shifts all of the bits in a value to the right to a specified number of times.int a =15;a= a >> 3;The above line of code moves 15 three characters right. The unsigned shift operator ‘>>>’ used to shift right. The places which were vacated by shift are filledwith zeroes.

What are constants and how to create constants in java?

What are constants and how to create constants in java?

JAVA INTERVIEW QUESTIONS

Constants are fixed values whose values cannot be changed during the execution of program. We createconstants in java using final keyword.Ex : final int number =10;final String str=โ€java-interview โ€“questionsโ€

What is difference between Character Constant and String Constant in java ?

What is difference between Character Constant and String Constant in java ?

JAVA INTERVIEW QUESTIONS

Character constant is enclosed in single quotes. String constants are enclosed in double quotes. Characterconstants are single digit or character. String Constants are collection of characters.Ex :โ€™2โ€™, โ€˜Aโ€™Ex : โ€œHello Worldโ€

What is Unicode ?

What is Unicode ?

JAVA INTERVIEW QUESTIONS

Unicode is a character set developed by Unicode Consortium. To support all languages in the world Javasupports Unicode values. Unicode characters were represented by 16 bits and its character range is 0-65,535.Java uses ASCII code for all input elements except for Strings, identifiers, and comments.