Saturday, 10 October 2015

Data types

Java data type questions and answers with govind 

Java objective type data type questions and answers


(1)What will be the output of following java program?

class Datatype{
     public static void main(String[] args){
          byte num=(byte)130;
          System.out.print(num);
     }
}





Output: -126

(2)What will be the output of following java program?

class Datatype{
     public static void main(String[] args){
          byte num=130;
          System.out.print(num);
     }
}





Output: Compiler error

(3)What will be the output of following java program?

class Datatype{
     public static void main(String[] args){
          byte number=0101;
          System.out.print(number);
     }
}





Output: 65

(4)What will be the output of following java program?

class Datatype{
     public static void main(String[] args){
          short num=0x8fff;
          System.out.print(num);
     }
}







Output: compiler error

(5)What will be the output of following java program?

class Datatype{
     public static void main(String[] args){
          char num=65;
          System.out.println(num);
     }
}





Output: A

(6)What will be the output of following java program?

class Datatype{
     public static void main(String[] args){
          String str="india\0 usa";
          System.out.println(str);
     }
}






Output: India

(7)What will be the output of following java program?

class Datatype{
     public static void main(String[] args){
          String str="india\11usa";
          System.out.println(str);
     }
}




Output: india usa

(8)What will be the output of following java program?

class Datatype{
     public static void main(String[] args){
          String str="india\12usa";
          System.out.println(str);
     }
}





Output:
india
usa

(9)What will be the output of following java program?

class Datatype{
     public static void main(String[] args){
          String str="india\rome";
          System.out.print(str);
     }
}





Output:
india
ome

(10)What will be the output of following java program?

class Datatype{
     public static void main(String[] args){
          String str="japan\taskand";
          System.out.print(str);
     }
}





Output: japan askand

(11)What will be the output of following java program?

class Datatype{
     public static void main(String[] args){
          String str="local\national";
          System.out.print(str);
     }
}






Output:
local
ational

Array in c

Array tutorials in c programming language by examples



An array is derived data type in c programming language which

can store similar type of data in continuous memory location.

Data may be primitive type (int, char, float, double…), address of

union, structure, pointer, function or another array.

Example of array declaration:

int arr[5];
char arr[5];
float arr[5];
long double arr[5];
char * arr[5];
int (arr[])();
double ** arr[5];

Array is useful when:

(a) We have to store large number of data of similar type. If we

have large number of similar kind of variable then it is very

difficult to remember name of all variables and write the

program. For example:

//PROCESS ONE
#include<stdio.h>
int main(){
    int ax=1;
    int b=2;
    int cg=5;
    int dff=7;
    int am=8;
    int raja=0;
    int rani=11;
    int xxx=5;
    int yyy=90;
    int p;
    int q;
    int r;
    int avg;
    avg=(ax+b+cg+dff+am+raja+rani+xxx+yyy+p+q+r)/12;
    printf("%d",avg);

    return 0;      
}
If we will use array then above program can be written as:

//PROCESS TWO
#include<stdio.h>
int main(){
    int arr[]={1,2,5,7,8,0,11,5,50};
    int i,avg;
    for(int i=0;i<12;i++){
         avg=avg+arr[i];
    }
    printf("%d",avg/12);
    return 0;      
}

Question: Write a C program to find out average of 200 integer

number using process one and two.

(b) We want to store large number of data in continuous memory

location. Array always stores data in continuous memory location.

(q) What will be output when you will execute the following

program?

#include<stdio.h>
int main(){
int arr[]={0,10,20,30,40};
    char *ptr=arr;
    arr=arr+2;
    printf("%d",*arr);
    return 0;      
}

Advantage of using array:


1. An array provides singe name .So it easy to remember the

name of all element of an array.

2. Array name gives base address of an array .So with the help

increment operator we can visit one by one all the element of an

array.

3. Array has many application data structure.

Array of pointers in c:


        Array whose content is address of another variable is known

as array pointers.  For example:

#include<stdio.h>
int main(){
float a=0.0f,b=1.0f,c=2.0f;
    float * arr[]={&a,&b,&c};
    b=a+c;
    printf("%f",arr[1]);
    return 0;      
}

Complex arrays in c


1. Declaration of an array of size five which can store address

such functions whose parameter is void data type and return type

is also void data type:


void ( arr[5] )( );

2. Declaration of an array of size five which can store address

such function which has two parameter of int data type and

return type is  float data type:

float ( arr[5] )(int, int);

3. Declaration of an array of size two which can store the address

of printf or sacanf function:

int ( arr[2] )( const char *, … );

Note: prototype of printf function is:  int printf( const char *, … );

Different type of array in c:


(a) Array of integer
    An array which can hold integer data type is known as array of

integer.

(b) Array of character
    An array which can hold character data type is known as array

of character.

(c) Array of union
    An array which can hold address of union data type is known as

union of integer.

For example:

(1) What will be output when you will execute the following

program?

#include<stdio.h>
union A{
char p;
float const * const q;
};
int main(){
    union A arr[10];
    printf("%d",sizeof arr);
   return 0;    
}

Output: 20

(2) What will be output when you will execute the following

program?

#include<stdio.h>
union A{
    char character;
    int ascii;
};
int main(){
    union A arr[2]={{65},{'a'}};
    printf("%c %c",arr[0],arr[1]);
       return 0;    
}

Output: A a

(d) Array of structure
 An array which can hold address of structure data type is known

as array of structure. For example:

(1) What will be output when you will execute the following

program?

#include<stdio.h>
typedef struct stu{
    char * name;
    int roll;
}s;
int main(){
    s arr[2]={{"raja",10},{"rani",11}};
    printf("%s %d",arr[0]);
    return 0;      
}

Output: raja 10

(2) What will be output when you will execute the following

program?

#include<stdio.h>
struct A{
    int p;
    float q;
    long double *r;
};
int main(){
    struct A arr[10];
    printf("%d",sizeof arr);
 
    return 0;      
}

Output: 80

(e) Array of string
    An array which can hold integer data type is known as array of

integer.

(f) Array of array
    An array which can hold address of another array is known as

array of array.

(g) Array of address of integer
    An array which can hold address integer data type is known as

array of address of integer.


Pointer to array


A pointer which holds base address of an array or address of any

element of an array is known as pointer to array. For example:

(a)

#include<stdio.h>
int main(){
    int arr[5]={100,200,300};
    int *ptr1=arr;
    char *ptr2=(char *)arr;
    printf("%d   %d",*(ptr1+2),*(ptr2+4));

       return 0;    
}
Output: 300   44

(b)

#include<stdio.h>
int main(){
    static int a=11,b=22,c=33;
    int * arr[5]={&a,&b,&c};
    int const * const *ptr=&arr[1];
    --ptr;
    printf("%d ",**ptr);
        return 0;      
}

Output: 11

Jazbaa Full Movie (2015) Hindi Movie DVDScr

                                Poster Of Hindi Movie Jazbaa (2015) Free Download Full New Hindi Movie Watch Online At worldfree4u.com
Ratings: 5.6/10
Genre(s): Thriller
Directed By: Sanjay Gupta
Released On: 9 October 2015

Synopsis: Aishwarya Rai Bachchan is the main protagonist. She will essay the role of a lawyer. Irrfan Khan cast in a role of a suspended cop while Shabana Azmi will be playing the role of a mother. Chandan Roy Sanyal plays the main antagonist in the film. Siddhanth Kapoor will be essaying the role of a troubled individual undergoing psychiatric treatment.Jazbaa 2015 Full Movie Download DVDScr 700MB


      Resumable Single Download Link For Hindi Film Jazbaa (2015) Watch Online Download High Quality
Screen Shot Of Hindi Movie Jazbaa (2015) Download And Watch Online Free at worldfree4u.com
Resumable Mediafire Download Link For Hindi Film Jazbaa (2015) Watch Online Download
Watch Online Full Hindi Movie Jazbaa (2015) On Putlocker Blu Ray Rip
             
                                                          ||Download Movie Via Single Resumable 698MB Links||
          
  

Core Java with OCJP_SCJP Language Fundamentals Part-2 __ Data Types part-1

Java with Govind  
   

Datatypes

In java every variable has a type, every expression has a type and all types are strictly defined.All the assignments should be checked by the compiler for the type compatibility. Hence java language
considers as strongly typed language.Java is not considered as pure object oriented programming
language because several OOP features(like multiple inheritance, operator overloading) are not supported by java. Even java contains non-object primitive datatypes.

Except boolean and char all the remaining datatypes are signed datatypes i.e we can represent both +ve and –ve numbers.

byte

              Size :  8-bits
             Range:  -128 to 127
-ve numbers can represented in 2’s compliment form.
   Ex:
         byte b = 10;
         byte b = 127;

         byte b = 130; --->  C.E: possible loss of precision

      byte b = true;  ----> C.E: Incompatible types found: boolean
                                                                  required: byte
byte datatype is best suitable if we are handling data either from file or form network.

short


     
Ex:
        short s = 10;
        short s = 32767;
        short s = 65535;---> C.E: possible loss of precision.
        short s = true;   ---->  C.E: Incompatible types
 short is best suitable datatype for 16 -bit process. But currently these are completely  out dated and hence the corresponding datatypes also no one is using.

int

      The most commonly used datatype is int. 
       size = 4 bytes

The size of int is always fixed irrespective of platform hence the chance of failing java program is
very less if u r changing the platform hence the java is considered as Robust.

Core Java with OCJP_SCJP Language Fundamentals Part- 3 __ Data Types part-II


long

       if int is not enough to hold big values then we should go for long-datatype
     


Ex:
The amount of distance traveled by light in 1000days can be represented by long
datatype only and int is not enough.

floating -point


           for representing real numbers(numbers with decimal points)


boolean datatye

         size = not a pplicable(virtual machine dependent).

         range = not applicable but allowed values are true/false

Ex:

int x = 0;
if(x)
{
System.out.println("Hello");
}
else
{
System.out.println("Hai");
}
C.E: Incompatible types found :int
required: boolean.

char


Comparison table for java primitive datatypes








Core Java with OCJP_SCJP Language Fundamentals Part-1 __ Java Identifiers and Reserved Words


What is Java?

Java is:
  • Object Oriented
  • Platform independent:
  • Simple
  • Secure
  • Architectural- neutral
  • Portable
  • Robust
  • Multi-threaded
  • Interpreted
  • High Performance
  • Distributed
  • Dynamic

Java Environment Setup:

Java SE is freely available from the link Download Java. So you download a version based on your operating system.
You can refer to installation guide for a complete detail.

Java Basic Syntax:

  • Object - Objects have states and behaviors. Example: A dog has states-color, name, breed as well as behaviors -wagging, barking, eating. An object is an instance of a class.
  • Class - A class can be defined as a template/ blue print that describe the behaviors/states that object of its type support.
  • Methods - A method is basically a behavior. A class can contain many methods. It is in methods where the logics are written, data is manipulated and all the actions are executed.
  • Instant Variables - Each object has its unique set of instant variables. An object's state is created by the values assigned to these instant variables.

First Java Program:

Let us look at a simple code that would print the words Hello World.
public class MyFirstJavaProgram{

   /* This is my first java program.  
    * This will print 'Hello World' as the output
    */

    public static void main(String []args){
       System.out.println("Hello World"); // prints Hello World
    }
} 
About Java programs, it is very important to keep in mind the following points.
  • Case Sensitivity - Java is case sensitive which means identifier Helloand hello would have different meaning in Java.
  • Class Names - For all class names the first letter should be in Upper Case.

    If several words are used to form a name of the class each inner words first letter should be in Upper Case.

    Example class MyFirstJavaClass
  • Method Names - All method names should start with a Lower Case letter.

    If several words are used to form the name of the method, then each inner word's first letter should be in Upper Case.

    Example public void myMethodName()
  • Program File Name - Name of the program file should exactly match the class name.

    When saving the file you should save it using the class name (Remember java is case sensitive) and append '.java' to the end of the name. (if the file name and the class name do not match your program will not compile).

    Example : Assume 'MyFirstJavaProgram' is the class name. Then the file should be saved as 'MyFirstJavaProgram.java'
  • public static void main(String args[]) - java program processing starts from the main() method which is a mandatory part of every java program..

Java Identifiers:

All Java components require names. Names used for classes, variables and methods are called identifiers.
In java there are several points to remember about identifiers. They are as follows:
  • All identifiers should begin with a letter (A to Z or a to z ), currency character ($) or an underscore (_).
  • After the first character identifiers can have any combination of characters.
  • A key word cannot be used as an identifier.
  • Most importantly identifiers are case sensitive.
  • Examples of legal identifiers:age, $salary, _value, __1_value
  • Examples of illegal identifiers : 123abc, -salary

Java Modifiers:

Like other languages, it is possible to modify classes, methods, etc., by using modifiers. There are two categories of modifiers.
  • Access Modifiers : default, public , protected, private
  • Non-access Modifiers : final, abstract, strictfp
We will be looking into more details about modifiers in the next section.

Java Variables:

We would see following type of variables in Java:
  • Local Variables
  • Class Variables (Static Variables)
  • Instance Variables (Non static variables)

Java Arrays:

Arrays are objects that store multiple variables of the same type. However an Array itself is an object on the heap. We will look into how to declare, construct and initialize in the upcoming chapters.

Java Enums:

Enums were introduced in Java 5.0. Enums restrict a variable to have one of only a few predefined values. The values in this enumerated list are called enums.
With the use of enums it is possible to reduce the number of bugs in your code.
For example if we consider an application for a fresh juice shop it would be possible to restrict the glass size to small, medium and Large. This would make sure that it would not allow anyone to order any size other than the small, medium or large.

Example:

class FreshJuice{

   enum FreshJuiceSize{ SMALL, MEDIUM, LARGE }
   FreshJuiceSize size;
}

public class FreshJuiceTest{

   public static void main(String args[]){
      FreshJuice juice = new FreshJuice();
      juice.size = FreshJuice. FreshJuiceSize.MEDIUM ;
      System.out.println("Size :" + juice.size);
   }
}
Note: enums can be declared as their own or inside a class. Methods, variables, constructors can be defined inside enums as well.

Java Keywords:

The following list shows the reserved words in Java. These reserved words may not be used as constant or variable or any other identifier names.
abstractassertbooleanbreak
bytecasecatchchar
classconstcontinuedefault
dodoubleelseenum
extendsfinalfinallyfloat
forgotoifimplements
importinstanceofintinterface
longnativenewpackage
privateprotectedpublicreturn
shortstaticstrictfpsuper
switchsynchronizedthisthrow
throwstransienttryvoid
volatilewhile

Comments in Java

Java supports single line and multi-line comments very similar to c and c++. All characters available inside any comment are ignored by Java compiler.
public class MyFirstJavaProgram{

   /* This is my first java program.
    * This will print 'Hello World' as the output
    * This is an example of multi-line comments.
    */

    public static void main(String []args){
       // This is an example of single line comment
       /* This is also an example of single line comment. */
       System.out.println("Hello World"); 
    }
}