You are on page 1of 9

PART A

(PART A : TO BE REFFERED BY STUDENTS)


Experiment No. 01
Aim : Write a program to input your roll no, name, age, fees paid, sex from keyboard and
print them.(Use of Scanner class and BufferedReader class)
Objective : To make the students aware of different primitive data types and there use in
real world .
Outcome :
1. Students have come to know the different type of primitive data types of java.
They have learned how to make use of these in real world scenario.
2. Students are exposed to reading of input data from consol.
Theory:
Data Types in Java
In java, there are two types of data types
• Primitive data types
• Non-primitive data types

Data Type Default Value Default size


Boolean False 1 bit
Char '\u0000' 2 byte
Byte 0 1 byte
Short 0 2 byte
Int 0 4 byte
Long 0L 8 byte
Float 0.0f 4 byte
Double 0.0d 8 byte
Java uses Unicode system rather than ASCII code system. \u0000 is the lowest range of
Unicode system.
Algorithm:

1. Start
2. Create object of BufferedReader class.
3. int a=(Integer.parseInt)br.readLine().
4. float b=(Float.parseFloat)br.readLine();
5. double c=(Double.parseDouble) br.readLine();
6. String d= br.readLine();
7. Display a,b,c,d
8. Create object of Scanner class
9. int p=sc.nextInt()
10. float q=sc.nextFloat()
11. double r=sc.nextDouble()
12. String s=sc.nextLine()
13. Display p,q,r,s
14. Stop
PART B
(PART B : TO BE COMPLETED BY STUDENTS)

(Students must submit the soft copy as per following segments within two hours of the
practical. The soft copy must be uploaded at the end of the practical)

Roll. No. C28 Name: Prathmesh Krishna Gaikwad


Class: SE-C Batch: B-1
Date of Experiment: 25/10/2021 Date of Submission: 01/11/2021
Experiment No.: 01 Grade:
B.1 Software Code written by student:
import java.util.*;
import java.io.*;
class Info
{
public static void main(String args[]) throws IOException
{ //BufferedReader class
InputStreamReader A = new InputStreamReader(System.in);
BufferedReader B = new BufferedReader(A);
System.out.println("Enter the Roll No.=");
int rollno = Integer.parseInt(B.readLine());
System.out.println("Enter the Name=");
String name = B.readLine();
System.out.println("Enter the Age=");
int age = Integer.parseInt(B.readLine());
System.out.println("Enter the paid fees=");
double feespaid = Double.parseDouble(B.readLine());
System.out.println("Enter the Gender (M/F)=");
char gender = (char)B.read();

System.out.println();
System.out.println("Roll No.="+rollno);
System.out.println("Name="+name);
System.out.println("Age="+age);
System.out.println("Fees Paid="+feespaid);
System.out.println("Gender="+gender);
System.out.println();
//Scanner Class
Scanner s=new Scanner(System.in);
System.out.print("Enter the Roll No= ");
int a=s.nextInt();
System.out.print("Enter the Name= ");
String b=s.next();
System.out.print("Enter the Age= ");
int c=s.nextInt();
System.out.print("Enter the Fees paid= ");
double d=s.nextDouble();
System.out.print("Gender (M/F)= ");
String e=s.next();
System.out.println();
System.out.println("Roll No.= "+a);
System.out.println("Name= "+b);
System.out.println("Age= "+c);
System.out.println("Fees Paid= "+d);
System.out.println("Gender= "+e);
}
}
B.2 Input and Output:

B.3 Observations and learning:


A)There are various types of datatypes in Java; and each can be read via
the BufferedReader class or the Scanner class.
B)The BufferedReader class constructor, however, requires an
InputStreamReader object as parameter.
C)The BufferedReader Class also cannot parse the Input on its own and
only reads the input stream line by line, returning what it reads as a string.
D)The BufferedReader Class may throw an exception, hence the main
function needs the keyword throws Exception.
E)You need some special Wrapper classes to Parse the input.
F)The Scanner classs can parse tokens on its own, not requiring Type
conversion using Wrapper classes.
G)The Scanner class, when used after the BufferedReader Class, needs the
BufferredReader Object as argument.
H)Using specialized functions for parsing using Scanner object does not
consume a newline character, however, and hence must be accounted for.
B.4 Conclusion:
A)One must use the BufferedReader class if you want to only read the
Input Stream or file line by line. It is much faster than the Scanner class.
B)Scanner classs is slower, but it can actually parse tokens. But parsing
unique tokens leaves a trailing newline in the input

B.5 Question of Curiosity


1. Which of these occupy first 0 to 127 in Unicode character set used for characters in
Java?

Code Decimal Octal Description Abbreviation/Key

U+0000 0 000 Null character NUL

U+0001 1 001 Start of Heading SOH / Ctrl-A

U+0002 2 002 Start of Text STX / Ctrl-B

U+0003 3 003 End-of-text character ETX / Ctrl-C1

U+0004 4 004 End-of-transmission character EOT / Ctrl-D2

U+0005 5 005 Enquiry character ENQ / Ctrl-E

U+0006 6 006 Acknowledge character ACK / Ctrl-F

U+0007 7 007 Bell character BEL / Ctrl-G3

U+0008 8 010 Backspace BS / Ctrl-H

U+0009 9 011 Horizontal tab HT / Ctrl-I

U+000A 10 012 Line feed LF / Ctrl-J4

U+000B 11 013 Vertical tab VT / Ctrl-K

U+000C 12 014 Form feed FF / Ctrl-L

U+000D 13 015 Carriage return CR / Ctrl-M5


U+000E 14 016 Shift Out SO / Ctrl-N

U+000F 15 017 Shift In SI / Ctrl-O6

U+0010 16 020 Data Link Escape DLE / Ctrl-P

U+0011 17 021 Device Control 1 DC1 / Ctrl-Q7

U+0012 18 022 Device Control 2 DC2 / Ctrl-R

U+0013 19 023 Device Control 3 DC3 / Ctrl-S8

U+0014 20 024 Device Control 4 DC4 / Ctrl-T

U+0015 21 025 Negative-acknowledge character NAK / Ctrl-U9

U+0016 22 026 Synchronous Idle SYN / Ctrl-V

U+0017 23 027 End of Transmission Block ETB / Ctrl-W

U+0018 24 030 Cancel character CAN / Ctrl-X10

U+0019 25 031 End of Medium EM / Ctrl-Y

U+001A 26 032 Substitute character SUB / Ctrl-Z11

U+001B 27 033 Escape character ESC

U+001C 28 034 File Separator FS

U+001D 29 035 Group Separator GS

U+001E 30 036 Record Separator RS

U+001F 31 037 Unit Separator US

U+007F 127 0177 Delete DEL


2. What are the default or implicitly assigned values for data types in java?
Data Type Default Value
byte 0
short 0
int 0
long 0l
float 0.0f
double 0.0d
char ‘\u0000’
string Null
boolean False

3. What is casting?
Ans -In Java, type casting is a method or process that converts a data type into another
data type in both ways : manually and automatically. The automatic conversion is done
by the compiler and manual conversion performed by the programmer.

4. What is difference between Scanner and BufferReader Class in Java?


Ans –
A)The BufferedReader class reads the input line by line and only returns a string. This
cannot be parsed automatically into different datatypes.
B)The Scanner class allows you to do that, but the special functions for parsing tokens
do not consume a trailing newline.

5. What is the difference between Data Type and Data Structure?


Ans- A data type is the most basic and the most common classification of data. Basically
data type is a type of information transmitted between the programmer and the
compiler where the programmer informs the compiler about what type of data is to be
stored and also tells how much space it requires in the memory.

A data structure is a collection of different forms and different types of data that
has a set of specific operations that can be performed. It is a collection of data types. It
is a way of organizing the items in terms of memory, and also the way of accessing each
item through some defined logic.

You might also like