Learn Java Tutorials Questionwise,Java Tutorials- Questions And Answers -1

No comments
Here is an attempt to provide the concepts of java programming language in question answers form. This is the first article on this topic where the basic java concepts are provide in simple question answers form which will help you in understanding and remembering the concepts more quickly. This question answer approach is also very helpful for interviews where we face various concepts in questions form.

Q.1 What is a java program?

Answer- A java program is a collection of objects which talk to each other using their methods

Q.2 What is a class in java?

Answer- In java a class is a template which has methods and instance variables which defines a class.

Q.3 What is object in java?

Answer- In java an object is an instance of the class in the java, each object of a class type has its own set instance variables.

Q.4 What is the meaning of state and behaviour of an object in java?

Answer- In java each object has its own set of instance variables defined its class, instance variables in the objects with values defines the state of an object. Behaviour are the methods defined in class, all the logic and algorithms are written inside a method of a class, all the objects talk to each other with the help of their methods.

Q.5 What are identifiers in java?

Answer- like any other computer language in java we need to name the different classes, objects ,methods and variables ,these names are called the identifiers.

Q.6 What is Inheritance in java ? explain with a example in brief?

Answer- Inheritance is one of the OOP language property ,with the help of inheritance we can reuse the code written inside a class in another class.The class which extends another class is called subclass and the class which is being extended by some other class is called superclass. A superclass does not know anything about the subclass which has extended it , but a subclass has access to all the instance variables and methods defined inside a superclass except private ones.

Q.7 What is an Interface In java? Explain with a brief example?

Answer- In java an interface is 100% abstract class which has abstract methods.(abstract methods are the methods without body) To use an interface a class need to implement it by implementing all its methods. A class implement an interface using implements keyword.

Q.8 What are the rules for naming of legal identifiers in java?

Answer- There are some rules for naming of identifiers, they are-

  • An identifier should start with a letter, a currency symbol like $ or a conneting character like _(underscore).

  • An identifier should not start with a number

  • An identifier can have any combination of numbers,letters,currency characters or connecting characters after the first character.

  • An identifier can have any number of characters.

  • A java reserved keyword can never be used as an identifier.

Q.9 What are the naming standards for the naming of identifiers in java recommended by Sun?

Answer- Naming standards recommended by sum for various identifiers-

Identifiers for classes-

A class name should start with a capital letter, and after it should follow camelCase. Like- Car ,Animal, SubmitButton are all legal class identifiers. It is good to have class name which is a noun.

Identifiers for methods-

A method name in java should start with a small case letter, and then simple camelCase. It is recommended to have a method name in java which is a combination of verb and noun, Like- getName()

Identifiers for variables-

A variable name should also follow camelCase, and should be short and meaningful.

Identifiers for constants-

In java constants are named with capital letters with _ as separators. A constant in java is a static and final keyword.

Q.10 What is a bean in java?

Answer- In java a bean is a class with properties which are private and these properties of the bean can only be accesses by the getter and setter methods of the class outside a class.

Q.11 What are getters and setters in java class?

Answer- getters and setters in java are the methods defined inside a class(bean) used for setting and getting the values of its properties which are private.



If you have any questions related to the concepts explained in above questions then feel free to comment below , and we will try to solve your queries.
Thanks for reading,
Next series of questions will be uploaded soon.

No comments :

Post a Comment