Professional Documents
Culture Documents
1. In java, you know about two types of data types, Primitive and Non-Primitive data types.
Could you explain what are the differences between those data types and give some
examples?
Answer : Primitive data types are the most basic data types in the Java language,
primitive data types have been defined by Java and are named with keywords, for
example the keywords int, long, char, etc. While non-primitive data types are data types
that are defined by the programmer themselves and usually contain more than one
value. non-primitive can also be called the Reference data type.
The main differences between primitive and non-primitive data types are: Primitive
types are predefined (defined) in Java. Non-primitive types are created by programmers
and not defined by Java (except for String ).
Primitive data types only have values, no properties or methods. Examples of primitive
data types: number, boolean, null, string, integer, long, double.
Non primitive means that it is not defined by default, it must be filled by itself such as
arrays and classes where there are strings, ints, etc.
Example :
2.
• Explain how the for statement works with an example!
Answer : FOR is a loop statement that is specific to iterations that knows exactly how
many times the iteration will occur.
Writing Form:
• Explain the function of break and continue statements in the looping function!
Give an example how to implement those statements!
Answer :
The break command if used in a loop serves to 'force stop' the ongoing looping
process. We have also seen the use of the break command in the SWITCH
structure.Break is usually used after the IF condition, to select 'when' the loop
should stop.
Example
the continue command will stop the loop that is currently happening (1 iteration
only), and then continue the iteration of the next iteration, or it can also be called
to 'skip' 1 loop. Just like the break command, continue is usually used after the IF
condition which is used to select 'when' ' loop must be skipped
Example
3. Explain the difference between the concepts of call by value and call by reference in the
implementation of function calls (methods) along with examples of their implementations!
Answer :
Call by Value means calling a method with a parameter as value. Through this, the
argument value is passed to the parameter.While Call by Reference means calling a
method with a parameter as a reference. Through this, the argument reference is passed to
the parameter.In call by value, the modification done to the parameter passed does not
reflect in the caller's scope while in the call by reference, the modification done to the
parameter passed are persistent and changes are reflected in the caller's scope. Following
is the example of the call by value The following program shows an example of passing a
parameter by value. The values of the arguments remain the same even after the method
invocation.
Example Call by value
Output
Before swapping, a = 30 and b = 45
Before swapping(Inside), a = 30 b = 45
After swapping(Inside), a = 45 b = 30
**Now, Before and After swapping values will be same here**:
After swapping, a = 30 and b is 45
Output
Before swapping, a = 30 and b = 45
Before swapping(Inside), a = 30 b = 45
After swapping(Inside), a = 45 b = 30
**Now, Before and After swapping values will be different here**:
After swapping, a = 45 and b is
4. Explain the concept of array in detail, why we need to use that, and how we use it in the
Java application!
Answer :
Array is a netode used in programming to perform division of functions. The function of
the array is to divide the program into smaller parts. Also known as subroutines or
subprograms. where the function has a return value when the subprogram is called.
Why we need to use that?
• Simplify and speed up program development. This is because the subprogram will
divide up a long program code so that it will have relatively little code.
• Can be used to reduce repetition of certain codes in a program.
• Can Make the program more modular so that it will be easy to understand and
develop.