Вы находитесь на странице: 1из 14

Sachin krishna

Why pointers are eliminated from java? 1.pointers are lead confusion to progranmmer 2.pointers break security,using pointers ,harmful programs like virus and other hacking programs can be developed. What is the diff between function and method? Method:it is a function that is written in class,we do not have functions in java..we use methods here When ever function is written in java it should be written in inside the class only But in c++ we write the finctions inside as wee as ousidedats y it is called as member functions Which part of the jvm will allocate the memory for a java program? Class loader subsystem of jvm will allocate the necessary memory needed by the java program, Which algorithm is used by the garbage collector to remove the unused variables from memory? The algorithm is mark and sweep.. How u can call the garbage collector? It is automatically invoked when the program is being runit can also called by gc()method of run time class in java. What is jit compiler? It is the part of jvm which increases speed of execution of the java program What is diff b/n c++ and java? C++ It is not a purely oop language Pointers are available and statement java It is a purely oop language goto We cannot create pointers in java and no goto statement

sachin

Sachin krishna

Operator overloading and multiple No multiple inheritance and operator inheritance in c++ overloading in java What is diff b/n include and import statement? #include directive makes the compiler goto standard library and copy the code from the header files in to the program.as a result wasring memory and processors time Import statement makes the jvm goto java standard library ,execute the code there,and substitute the result in to the program.import is efficient than include What happens if string args[] is not written in main() method? The code will compile but jvm cannot run the code because it cannot recognize main() methodjvm always looks for main() method with string type as parameter. What is the diff n/n print() and println()? Both methods are used to display the results Print() method displays the result and then retains the cursor in the same line Println() displays the result and throws the cursor to the next line What is diff b/n float and double? Float can represent up to 7 digits accurately after decimal point,where as double can represent up to 15 digits What is Unicode system? It is an encoding standard that provides a unique number for every character..unicode uses 2 bytes to represent a single character. How positive and negative numbers are represented internally? Positive numbers are represente in binary using 1s compliment form and negarive is in 2s complement form What is the diff b/n >> and >>>?

sachin

Sachin krishna

>> is bitwise r8 shift operator ..>>> is biewise zero fill r8 shift operator Both r used for shift the bits towars right >> protect the sign bit and <<< will not protect the sign bit. What are control statements? These statements which alter the flow of execution and provide better control to the programmer on flow of execution. Which loop is efficient do or while? While loop is more efficient What is a collection? It represents group of elements like integers values or objects..examples are arrays and java.util classes(stack,linked list,vector,etc) Why goto statements are not present in java? It leads confusion to the programmer..if several goto statements are used the programmer should be perplexed while understanding the flow from where to where the control is jumping What is diff b/n return and system.exit(0)? Return statement is used inside a method to come out of it.system.exit(0) is used in any where to come out of the program What is diff b/n system.exit(0) and system.exit(1)? System.exit(0) terminates the program normally, System.exit(1) terminate sthe program because of the program because of some error encountered in the program What is diff b/n system.out and system.err? Both can be used to send the data or results on monitor System.out display normal messages and system.err displays error messages
sachin

Sachin krishna

On which memory ,arrays are created in java? Arrays are created on dynamic memory by jvm.in java every thing is stored in dynamic memory Can u call the main() method of a class from another class? Yes,we can call using classname.main().at the time of calling main() method,we should pass a string type array to it Is string a class or datatype? String is a class in java.lang package.all classes are datatypes in java Can we call class is a datatype? Yes,a class is also called user-defineddatatype What is object reference? It is a unique hexadecimal number representing the memory address object.it is useful to access the members of the object. What is diff b/n == and equals()? == compare sthe reference of the string objects.it does not compare the contents of the object Equals() compares the contents..equals() is reliable to produce correct results What is string constant pool? It is a separate block of memory where the string objects are held by jvm. String s1=hello it is stored in string constant pool. What is diff b/n string and stringbuffer classes? Strings are immutable it cannot be modified String buffer class objects are mutable,they can be modified What is diff b/n stringbuffer and string builderclass? of the

sachin

Sachin krishna

String buffer is synchronized and stringbuilder is not. When the programmer wants to use several threads stringbuffer is used When the programmer use single thread ,string builder is preffered,as it improves execution time What is object oriented approach? It is a programming methodology to design computer programs using classes and objects What is diff b/n class and object? A class is a model for creating objects and does not exist physically. An object is any thing that exists physically Both classes and objects contain variables and methods Encapsulation? Where the data and code bind together .class is an example for encapsulation Abstraction? Hide the unnecessary data from the user,expose only that data that is of interest to the user Inheritance? It creates new classes from the existing classes. Example ::in nature parents producing the children and children inheriting the qualities of parents Polymorphism? Polymorphism provides flexibility in writing programs in such way that the programmer uses same method call to perform diff operations depending on the requirement What is diff b/n object oriented and object based programming?
sachin

Sachin krishna

Ool follow all the features of the oops.ex:small talk,c++,java Oob follow all features except inheritance.ex:javascript,vb script What is hash code? It is a unique identification number allotted to the objects by the jvm.it is also called reference number How can u find thee hash code of an object? Hashcode() method of object class in java.lang package is useful to find the hashcode Access specifiers: Private::members of classare not accessible any where outside the class.they are accessible only inside the class Public::members of class are accessible every where outside the class Protected::members of a class accessible outside the class but with in the directory Can u declare class as private? No,if we declare class as a private,it is not available to jvm and compile time error occurs..but,inner classes declare as a private When is constructor called,before or after creating the object? A constructor is called concurrently when the object is running on..jvm allocates memory first for the object and then executes the constructor yo initialize the instance variables. What is constructor overloading? Writing two or more constructors with same name but with difference parameters is called constructor overloading.such constructors are useful to perform different tasks.

sachin

Sachin krishna

What are instance methods? It is the methods which act on the instance variables of the class.to call the instance methods,we should use the form:objectname.methodname() What are static methods? It is the methods which does not act upon the instance variables of a class.it is declared as static. What is diff b/n instance variables and static variables? An instance variable is a variable whose separate copy is available to each object. A class variable is a variable whose single copy is available to each object. Instance variable are created in the objects of heap memory Why instance variables are not available to static methods? After executing the static methods.jvm creates the objects.this is the reason. Is it possible to compile and run a java program without writing main() method? Yes it is possible using a static block method in the java program. How objects are passed to methods in java? Everything are passed to methods by using pass by value or call by value method This means their bit by bit copy is passed to methods What are factory methods? A factory method is a method that creates and returns a object to the class to which it belongs. A single factory method replaces several constructors in the class by accepting different options from the user ,while creating the object In how many ways can u create object in java? 4 ways.1)using new operator emp obj=new emp();

sachin

Sachin krishna

2)using factory methods nf obj=nf.getnumberinstance() 3)using new instance method class c=class.forname(employee); 34)by cloning method What is object graph? It is agraph showing relationship b/n different objects in memory What is anonymous inner class? It is a inner class whose name is not written in the outer class and for which only one object is created. What is inheritance? Deriving new classes from the existing classes Why super class members are available to subclass? Because ,the sub class object contains a copy of super class object What is the advantage of inheritance? In heritance,a programmer reuses the super class code without rewriting it,in creation of subclasses,so developing the classes very easy Why multiple inheritance are not available in java? It leads confusion The programmer can achieve multiple inheritance by using interfaces. How many types of inheritances are there? Two types:single and multiple all other types are mere combination of these Java supports only single inheritance What is coercion? It is automatic conversion between different data types done by the compiler

sachin

Sachin krishna

What is conversion? It is a explicit change in the datatype specified by the cast operator What is method signature? It represents the method name along with method parameters What is method overloading? Writing two or more methods in the same class ,each method has same name with different method signatures What is method overriding? Writing two or more methods in super and sub classes,that methods have same name and same signature Can u override private methods? No private methods are not available in sub classes, they cannot be overridden

Can we take private methods and final methods are same? Both the methods cannot be overridden ,so private methods can be taken as final methods What is final? It is used in two ways: It is used to declare constants final double pi=3.15159; It is used to prevent inheritance as: Final class a Subclass cannot be created
sachin

Sachin krishna

What is diff b/n primitive and advanced datatypes? Primitive datatypes represents single values.advanced datatypes represents group of values In Primitive methods are not available.in advanced methods are available What is implicit casting? Automatic casting done by the jvm compiler internally is called implicit casting.it is done to convert a lower datatype into a higher datatype. What is explicit casting? This casting is done by a programmer.converting from higher datatype to lower datatype. What is generalization? It is a phenomenon where subclass is promoted to a super class.it needs upcasting What is specialization? It is a phenomenon where super class is narrowed down to sub class.it needs downcasting. What is widening and narrowing? Converting lower datatype in to higher is called widening. Converting higher into lower is narrowing. Which is the supeer class for all the clases including your classes also? Object class What is marking interface? An interface with out any members is called marking interface. What is abstract method?

sachin

Sachin krishna

It is a method without method body..an abstract method is written when the same method has to perform different tasks depending on the object calling it. What is abstract class? Abstract class is a class that contains 0 or more abstract methods. How can you force programmers to implement only the features of your class? By writing abstract class or an interface. Can u declare a class as abstract and final also? No,abstract class needs subclasses.final class represents subclasses which cannot be created. What is interface? An interface is a specification of method prototypes.all the methods of the interface are public and abstract. Why the method of interface are public and abstract by default? It is public because they should be available to third party to provide implementation. They are abstract because their implementation is left for third party vendors Can u implement one interface from another?n No,we cant Can u write a class within an interface? Yes,it is possible to write a class with an interface. How can u call the garbage collector? We can call garbage collector of jvm to delete any unused variables and unreferenced objects from memory using gc() method. The gc() appers in both run time and system classes of java.lang package.

sachin

Sachin krishna

What is difference between below two statements? 1)import pack.addition; 2)import pack.*; In frst statement,only the addition class of the package pack is imported in to the program and in Second statement ,all the classes and interfaces of the package pack are available to the program. What is CLASSPATH? It is an environment variable that tells the java compiler where to look for class files to import.CLASSPATH is generally set to a directory or a JAR file. What is JAR file? It is a file that contains compressed version of several .class files,audio files,image files or directories. JAR file is useful to bundle up several files related to aproject and use them easily. What is the scope of default access specifier? Default members are available with in the same package,but not outside of the package .so their scope is package scope. What happens if main() method is written without string args[]? The code compiles but jvm cannot run it,as it cannot see the main() method with string args[]. What are checked exceptions? The exceptions are checked at compilation time by the java compiler are called checked exceptions,. The exceptions are checked by the jvm are called unchecked exceptions;. What is throwable?

sachin

Sachin krishna

It is a class that represents all errors and exceptions which may occur in java Which is super class for all exceptions? It is the super class for all exceptions in java What is the difference b/n exception and error? Exception is a error which can be handled. Error which cannot be handeled. What is the difference b/n throws and throw? Throws clause is used when the programmer does not want to handle the exception and throw it out of a methd. Throw clause is used whenthe programmer wants to throw an exception explicitly and wants to handle it using catch block.throw and throws are contradictory. why do we need wrapper classes? They convert primitive datatypes into objects and this is needed on internet to communicate between two applications. The classes in java.util package handle only objects and hence wrapper classes help in this case also

sachin

Sachin krishna

sachin

Вам также может понравиться