Showing posts with label ALL JAVA. Show all posts
Showing posts with label ALL JAVA. Show all posts

Tuesday, June 12, 2012

Java questions and answers for viva

Java questions and answers for viva 


(1)
public class Literal {
    public static void main(String[] args) {
         String str$="world";
         char str_='X';
         String $_=str$+str_;
         System.out.print($_);
            
    }
}
What will output when you compile and run the above code?
(a)world
(b)worldX
(c)world’X’
(d)Compiler error
Answer: (b)
Explanation:
    In java programming language operator + can add two numeric data type as well as it can concatenate two string or character data type.
Here $_=”world”+’X’ ,Operator + is working as concatenating one string and char data type.
Note: $_ is valid variable name. In java programming language variable name includes alphabet, digits few special characters like underscore (_), dollar singe ($) but it should not be any reserved word of java language. 
Integer Literals
(2)
public class Literal {
    public static void main(String[] args) {
         int a=012;
         int c=a*2;
         System.out.print(c);
            
    }
}
What will output when you compile and run the above code?
(a) 24
(b) 024
(c) 20
(d) Compiler error
Answer: (c)

(3)
public class Literal {
    public static void main(String[] args) {
         byte a=0110;
         int c=a*2;
         System.out.print(c);
            
    }
}
What will output when you compile and run the above code?
(a)1100
(b)220
(c)144
(d) Java doesn’t support binary number.Compiler error

Answer: (c)
(4)
public class Literal {
    public static void main(String[] args) {
         byte a=08;
         int c=a>>2;
         System.out.print(c);
            
    }
}
What will output when you compile and run the above code?
(a)32
(b)2
(c)02
(d) Compiler error
Answer: (d)
(5)
public class Literal {
    public static void main(String[] args) {
         byte a=0x11;
         byte b=0X22;
         int c=a&&b;
         System.out.print(c);
            
    }
}
What will output when you compile and run the above code?
(a)2
(b)0
(c)1
(d) Compiler error
Answer:  (d)
(6) Numerical value of false in java is :
(a)  0
(b) All values except one
(c) zero and all negative integers
(d) java doesn’t support any numerical value of false
Answer: (d)
(7)
public class Literal {
    public static void main(String[] args) {
         boolean b =5==5;
         int a=(int)b;
         System.out.println(a);
    }
}
What will output when you compile and run the above code?
(a)0
(b)1
(c)NaN
(d) Compiler error
Answer:(d)

(8) Which of the following is not valid java floating point literal?
(a) 4.5f
(b) .033D
(c) 5.0e^2
(d) 6.8
Answer: (c)
(9) Which of the following is a not valid java floating point literal?
(e) 8.09F
(f) .033f
(g) 5.0E25
(h) 6.8e^2
Answer: (h)
(10)
public class Scope {
    public static void main(String[] args) {
         int a=5;
         {
             a=10;
             int b=15;
             a=a+b;
         }
         System.out.println(a);
    }
}
What will output when you compile and run the above code?
(a)5
(b)25
(c)Run time exception
(d) Compiler error
Answer: (b)
(11)
public class Scope {
    public static void main(String[] args) {
         {
             static int a=5;
         }
         {
             int a=10;
             a=++a;
         }
         System.out.println(a);
    }
}
What will output when you compile and run the above code?
(a)5
(b)21
(c)11
(d) Compiler error
Answer: (d)
(12)
public class Scope {
    public static void main(String[] args) {
         {
             int a=5;
             System.out.println(a);
         }
         int a=6;
         a=~a;
         System.out.println(a);
    }
}
What will output when you compile and run the above code?
(a)5
  -7
(b)5
  -6
(c)Run time exception
(d) Compiler error



Answer: (a)

JAVA MULTIPLE CHOICE QUESTIONS

Basic java questions and answers

Basics core java questions and answers 
(1) Which of the following option is not true about java programming language? 
(a) Java is high level programming language.
(b) Java is a platform.
(c) javac is compiler.
(d) Byte code is executed by CPU. 
Answer: (d)
(2) Which is a not characteristic of java programming language? 
(a) Robust
(b)Procedural
(c) Distributed
(e) Multithreaded
Answer: (b)
(3) Which of the following is true about of java hotspot virtual machine? 
(a) It is additional virtual machine which improves the performance of an application.
(b) It is internal device which convert source code into byte code.
(c) It is virtual machine which detects runtime exception.
(d) All are true.
 Answer: (a)
(4) Which of the following is correct?
(a) Java platform is software only platform that runs on the top of other hardware based platform. 
(b) Java platform has two components: JVM, API.
(c) Java technology is programming language as well as platform
(d) All of the above.
 Answer: (d) 
(5) Which of them is a not command line tool?
(a) java
(b) javaw
(c) javapath
(d) javadoc 
Answer: (c) 
(6) Which of the following is correct about main method in java?
(a) Must be declared as public. 
(b) It must not return any value.
(c) Must be declared as static.
(e) Must accept string as a parameter.
(f) Above all are compulsory. 
(g) All are optional.
 Answer: (f)
(7) Which not true about API in java?
(a) API stands for application package interface. 
(b) It is large collection of software components.
(c) It is large array of useful class.
(d) It is grouped into the package of related class. 
Answer: (a) 
(8) Which of the following is correct? 
(a)
class MainClass {
     static public void main(String[] args) {
          System.out.println("Hello World!");
     }
}
(b)
class MainClass {
     public static void main(String[] args) {
          System.out.println("Hello World!");
     }
}
(c)
 class MainClass {
      static public int main(String[] args) {
           System.out.println("Hello World!");
           return 1;
     }
}
(d) Both option (a) and (b)
 Answer: (d) 
(9) Which of the following is not true in java? 
(a) Java platform is bit faster than actual CPU platform.
(b) javac is compiler tool. 
(c) java command launch an application. 
(d) javadoc is documentation tool. 
Answer: (a) 
(10) What is difference between following two commands?
(i) java ClassName
(ii)javaw ClassName
Where ClassName.class is name of any class file. 
(a) Execution time of (i) is faster than (ii) 
(b) (i) is used to run in server machine while (ii) is used to run in client machine.
(c) (ii) is used to run in server machine while (i) is used to run in client machine. 
(d) (i) has console window while (ii) has not any console window. 
Answer: (d) 
(11) If any class file Binary.class is zipped in Binary.zip at c:\Test. Which of the following command line command is suitable to execute the zip file?
(a) java –classpath c:\Test\Binary.zip Binary
(b) java –cp c:\Test\Binary.zip Binary
(c) javaw –classpath c:\Test\Binary.zip Binary 
(d) javaw –cp c:\Test\Binary.zip Binary
(e) All of them are correct.
Answer: (e) 
(12) How can we set the following two path of class folder at a time in command prompt?
(i) c:\test
(ii) Current working directory.
(a) set classpath=c:\test;.
(b) set -cp=c:\test;.
(c) path=c:\test;. 
(d) PATH=. ; c:\test 
Answer: (a) 
(13) If Binary.class is present is at both of following directory
(i) c:\test
(ii) d:\raja
Which of them is true if following command is executed in the command prompt?
set cp=c:\test;d:\raja java Binary
(a) Binary.class, which is present in test folder will execute only.
(b) Binary.class, which is present in raja folder will execute only. 
(c) Binary.class, which are present in test and raja folders both will execute. 
(d) It will depend upon O.S.
 Answer: (a)

Debugging questions in C with answers

Debugging questions in c with answers


C debugging interview questions
C debugging questions with answers


1. Write a c program too shutdown window operating system   in TURBO C.

void main(void)
{
system("shutdown -s");
}
Save the above .Let file name is close.c and compile and execute the above program. Now close the turbo c compiler and open the directory in window you have saved the close.c (default directory c:\tc\bin) and double click its exe file (close.exe).After some time your window will shutdown.
2. Write a scanf statement which can store one line of string which includes white space?
Answer:
void main() {
char a[30];
clrscr();
scanf("%[^\n]",a);
printf("%s",a);
getch();
}
3. Given the string "MATCHMAKING", write a program to read the string from the terminal and display the same in the following formats:
(a) MATCH MAKING
(b) MATCH
MAKING
(c) M.M.
4.  I need it to write a C/C++ program that connects to a MySQL server and displays the global TIMEZONE.
5.  A string (example "I am writing an email") is entered through the keyboard, write a program in C to get its reverse in a column as output i.e.:
email
an
writing
am
Answer:
void main()
{
char str[20];
char *ptr=str,*temp;
int i=0,j;
clrscr();
scanf("%[^\n]",str);
while(*ptr){
i++;
ptr++;
}
for(j=0;j
            if(*ptr==' ')
            {
                  temp=ptr;ptr--;temp++;
                  while((*temp!=' ')&&(*temp!='\0')) {
                       printf("%c",*temp);
                        temp++;
                  }
                  printf("\n");
            }
            else
            {
                  ptr--;
            }
}
while(*ptr!=' ') {
printf("%c",*ptr);
ptr++;
}
getch();
}
6. I want a C program to check whether a string is a palindrome or not where the string to be checked is passed as command line argument during execution.
Answer:
#include
void main(int counter,char**string)
{
char *rev;
char str[15];
int i,j;
clrscr();
strcpy(str,string[1]);
printf("%s",str);
for(i=strlen(str)-1,j=0;i>=0;i--,j++)
rev[j]=str[i];
rev[j]='\0';
if(strcmp(rev,str))
printf("\nThe string is not a palindrome");
else
printf("\nThe string is a palindrome");
getch();
}
7. How to write a c program to display the source code of the program.
Answer:
If source code is available
#include
void main()
{
   char str[70];
   FILE *p;
   clrscr();
   if((p=fopen("mod.c","r"))==NULL)
   {
      printf("\nUnable t open file string.txt");
      exit(1);
   }
   while(fgets(str,70,p)!=NULL)
          puts(str);
   fclose(p);
   getch();
}
8. Swapping of two number without using third variable
Answer:
void main()
{
int a=5,b=10;
clrscr();
//process one
a=b+a;
b=a-b;
a=a-b;
printf("a= %d  b=  %d",a,b);
//process two
a=5;b=10;
a=a+b-(b=a);
printf("\na= %d  b=  %d",a,b);
//process three
a=5;b=10;
a=a^b;
b=a^b;
a=b^a;
printf("\na= %d  b=  %d",a,b);
//process four
a=5;b=10;
a=b-~a-1;
b=a+~b+1;
a=a+~b+1;
printf("\na= %d  b=  %d",a,b);
//process five
a=5,b=10;
a=b+a,b=a-b,a=a-b;
printf("\na= %d  b=  %d",a,b);
getch();
}
9. How to convert decimal to binary in c program?
Answer
void main()
{
  long int m,no=0,a=1;
  int n,rem;
  clrscr();
  printf("Enter any decimal number->");
  scanf("%d",&n);
  m=n;
  while(n!=0)
  {
          rem=n%2;
          no=no+rem*a;
          n=n/2;
          a=a*10;
  }
  printf("The value %ld in binary is->",m);
  printf("%ld",no);
  getch();
}
  
10. Write a program to accept character and integer n from user and display next n character
Answer:
void main()
{
char c;
int n,i;
clrscr();
printf("insert one character and integer : ");
scanf("%c%d",&c,&n);
for(i=c+1;i<=c+n;i++)
printf("%c ",i);
getch();
}
Output:
insert one character and integer : c 4
d e f g
C debugging questions
Debugging questions in c