Java Programming Fundamentals and Servlets
Covers core Java programming concepts including polymorphism, object-oriented principles, keywords, and web servlet configuration.
Questions
Within a web.xml which maps the servlet com.tcs.login.LoginServlet to the url /utils/LoginServlet
- <servlet> <servlet-name>login</servlet-name> <servlet-class>com.tcs.login.LoginServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>login </servlet-name> <url-pattern>/utils/L
- <servlet-mapping> <servlet-class>com.tcs.login.LoginServlet </servlet-name> <url-pattern>/utils/LoginServlet</url-pattern> </servlet-mapping>
- <servlet> <servlet-class>com.tcs.login.LoginServlet </servlet-name> <url-pattern>/utils/LoginServlet</url-pattern> </servlet>
- <servlet> <servlet-name>login</servlet-name> <servlet-class>com.tcs.login.LoginServlet</servlet-class> <servlet-mapping> <servlet-name>login </servlet-name> <url-pattern>/utils/LoginServlet</u
Which element guarantees a servlet will be loaded on the start up of the web application
- <load-on-startup>true</load-on-startup>
- <load-on-startup>1</load-on-startup>
- <load-on-startup>0</load-on-startup>
- <load-on-startup/>
How to define a session time out of 10 minutes in web.xml
- <session-config> <session-timeout>10</session-timeout> </session-config>
- <session-config> <session-timeout>600</session-timeout> </session-config>
- <session-time-config> <session-timeout>600</session-timeout> </session-time-config>
- <session-config> <session-invalid-time>60</ session-invalid-time> </session-config>
Which is the correct definition of servlet init parameter in web.xml?
- <servlet> <servlet-name>login</servlet-name> <servlet-class>com.tcs.login.LoginServlet</servlet-class> <init-param> <param-name>mailId</param-name> <param-value>[email protected]</param-val
- <servlet> <servlet-name>login</servlet-name> <servlet-class>com.tcs.login.LoginServlet</servlet-class> </servlet> <init-param> <param-name>mailId</param-name> <param-value>[email protected]
- <servlet> <servlet-name>login</servlet-name> <servlet-class>com.tcs.login.LoginServlet</servlet-class> </servlet> <servlet-init-param> <param-name>mailId</param-name> <param-value&
- <servlet> <servlet-name>login</servlet-name> <servlet-class>com.tcs.login.LoginServlet</servlet-class> <servlet-init-param> <param-name>mailId</param-name> <param-value>[email protected]</
package polymorphism;class TestPolymorphismSuper1 { String name; TestPolymorphism2 testPoly() { TestPolymorphism2 TS = new TestPolymorphism2(); TS.name ="tcs"; return TS; }}public class TestPolymorphism2 extends TestPolymorphismSuper1{ TestPolymorphism2 testPoly() { TestPolymorphism2 TSub = new TestPolymorphism2(); TSub.name = "UX"; return TSub; } public static void main(String[] args) { TestPolymorphismSuper1 TSuper = new TestPolymorphism2(); TSuper.testPoly(); System.out.println(TSuper.name); }}
- UX
- tcs
- null
- Exception
package polymorphism;class TestSup { static int p = 100;}public class TestPoly extends TestSup { public static void main(String[] args) { TestPoly TP = new TestPoly(); TP.p = 400; TestSup TS = new TestSup(); TS.p = 100; TestSup TSP = new TestPoly(); TSP.p = 500; System.out.print("TestSup = " + TestSup.p); System.out.print(" ,TestPoly = " + TestPoly.p); System.out.print(" ,TP = " + TP.p); System.out.print(" ,TS = " + TS.p); System.out.print(" ,TSP = " + TSP.p); }}
- TestSup = 100 ,TestPoly = 400 ,TP = 500 ,TS = 500 ,TSP = 500
- TestSup = 500 ,TestPoly = 500 ,TP = 500 ,TS = 500 ,TSP = 500
- TestSup = 100 ,TestPoly = 400 ,TP = 400 ,TS = 100 ,TSP = 500
- TestSup = 500 ,TestPoly = 400 ,TP = 500 ,TS = 100 ,TSP = 400
package polymorphism;class TestSuperr { double TestPoly(long a, float b, int c) { return ((a + b) * c); }}public class TestPolym extends TestSuperr { double TestPoly(long a, double b, int c) { return (a + b + c); } public static void main(String[] args) { TestSuperr TSU = new TestPolym(); double p = TSU.TestPoly(11, 9, 10); System.out.print("p = " + p); p1 = TSU.TestPoly(11, 9.0, 10); System.out.print(" ,p1 = " + p1); }}
- p = 200.0, p1 = 30.0
- p = 200.0, p1 = 200.0
- p = 30.0, p1 = 30.0
- Compiler Error
package polymorphism; class TestSupe { static int p = 100; } public class TestPoly1 extends TestSupe { static int p =1000; public static void main(String[] args) { TestPoly1 TP = new TestPoly1(); TP.p = 400; TestSupe TS = new TestSupe(); TS.p = 300; TestSupe TSP = new TestPoly1(); TSP.p = 500; System.out.print("TestSupe = " + TestSupe.p); System.out.print(" ,TestPoly = " + TestPoly1.p); System.out.print(" ,TP = " + TP.p); System.out.print(" ,TS = " + TS.p); System.out.print(" ,TSP = " + TSP.p); } }
- TestSupe = 300 ,TestPoly = 400 ,TP = 400 ,TS = 300 ,TSP = 500
- TestSupe = 500 ,TestPoly = 400 ,TP = 400 ,TS = 500 ,TSP = 500
- TestSupe = 500 ,TestPoly = 400 ,TP = 400 ,TS = 300 ,TSP = 500
- TestSupe = 300 ,TestPoly = 400 ,TP = 500 ,TS = 500 ,TSP = 500
What is a method's signature?
- The signature of a method is the name of the method the type of its return value.
- The signature of a method is the name of the method and the names of its parameters.
- The signature of a method is the name of the method and the data types of its parameters.
- The signature of a method is the name of the method, its parameter list, and its return type.
What is an advantage of polymorphism?
- The same program logic can be used with objects of several related types.
- Variables can be re-used in order to save memory.
- Constructing new objects from old objects of a similar type saves time.
- Polymorphism is a dangerous aspect of inheritance and should be avoided.
Which is not a java keyword?
- for
- break
- continue
- Structure
What command is used to compile a program in Java
- javac
- java
- run java
- javas
How many objects of a given class can there be in a program?
- One per defined class.
- One per constructor definition.
- As many as the program needs.
- One per program
Distributed programming helps in:
- balance resource loading
- lower cost of development since clients can access remote codes for services
- operator overloading
- none of these
Is it OK if a class definition implements two interfaces, each of which has the same definition for a constant PI?
- True
- False
Is "java.lang.Object" a valid class in java?
- True
- False
"JAVA" stands for Just Another Virtual Analyser
- True
- False
The garbage collector will run immediately when the system runs out of memory.
- True
- False
Current version of java is 1.5
- True
- False
What is dependency injection?
- A pattern (design) whereby collaborators are passed into an object from the outside - the object does not allocate them for itself.
- It is a pattern in which the child class inherit the parent class properties
- It is a type of operator overloading in java
- It represents the compile time and run time polymorphism in java