Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Java Programming notes 1, Summaries of Java Programming

Short definitions of basics of java . keywords ,datatypes etc

Typology: Summaries

2021/2022

Available from 06/23/2022

sanskriti-shrivastava-1
sanskriti-shrivastava-1 🇮🇳

1 document

1 / 10

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Java Programming Assignment 2
-Sanskriti Krishna Shrivastava
4th June 2022
1.What is the difference between float
and double?
Float Double
This is generally
used for graphic
based libraries for
making the
processing power of
your programs
faster, as it is
simpler to manage
by compilers.
This is the most
commonly used data
type in programming
languages for
assigning values
having a real or
decimal based
number within, such
as 3.14 f
It has single
precision.
It has the double
precision or you can
say two times more
precision than float.
According to IEEE, it
has a 32-bit floating
point precision.
According to IEEE, it
has a 64-bit floating
point precision.
Float takes 4 bytes
for storage.
Double takes 8 bytes
for storage.
A value having a
range within 1.2E-38
to 3.4E+38 can be
assigned to float
A value having range
within 2.3E-308 to
1.7E+308 can be
assigned to double
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Java Programming notes 1 and more Summaries Java Programming in PDF only on Docsity!

Java Programming Assignment 2

-Sanskriti Krishna Shrivastava 4 th June 2022

1.What is the difference between float

and double?

Float Double

This is generally

used for graphic

based libraries for

making the

processing power of

your programs

faster, as it is

simpler to manage

by compilers.

This is the most

commonly used data

type in programming

languages for

assigning values

having a real or

decimal based

number within, such

as 3.14 f

It has single

precision.

It has the double

precision or you can

say two times more

precision than float.

According to IEEE, it

has a 32-bit floating

point precision.

According to IEEE, it

has a 64-bit floating

point precision.

Float takes 4 bytes

for storage.

Double takes 8 bytes

for storage.

A value having a

range within 1.2E-

to 3.4E+38 can be

assigned to float

A value having range

within 2.3E-308 to

1.7E+308 can be

assigned to double

variables. type variables

Has a precision of 6

decimal places.

Has a precision of 15

decimal places.

2.WAP to input two numbers and

print their addition.

class Main {

public static void main(String[] args) {

System.out.println("Enter two numbers");

int first = 10;

int second = 20;

System.out.println(first + " " + second);

// add two numbers

int sum = first + second;

System.out.println("The sum is: " + sum);

public class FindProduct{

public static void main(String args[])

int num1=12,num2=15;

int mul=num1*num

System.out.println("Product of

"+num1+" and "+num2+":"+mul);

5) WAP to input a number and

print it's square.

import java.util.Scanner;

* @author H2O

public class Code4Example {

* @param args the command line

arguments

public static void main(String[]

args) {

int num, square;

Scanner keyboard = new

Scanner(System.in);

System.out.print("Enter a

number to calculate square=");

num = keyboard.nextInt();

square = num * num;

System.out.print("Square = " +

square);

_____________________________________

_____________

storage. 8 Compilers more often take a large amount of time for analyzing the source code. In comparison, Interpreters take less time for analyzing the source code. 9 C, C++, C#, etc are programming languages that are compiler based. Python, Ruby, Perl, SNOBOL, MATLAB, etc are programming languages that are interpreter based. **1 0

  1. Which one is better? Compiler or interpreter?**

- The main advantage is that the code produced by a compiler works faster than the code generated by an interpreter. Compiler produces optimized code for a given processor and this code usually consumes far less resources than the code of an interpreter. 3) What are the different data types in java? - Object Program Compiler Source ptogram program^ Source^ Intermediate code Interpreter

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 4) What are the different keywords in java?

- Here is a list of keywords in the Java programming language. You cannot use any of the following as identifiers in your programs. The keywords const and goto are reserved, even though they are not currently used. true, false, and null might seem like keywords, but they are actually literals; you cannot use them as identifiers in your programs. Abstract continuefor new switch assert*** default goto* package synchronized boolean do if private this break double implements protected throw

For many hardware and software platforms, JVMs are available (i.e. JVM depends on the platform). JVM is the Java Virtual Machine – it actually executes Java ByteCode. JRE is the Java Runtime Environment – it contains a JVM, among other things, and is what you need to run a Java program. JDK is the Java Development Kit – it is the JRE, but with javac (which is what you need to compile Java source code) and has other programming tools added.