Very Beginner\'s Java questions. Please write the answers short so even beginner
ID: 3733584 • Letter: V
Question
Very Beginner's Java questions. Please write the answers short so even beginners can understand. Thank you!
1. What is enumerated type, what do they provide, when should you use them?
2. What is UML, how is it used?
3. What is Composition?
4. Compare between Contrast, Array, and ArrayList.
5. What is variable scope?
6. How does java pass information to methods? (pass by value versus pass by reference)
7. What are exceptions?
8. How is a handler for an exception found?
9. Compare checked versus unchecked exceptions.
10. What is an interface. Why do we use them?
11. What are classes?
12. Lower camelCase what is it and why do we use it?
Explanation / Answer
1. What is enumerated type, what do they provide, when should you use them?
-> enumerated type is used to provide named constants, for eg. list of days like monday, tuesday....
insted of giving numbers like 1 for monday, 2 for tuesday.
enumeration provides easier compilation and more readability.
2. What is UML, how is it used?
-> UML stands for Unified Modeling Language
It is a standardized modeling language which allow developer to visualize the system before developing it, so he can clearly understand relation between each component of sytem.
UML is set of components(diagrams) used to design system and identify relation/flow/component between system.
3. What is Composition?
Composition is a relationship between objects .
Composition shows strong relationship between objects, that means if one object destroyed then other is automatically going to be destroyed. for eg house is made up of rooms if house is destroyed the automatically rooms are going to be destroyed. it means rooms can not exists their own, they are part of house.
exactly that is composition.
4. Compare between Contrast, Array, and ArrayList.
-> Actually arrayList is internally supported/implemented by using array itself.
the main difference is array can not grow dynamically arraylist can grow dynamically.
other operations are same like insertion , deletion make same cost by using any of both
eg if we declare array of 10 element we cant put 11th element in array, but arraylist is used to increas dynamically
as long as we add element in arraylist it grows automatically.
5. What is variable scope?
Generally braces({}) defines the scope of variable in java
eg. if you have declared variable wthin method's/function's paranthesis, it will exists for that method only
if you declare variable within class's paranthesis it will exists for that class's object only.(if it is static then for that class only)
if you declare within loop the it will exists for that loop only
6. How does java pass information to methods? (pass by value versus pass by reference)
-> java always do pass by value there is nothing like pass by referance in java
7. What are exceptions?
-> exceptions are the errors that abort normal execution of program
8. How is a handler for an exception found?
-> java provide try{}catch(){}finally() mechanism to handle the exceptions
where try contains the code that may cause exception
catch blocks are the handlers that handles the raised exceptions
and finally block contains the code which should execute in all situation whether exception occured or not.
9. Compare checked versus unchecked exceptions.
-> 1.checked exceptions are the exception that are checked at compile time.
like fileNotFoundException because when you are dealing with file there may possibility that file not exist to read so we should handle such exception those are checked exceptions
2.unchecked exceptions are the exceptions that are checked at compile time
like arithmeticException because when you are doing mathematical operation you dont know what will be result at compile time it may be possible, your operation contains devide by 0 , and that will goto infinite loop.
so such unknown exceptions are occurs or checked at runtime. So that are runtime exceptions
10. What is an interface. Why do we use them?
-> In simple word Interface is contract to sign and implementing class should fulfill that contract
Interface contains method that need to be implemented by implementing class
all methods are public and abstract and all variable are public static final in interface
11. What are classes?
-> Class is simply structure or blueprint which defines the properties and behaviours
we use class to create object, and that object have properties and behaviours defined by class
class is like dice to create object.
12. Lower camelCase what is it and why do we use it?
-> java uses lower camel case to name the variables and methods
it is used so that we can complete the phrases without breaking the word
if we have two words the second words first letter is capital, it increase the readability of the programme.
eg. suppose we have method that calculate area of circle, so while naming it should be readable
public double getAreaOfCircle();
here reader can easily identify the purpose of method.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.