Important Viva Voice Questions for Advance Java Programming Lab from unit 1(a) basics of java
Important Viva Voice Questions for Advance Java Programming Lab from unit 1(a) basics of java
main() in Java is the entry point for any Java program. It is always written as public static void
main(String[] args).
public: Public is an access modifier, specify who can access this method. Public means
that this Method will be accessible by any Class.
static: It is a keyword in java which identifies it is class-based. main() is made static in
Java so that it can be accessed without creating the instance of a Class. In case, main is
not made static then the compiler will throw an error as main() is called by the JVM
before any objects are made and only static methods can be directly invoked via the
class. With the help of class name main() method is called.
void: It is the return type of the method. Void defines the method which will not return
any value.
main: It is the name of the method which is searched by JVM as a starting point for an
application.It is the method where the main execution occurs.
String args[]: It is the parameter passed to the main method to accept user input in String
type Array.
Java is called platform independent because of its byte codes which can run on any operating
system.
No.
Q6) If I don't provide any arguments on the command line, then what will the value stored
in the String array passed into the main() method, empty or NULL?
Q7) What if I write static public void instead of public static void?
The program compiles and runs correctly because the order of specifiers doesn't matter in Java.
The local variables are not initialized to any default value, neither primitives nor object
references.
yes, The constructor implicitly returns the current instance of the class (You can't use an explicit
return type with the constructor.
o Simple: Java is easy to learn. The syntax of Java is based on C++ which makes easier to
write the program in it.
o Object-Oriented: Java follows the object-oriented paradigm which allows us to maintain
our code as the combination of different type of objects that incorporates both data and
behavior.
o Secured: Java is secured because it doesn't use explicit pointers. Java also provides the
concept of ByteCode and Exception handling which makes it more secured.
o Interpreted: Java uses the Just-in-time (JIT) interpreter along with the compiler for the
program execution.
o Multithreaded: We can write Java programs that deal with many tasks at once by
defining multiple threads. The main advantage of multi-threading is that it doesn't occupy
memory for each thread. It shares a common memory area. Threads are important for
multi-media, Web applications, etc.
Java Virtual Machine is a virtual machine that enables the computer to run the Java program.
JVM acts like a run-time engine which calls the main method present in the Java code. JVM is
the specification which must be implemented in the computer system. The Java code is compiled
by JVM to be a Bytecode which is machine independent and close to the native code.
Q20)What is an Object?
An instance of a class is called an object. The object has state and behavior.
Whenever the JVM reads the “new()” keyword then it will create an instance of that class.
Yes, the constructors can be overloaded by changing the number of arguments accepted by the
constructor or by changing the data type of the parameters.
Q23) What are the restrictions that are applied to the Java static methods?
o The static method can not use non-static data member or call the non-static method
directly.
o this and super cannot be used in static context as they are non-static.
Because the object is not required to call the static method. If we make the main method non-
static, JVM will have to create its object first and then call main() method which will lead to the
extra memory allocation.