Posts

Showing posts from August, 2020

Operations on Data and Java Library

Image
  Operations on Data 1) (byte, short, int, char) + (byte, short, int, char) => int 2) (byte, short, int, long, char) + long => long 3) (byte, short, int, long, float, char) + float => float 4) (byte, short, int, long, float, double, char) + double => double Note: Operations cannot be performed on boolean types.  Java Library Java library organised in the form of packages. A package is a collection of sub packages, classes & interfaces. java.lang package is a default package and it is implicitly imported in every java program. Java Notations: 1) Package & Sub Package: All small letters and sub packages are separated with dot(.) symbol. 2) Class & Interface: Each word first letter is capital and no space between words. 3) Variable & Method: Second word on wards first letter is capital and no space between words. Interface in Java An  interface in Java  is a blueprint of a class. It has static constants and abstract methods. The interface in Java is  a mec

Assignment-1(core java)

  If we compile and run the following code snippets, what will be happen? 1) int true =10;                          System.out.println(true); 2) int True=20;     System.out.println(True); 3) byte a=10;      short b=a;      System.out.println(b); 4)short a=10;      byte b=a;      System.out.println(b); 5)short a=10;      byte b=(byte)a;      System.out.println(b); 6) char a='A';      int b=a;  System.out.println(b); 7)char a='A';     int b=(int)a;  System.out.println(b); 8)int a=67;  char b=a;  System.out.println(b); 9)int a=78; char b=(char)a;  System.out.println(b); 10)char Char="A";  System.out.println(Char); 11)boolean a=true; boolean b=false; boolean c=a+b; System.out.println(c); 12)double a=3.5; int b=3; float c=(float)a+b; System.out.println(c); 13) float a=3.5f; char b= 'a'; int c=(int)(a+b); System.out.println(c); 14)char a='A'; short b=5; char c=(char)(a+b); System.out.println(c);

Type Conversions

  Data Types Primitive Data Types: 1) byte  2) short  3) int 4) long  5) float  6) double 7) char 8) boolean Type Conversions:- Conversion one type to another type is called type conversions. types of conversion are divided in to two types 1. Widening or Automatic Type Conversion  ( Implicitly) 2. Narrowing Type Conversion   ( Explicitly ) over all 56 conversions (8*7=56) boolean type cannot be converted to other types and other types cannot be converted to boolean type.=14(not Possible) Widening or Implicitly Type Conversions:- The following 19 conversions are done by system implicitly: byte to short, int, long, float, double   => 5 short to int, long, float, double            => 4 int to long, float, double                       => 3 long to float, double                              => 2 float to double                                       => 1 char to int, long, float, double             => 4                             

Operators in Java

  Operators in Java Arithmetic Operators Unary Operators Relational Operators  Logical Operators  Ternary operator  Bitwise Operators  Arithmetic Operators:- They are used to perform simple arithmetic operations on primitive data types. * : Multiplication / : Division % : Modulo + : Addition – : Subtraction Unary Operators:- Unary operators need only one operand. They are used to increment, decrement or negate a value. – :Unary minus , used for negating the values. + :Unary plus , used for giving positive values. Only used when deliberately converting a negative value to positive. ++ :Increment operator , used for incrementing the value by 1. There are two varieties of increment operator. Post-Increment : Value is first used for computing the result and then incremented. Pre-Increment : Value is incremented first and then result is computed. — : Decrement operator , used for decrementing the value by 1. There are two varieties of decrement operator. Post-decrement : Value is first used

Java Tokens

Image
Java Tokens A token is the smallest element of a program that is meaningful to the compiler. Tokens can be classified as follows: Identifiers Keywords Literals/Constants Data Types Operators     1.Identifiers:- Identifier is a word and it is used to identify variable, method,class, interface, package, .. etc., It can be a variable name, method name, class name, interface name, package name, .. etc., Rules to declare an identifier: 1) It can be formed by using alphabets(A to Z & a to z), digits (0 to 9), underscore symbol(_) and dollar symbol($). 2) It must begins with alphabet, underscore & dollar symbol. 3) The length of the identifier is not limited. 4) It should not contain special symbols other than underscore symbol or dollar symbol. 5) It should not contain whitespace characters(Space bar, tab & enter keys).   2 . Keywords:- A set of words reserved by language itself and those words are called keywords.There are 50 keywords at present in Java language including strict