• Home
  • Courses
  • School
  • Programs
  • Problems
  • Contact Us
  • My account
  • Register

Have any question?

(+91) 98222 16647
info@simplycoding.in
RegisterLogin
Simply Coding
  • Home
  • Courses
  • School
  • Programs
  • Problems
  • Contact Us
  • My account
  • Register

Java

Java Tokens and Data types Practice Questions

  • Categories Java, Tokens & Data Types, Values & Data Types
Java Tokens and Data types Practice Questions

Today we are going to practice short questions on Java  Tokens and Data Types. Before you attempt the questions, do a quick review of these two topics by going through our video links here.

          • Java Tokens
          • Java DataTypes
  1. Identify whether following are primitive or non-primitive types

(i) String  (ii) arrays  (iii) char  (iv) classes

Ans.

(i) String – Non-Primitive

(ii) arrays – Non primitive

(iii) char – Primitive

(iv) Classes – Non primitive

  1. List the variables from those given below that are composite data types.

(i) static int x;

(ii) data[2] = 10;

Ans.

(i) x is of a primitive data type

(ii) data is variable of a composite or non primitive data type

  1. List the variables from those given below that are composite data types.
    1. private char chr;
    2. String str;

Ans.

    1. chr is a variable of a primitive data type
    2. str is a variable of a composite data type – String is a class type
  1. List the variables from those given below that are composite data types.
    1. display();
    2. boolean b;
    3. Scanner sc;
    4. Z = ‘\n’;

Ans.

    1. obj is a variable of a composite data type
    2. b is a variable of a primitive data type
    3. sc is a variable of a composite data type as Scanner is a class
    4. Z is of type char so non primitive type.

 

  1. Arrange the following primitive data types in an ascending order of their size:

(i)         char                                                    (ii)  byte

(iii)       double                                                 (iv)  int

Ans.    byte, char, int, double

  1.      (i) State the number of bytes occupied by char and int data types?

  (ii) Write one difference between / and % operator.

Ans.

(i) char occupies two bytes and  int occupied 4 bytes.

(ii) / is division operator while % is modulus operator which gives the remainder on dividing two numbers.

  1. Write the size of the following integer data types in terms of bytes.
    • int
    • float
    • double
    • char

Ans.

    1. int: 4 bytes
    2. float: 4 bytes
    3. double: 8 bytes
    4. char: 2 bytes
  1. What are the default values of the primitive data type int and float?

Ans. The default value of  int is 0 and float is 0.0F

  1. Identify what is the type of literals listed below:

(i) 0.5 (ii)’A’ (iii) false (iv) “a”

Ans.

(i) Floating point literal
(ii) Character literal, single character in single quotes
(iii) Boolean literal
(iv) String literal, multiple characters in double quotes.

  1. Identify the literals as given below:

i. 246 ii. ‘c’ iii. true     iv. “SimplyCoding”

Ans. i. int    ii. char     iii. boolean    iv. String

  1. What is the range of the following data types:
    1. byte
    2. short
    3. long
    4. boolean

Ans:

    1. byte -> -128 to 127
    2. short -> -32768 to 32767
    3. long -> -263 to 263-1
    4. boolean – > true or false
  1. Identify the literals listed below :
    • 2.5
    • ’s’
    • false
    • ”Simply”

Ans :

    1. Real literal
    2. character literal
    3. boolean literal
    4. String literal
  1. Identify the following as valid variable names, state reason if invalid :
    • 3
    • D253
    • Emp_name
    • Salaryamount#

Ans.

    1. Invalid, dot (.) is not allowed.
    2. Valid
    3. Valid
    4. Invalid, # not allowed
  1. Identify the following as valid variable names, state reason if invalid :
    • S%
    • _A124

Ans.

    1. Invalid, special character (%) not allowed.
    2. Valid _ is allowed
  1. Identify the following as valid variable names, state reason if invalid :
    • _250
    • super
    • ST 106
    • While

Ans.

    1. valid as it begins with (underscore).
    2. Invalid, as super is a keyword.
    3. Invalid, space is not allowed.
    4. Valid, W is capital so it is not a key word.
  1. Identify the following literals as character/string literals:
    • \t
    • Simply coding#?9
    • \26
    • \ r
    • \Simply

Ans.

    1. Character
    2. String
    3. String
    4. Character
    5. String
  1. Which of the following set of values can be assigned to a boolean variable?
    • Yes and No
    • true and false
    • 0 and 1
    • high and low

Ans. b. true and false (variable Boolean can be true or false)

  1. Write java statements for following:
    • Declare double variable.
    • Declare float variable and assign any value to it.
    • Declare Boolean variable and assign value to it.

Ans.

    1. double x;
    2. float a = 3.14;
    3. boolean r = true;
  1. Predict the data type of the following:

i) int p; double q;                            ii) float m;

      r = p + q;                                           p = m/3*(Math.pow(4,3));

     Systems.out.println(r);                  System.out.println(p);

Ans. i) double ii) double

  1. What is the resultant data type of the following mathematical expression?

a+b*c-d

  1. where a is int, b is int, c is float and d is float type
  2. where a, b, c and d are of int type, however the expression is slightly modified as

(a+b*c-d)/7.0

Ans.

    1. float
    2. double
  1. What is the resultant data type of the following mathematical expression?

a+b*c-d

  1. where a is of double and b,c and d are of int type
  2. where a is char and b,c and d are of int type

Ans.

    1. double
    2. int
  1. Identify errors in following statements and correct them:
    1. int number = 3,250;
    2. char ch = “Simply”;

Ans. correct statement:

    1. int number = 3250; // comma not allowed
    2. String ch = “Simply”; // char data type  can have only 1 character
  1. Identify errors in following statements and correct them:
    1. int x/10 = y;
    2. int num = +25;

Ans. correct statement:

    1. int y= x/5;
    2. int num+ = 25;
  • Share:
author avatar
Simply Coding

Previous post

#1 Super Easy Star Hill Java Program
June 3, 2020

Next post

Java print/println exam questions
June 7, 2020

You may also like

Java Tokens
Java Tokens & Data Types
16 June, 2021
Crack Java Math Problems
Forming Math Expressions
13 June, 2020
Java Arrays Exercises
Java Arrays Exercises
11 June, 2020

Leave A Reply Cancel reply

You must be logged in to post a comment.

Categories

  • Uncategorized
  • Programs
    • Python
    • Java
  • Problems
    • Python
    • Java
    • Web Development
      • Internet
    • Emerging Technologies
  • Notes
    • General
    • QBasic
    • MS Access
    • Web Development
      • XML
      • HTML
      • JavaScript
      • Internet
    • Database
    • Logo Programming
    • Scratch
    • Emerging Trends
      • Artificial Intelligence
      • Internet of Things
      • Cloud Computing
      • Machine Learning
    • Computer Fundamentals
      • Computer Networks
      • E-Services
      • Computer Hardware
    • Python
    • Java
  • School
    • ICSE
      • Computers Class 9
        • Java Introduction
        • Tokens & Data Types
        • Java Operators
        • Math Library
        • if & switch
        • For & While
        • Nested loops
      • Computer Class 10
        • Sample Papers
        • OOPS concepts
        • Functions in Java
        • Constructors
        • Arrays in Java
        • Strings in Java
    • SSC
      • IT Class 11
        • IT Basics
        • DBMS
        • Web Designing
        • Cyber Laws
      • IT Class 12
        • Web Designing
        • SEO
        • Advanced JavaScript
        • Emerging Tech
        • Server Side Scripting
        • E-Com & E-Gov
      • Computer Science 11
      • Computer Science 12
    • CBSE
      • Computer 9
        • Basics of IT
        • Cyber Safety
        • Scratch
        • Python
      • Computer 10
        • Sample Papers
        • Networking
        • HTML
        • Cyber Ethics
        • Scratch
        • Python
      • Computer Science 11
        • Computer Systems
        • Python 11
          • Python Basics
          • Python Tokens
          • Python Operators
          • Python if-else
          • Python loops
          • Python Strings
          • Python List
          • Python Tuple
          • Python Dictionary
          • Python Modules
        • Data Management
      • Computer Science 12
        • Sample Papers
        • Python 12
          • Python Functions
          • Python File Handling
          • Python Libraries
          • Python Recursion
          • Data Structures
        • Computer Networks
        • Data Management
    • ISC
      • Computer Science 11
        • Introduction to Java
        • Values & Data Types
        • Operators
        • if & switch
        • Iterative Statements
        • Functions
        • Arrays
        • String
        • Data Structures
        • Cyber Ethics
      • Computer Science 12
        • Sample Papers
        • Boolean Algebra
        • OOPS
        • Wrapper Classes
        • Functions
        • Arrays
        • String

Categories

  • Uncategorized
  • Programs
    • Python
    • Java
  • Problems
    • Python
    • Java
    • Web Development
      • Internet
    • Emerging Technologies
  • Notes
    • General
    • QBasic
    • MS Access
    • Web Development
      • XML
      • HTML
      • JavaScript
      • Internet
    • Database
    • Logo Programming
    • Scratch
    • Emerging Trends
      • Artificial Intelligence
      • Internet of Things
      • Cloud Computing
      • Machine Learning
    • Computer Fundamentals
      • Computer Networks
      • E-Services
      • Computer Hardware
    • Python
    • Java
  • School
    • ICSE
      • Computers Class 9
        • Java Introduction
        • Tokens & Data Types
        • Java Operators
        • Math Library
        • if & switch
        • For & While
        • Nested loops
      • Computer Class 10
        • Sample Papers
        • OOPS concepts
        • Functions in Java
        • Constructors
        • Arrays in Java
        • Strings in Java
    • SSC
      • IT Class 11
        • IT Basics
        • DBMS
        • Web Designing
        • Cyber Laws
      • IT Class 12
        • Web Designing
        • SEO
        • Advanced JavaScript
        • Emerging Tech
        • Server Side Scripting
        • E-Com & E-Gov
      • Computer Science 11
      • Computer Science 12
    • CBSE
      • Computer 9
        • Basics of IT
        • Cyber Safety
        • Scratch
        • Python
      • Computer 10
        • Sample Papers
        • Networking
        • HTML
        • Cyber Ethics
        • Scratch
        • Python
      • Computer Science 11
        • Computer Systems
        • Python 11
          • Python Basics
          • Python Tokens
          • Python Operators
          • Python if-else
          • Python loops
          • Python Strings
          • Python List
          • Python Tuple
          • Python Dictionary
          • Python Modules
        • Data Management
      • Computer Science 12
        • Sample Papers
        • Python 12
          • Python Functions
          • Python File Handling
          • Python Libraries
          • Python Recursion
          • Data Structures
        • Computer Networks
        • Data Management
    • ISC
      • Computer Science 11
        • Introduction to Java
        • Values & Data Types
        • Operators
        • if & switch
        • Iterative Statements
        • Functions
        • Arrays
        • String
        • Data Structures
        • Cyber Ethics
      • Computer Science 12
        • Sample Papers
        • Boolean Algebra
        • OOPS
        • Wrapper Classes
        • Functions
        • Arrays
        • String
Simply Coding Computer Courses for School                Privacy Policy     Terms of Use     Contact Us

© 2021 Simply Coding

Login with your site account

Lost your password?

Not a member yet? Register now

Register a new account

Are you a member? Login now