Study Viral (Java Tutorials For Beginners - Step By Step)
  • Home
  • Java Tutorials
    • Core Java
    • Java Swing
    • MS Access JDBC Java Application
  • Facebook Page
  • Programs
    • C Programs
    • C++ Programs
    • Java Programs
    • Python Programs
  • UGC NET
  • Home
  • Java Tutorials
    • Core Java
    • Java Swing
    • MS Access JDBC Java Application
  • Facebook
  • Programs
    • C Programs
    • C++ Programs
    • Java Programs
    • Python Programs
  • UGC NET

UGC NET JULY 2018 (Computer Science And Applications Paper-II) (Question 3-4)

 July 08, 2018     Computer Science And Applications Paper-II, UGC NET JULY 2018     No comments   

UGC NET JULY 2018 (Computer Science And Applications Paper-II) (Question 3-4)


Q3. What is the output of the following JAVA program ?

      
       class simple
       {
           public static void main(String []args)
           {
                simple obj = new simple();
                obj.start();
           }
           void start()
           {
                 long [] P ={3,4,5};
                 long []Q = method(P);
                 System.out.print(P[0]+P[1]+P[2]+" : "); 
                 System.out.print(Q[0]+Q[1]+Q[2]+" : ");
           } 
           long [] method(long []R)
           {
                 R[1] = 7;
                 return R;
           }
       }//end of class

    (1) 12:15
    (2) 15:12
    (3) 12:12
    (4) 15:15

Reason : Initially array P as {3,4,5}. When we pass array P to method as method(P); the method function replaces the value of index 1  i.e. 4 with 7. Now new updated array is value {3,7,5}.
This new returned value reflects on both arrays respectively P and Q. Last the print function adds all index location values of  both arrays separately and shows output 15:15.  


Q4. What is the output of following 'C' program? (Assuming little - endian representation of multi-byte data in which Least Significant Byte (LSB) is stored at the lowest memory address.)

1. #include <stdio.h>
2. #include <stdlib.h>/**/
3. int main()
4. {
5.     union saving
6.     {
7.         short int one;
8.         char two[2];
9.     };
10.    union saving m;
11.    m.two[0] = 5;
12.    m.two[1] = 2;
13.    printf("%d, %d, %d\n",m.two[0],m.two[1],m.one);
14.    return 0;
15. }

(1)   5 ,2, 1282
(2)   5 ,2, 52
(3)   5 ,2, 25
(4)   5 ,2, 517 

 Reason : This is one is interesting question in exam. First we have to know about Big-endian and little-endian are terms that describe the order in which a sequence of bytes are stored in computer memory. Big-endian is an order in which the "big end" (most significant value in the sequence) is stored first (at the lowest storage address). Little-endian is an order in which the "little end" (least significant value in the sequence) is stored first. For example, in a big-endian computer, the two bytes required for the hexadecimal number 4E52 would be stored as 4E52 in storage (if 4E is stored at storage address 1000, for example, 52 will be at address 1001). In a little-endian system, it would be stored as 524E (52 at address 1000, 4E at 1001).
Here we have little - endian in our question. In code we have two union members short int one and char two[2]. In line 11,12 we have numeric values 5 and 2 in char array (without single quote '5' and '2'). In line 13 the output also shows result with %d (i.e. represents for numeric values) which is okay for output 5, 2 but how third values came because we did not provided any value to union member short int one. Just suppose binary conversion of
    5 is 00000101 and  2 is 00000010

Lowest Address (1000)Highest Address(1001)
0000010100000010

Now as per question requirement little - endian representation of multi-byte data in which Least Significant Byte (LSB) is stored at the lowest memory address. Therefore

Lowest Address (1000)Highest Address(1001)
0000001000000101
Now 00000010-00000101 convert this to Decimal value

512+0+0+0+0+0+0+4+0+1  = 517 
After converting the combination of both numbers we have 517 at third location and final result 5, 2, 517.
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
Email ThisBlogThis!Share to XShare to Facebook
Newer Post Older Post Home

0 comments:

Post a Comment

Facebook

StudyViral

Labels

Alphabet Pattern Binary Tree BLOB (Binary Large Object) Computer Networks Computer Science And Applications Paper-II Data Structure DBMS Digital Clock Digital Watch Extra Tutorials File Upload Find Age from Date of Birth Graph-Algorithms Java and J2EE web applications JAVA JDK 12 Java Mail API Java MySQL Java Programs Java Programs List Java Servlets Java Swing Java Swing With MySQL Database Java Tutorials JCalender KVS Compuer Science - January 2017 Question Paper MS Access JDBC Java Application Multiuser Login NETBEANS 11 IDE Occurrence of Digits in Number Operation System Pattern Program Reverse of String Sending Email Servlet Servlet Tutorial Software Engineering Star Struts 2 FrameWork Struts 2 Registration Form UGC NET JULY 2018 Windows Commands

Popular Posts

  • Program 01: Write a program to display/print your name.
     Program 01 - Write a program to display/print your name. This is a very basic and introductory program in Java. You might see similar p...
  • Install NetBeans 11 IDE on Windows 10 - Study Viral
    Install NetBeans 11 IDE on Windows 10 - Study Viral How to Install NetBeans 11 IDE on Windows 10. Download Link : https://netbeans...
  • Create CON, AUX, NUL name folder and files in Windows - Study Viral
    Create CON, AUX, NUL name folder and files in Windows - Study Viral Most of you may be aware of many MS-DOS commands but still n...

Categories

  • Alphabet Pattern (13)
  • Binary Tree (2)
  • BLOB (Binary Large Object) (1)
  • Computer Networks (2)
  • Computer Science And Applications Paper-II (40)
  • Data Structure (6)
  • DBMS (1)
  • Digital Clock (1)
  • Digital Watch (1)
  • Extra Tutorials (3)
  • File Upload (1)
  • Find Age from Date of Birth (1)
  • Graph-Algorithms (1)
  • Java and J2EE web applications (3)
  • JAVA JDK 12 (1)
  • Java Mail API (3)
  • Java MySQL (5)
  • Java Programs (44)
  • Java Programs List (3)
  • Java Servlets (3)
  • Java Swing (16)
  • Java Swing With MySQL Database (4)
  • Java Tutorials (37)
  • JCalender (1)
  • KVS Compuer Science - January 2017 Question Paper (6)
  • MS Access JDBC Java Application (6)
  • Multiuser Login (1)
  • NETBEANS 11 IDE (1)
  • Occurrence of Digits in Number (1)
  • Operation System (4)
  • Pattern Program (8)
  • Reverse of String (2)
  • Sending Email (1)
  • Servlet (3)
  • Servlet Tutorial (3)
  • Software Engineering (4)
  • Star (7)
  • Struts 2 FrameWork (2)
  • Struts 2 Registration Form (1)
  • UGC NET JULY 2018 (40)
  • Windows Commands (2)

Pages

  • Java Tutorials
  • ASP.NET (in Hindi)
  • Java Programs List

Blog Archive

  • ►  2021 (3)
    • ►  April 2021 (3)
  • ►  2019 (7)
    • ►  June 2019 (1)
    • ►  May 2019 (2)
    • ►  March 2019 (4)
  • ▼  2018 (111)
    • ►  November 2018 (7)
    • ►  October 2018 (20)
    • ►  September 2018 (10)
    • ►  August 2018 (3)
    • ▼  July 2018 (19)
      • Java Swing Retrieve Image From Database (MySQL) as...
      • Java Swing - Save Image to Database (MySQL) as BLO...
      • UGC NET JULY 2018 (Computer Science And Applicatio...
      • UGC NET JULY 2018 (Computer Science And Applicatio...
      • UGC NET JULY 2018 (Computer Science And Applicatio...
      • UGC NET JULY 2018 (Computer Science And Applicatio...
      • UGC NET JULY 2018 (Computer Science And Applicatio...
      • UGC NET JULY 2018 (Computer Science And Applicatio...
      • UGC NET JULY 2018 (Computer Science And Applicatio...
      • UGC NET JULY 2018 (Computer Science And Applicatio...
      • UGC NET JULY 2018 (Computer Science And Applicatio...
      • UGC NET JULY 2018 (Computer Science And Applicatio...
      • UGC NET JULY 2018 (Computer Science And Applicatio...
      • UGC NET JULY 2018 (Computer Science And Applicatio...
      • UGC NET JULY 2018 (Computer Science And Applicatio...
      • UGC NET JULY 2018 (Computer Science And Applicatio...
      • UGC NET JULY 2018 (Computer Science And Applicatio...
      • UGC NET JULY 2018 (Computer Science And Applicatio...
      • UGC NET JULY 2018 (Computer Science And Applicati...
    • ►  June 2018 (5)
    • ►  May 2018 (2)
    • ►  April 2018 (3)
    • ►  March 2018 (11)
    • ►  February 2018 (18)
    • ►  January 2018 (13)
  • ►  2017 (36)
    • ►  December 2017 (10)
    • ►  November 2017 (9)
    • ►  October 2017 (7)
    • ►  September 2017 (10)

About Me

Rohit Basra
Hello guys my name Rohit Basra. I love to code and teach java language.
View my complete profile

Followers

Copyright © Study Viral (Java Tutorials For Beginners - Step By Step) | Powered by Blogger