JAVA

1. Java-overview 2. Features of Java 3. History of Java 4. HW SW Req for Java SE 7 5. Java Environment Setup 6. Basic Requirement 7. Comments 8. My First Program in Java 9. Line Break 10. Escape Sequences 11. Literals in Java 12. Identifiers in Java 13. Variables in Java 14. Data-Types in Java 15. Declare Variables 16. Reserved Key Words 17. printf() 18. Chained & Embedded state 19. Prog.to print sum of 2 nos 20. Scanner class 21. Prg.to print sum & average 22. Area & Perimeter of Rectangle 23. Area Circumference of Circle 24. Prg.for Simple Calculator 25. Operatos in Java 26. Ex. Of Operators 27. Swap two numbers 28. Hierarchy of Operators 29. if( ) statement 30. Prg.to check +ve,-ve or zero 31. if..else statement 32. Prg.to check Odd or Even 33. Prg.to print larger of 2 nos 34. Prg.to print largest of 3 nos 35. Prg.to check divisibility 36. Prg.to check print range 37. for. . . loop statement 38. prg.to print series of nos 39. Prg.to check divisibility 40. prg.to print sum of nos 41. Prg.to print Pyramid 42. prg.for Factorial 43. prg.to fill screen 44. prg.for largest/smallest no 45. prg.to print reverse no 46. prg.to add each digit 47. prg.for sum of series 48. prg.for fibonacci series 49. prg.to check Prime nos 50. prg. Prime no from 1 to 100 51. prg.Specified Prime nos 52. while( ) statement 53. do. . While statement 54. break & continue statement 55. switch case statement 56. Array in Java 57. print reverse order using array 58. Ascending/Descending order 59. prg.to search no in Array 60. Multidimensional Array 61. String in Java 62. String with spaces 63. prg.to print string in reverse 64. prg. to count A,E,I,O,U vowel 65. User defined methods 66. Methods program example 67. General Purpose Programs 68. Loan & EMI calculation prg. 69. Table print prg. 70. Leap year program 71. lower to UPPER case prg. 72. Age Distribution prg. 73. Bank note calculation prg. 74. Simple Interest prg. 75. Compound Interest prg. 76. Simple Depreciation prg. 77. Reducing bal.Depreciation prg. 78. Marksheet prg. 79. Income Tax prg. 80. Time calculator prg. 81. Distance converter prg. 82. Volume Air Calculation prg. 83. Time to fill Water Tank prg. 84. Salary Calculation prg. 85. Total Sale Calculation prg. 86. Male/Female percentage prg. 87. Library Rent prg. 88. Office Expance prg. 89. Total Salary Calculation prg. 90. Profit or Loss prg. 91. Total Profit/Loss prg. 92. Palindrome program 93. Java Interview Part1 94. Java Interview Part2 95. Java Interview Part3 96. Java Interview Part4 97. Java Interview Part5 98. Java Interview Part6 99. Java Interview Part7 100. Java Interview Part8 101. Java Interview Part9 102. Java Interview Part10 103. Java Interview Part11
Pr.Pg Next Pg

JAVA Interview Questions and Answers Part 1

 

1. Explain JAVA?

  • Java programming language and environment was designed to solve number of problems in modern programming practice.

  • Java was developed at Sun Microsystems, by James Gosling and released in 1995 as core component of Sun Microsystems.

  • Java changed the face of programming environment and gave a new definition to OOPS (Object Oriented Programming)

  • The Primary goal for creation of the Java is:

    1. It is Simple

    2. It is object-oriented

    3. It is independent of host platform

    4. It contains language facilities and library for networking

    5. It is designed to execute code from remote securely.

2. Features of JAVA?

  • The following features of JAVA are such as:

  • Simple: Java is Easy to write and more readable and eye catching.

  • Object Oriented: Java is a pure Object oriented. everything in java is object. All programs and data reside inside objects and classes

  • Platform-Independent: This technique unlike many other programming languages including C and C++ when Java is compiled, it is not compiled into platform specific machine. Java create platform independent byte code

  • Secure: While Java's secure feature it enables to develop virus-free, tamper-free systems.

  • Portable: Java programs can be run on any platform (Linux, Window, Mac)

  • Robust: The Code of java is Robust and Means of first checks the reliability of the code before Execution When We trying to Convert the Higher data type into the Lower Then it Checks the Demotion of the Code the It Will Warns a User to Not to do this So it is called as Robust

  • Multi-threaded: With Java's multi-threaded feature, it is possible to write programs that can do many tasks simultaneously.

  • High Performance: The use of bytecode makes the performance high. the speed is also high with comparing c, c++.

  • Dynamic: Java is a dynamic language. So it is capable of linking dynamic new classes, methods and objects

 

3. Types of variables in Java? Exaplain.

  • Local variables

  • Instance variables

  • Class/static variables

  1. Local variables:

    • Similar to how an object stores its state in fields, a method will often store its temporary state in local variables. The syntax for declaring a local variable is similar to declaring a field (for example, int count = 0;).

    • There is no special keyword designating a variable as local; that determination comes entirely from the location in which the variable is declared ó which is between the opening and closing braces of a method. As such, local variables are only visible to the methods in which they are declared; they are not accessible from the rest of the class.

  2. Instance variables:

    • Objects store their individual states in "non-static fields", that is, fields declared without the static keyword.Non-static fields are also known as instance variables because their values are unique to each instance of a class

  3. Class/static variables:

    • These variables are declared at the top level. They begin their life when first class loaded into memory and ends when class is unloaded. As they remain in memory till classes exist, so these variables often called Class variables. There only one copy of these variables exist

    • These variables are having highest scope that is they can be accessed from any method/ block in a class. When no explicit assignment made while declaration they are initialized to default values , depending on their type.

4. How to declare variables in JAVA?

  • declare single variable:

Syntax:

datatype <variable name>;

 

Example:

int x; // This will declares x as int data type.

char sex; //This will declares sex as char data type.

float perc; // This will declare perc as float data type.

 

  • Way to declare more than one variable having same datatype:

Syntax:

datatype <variable1>, <variable2>Ö<variable n>;

 

Example:

int x, y, z; // This will declare x,y,z variable as int data type.

float perc1, perc2;// This will declare perc1 and perc2 variables as float data type.

char dept1, dept2; // This will declare dept1 and dept2 variables as char data type.

 

5. What is Scanner class in JAVA?

  • A simple text scanner which can parse primitive types and strings using regular expressions

  • A Scanner breaks its input into tokens using a delimiter pattern, which by default matches whitespace.

  • The resulting tokens may then be converted into values of different types using the various next methods.

  • If you want to read a number then the Java code will look like below:

Scanner sc = new Scanner(System.in);

int i = sc.nextInt();

 

6. Explain String in JAVA?

  • In Java you can use strings as array of characters, however, more common practice is to use the String keyword to declare a string variable.

  • You can create string object using one of the following methods:

    1. By assigning a string literal to a String variable

    2. By using a String class constructor

    3. By using the string concatenation operator (+)

    4. By retrieving a property or calling a method that returns a string

    5. By calling a formatting method to convert a value or object to its string representation

  • A string can be declared and initialized in following way:

String s = "Sam";

 

7. What is the Java API?

  • The Java API is a large collection of ready-made software components that provide many useful capabilities, such as graphical user interface (GUI) widgets.

 

8. What is the Java Virtual Machine (JVM)?

  • The Java Virtual Machine is software that can be ported onto various hardware-based platforms.


9. What is the difference between a String and a StringBuffer class?

  • String is immutable : you canít modify a string object but can replace it by creating a new instance. Creating a new instance is rather expensive.

  • StringBuffer is mutable : use StringBuffer or StringBuilder when you want to modify the contents. StringBuilder was added in Java 5 and it is identical in all respects to StringBuffer except that it is not synchronized,which makes it slightly faster at the cost of not being thread-safe.

 

10. What is an abstract class?

  • Abstract class must be extended/subclassed (to be useful). It serves as a template. A class that is abstract may not be instantiated (ie. you may not call its constructor), abstract class may contain static data.

  • Any class with an abstract method is automatically abstract itself, and must be declared as such. A class may be declared abstract even if it has no abstract methods. This prevents it from being instantiated.

Pr.Pg Next Pg