Javarecord
Javarecord
1. Platform Independent: Compiler converts source code to bytecode and then the
JVM executes the bytecode generated by the compiler. This bytecode can run on any
platform be it Windows, Linux, or macOS which means if we compile a program on
Windows, then we can run it on Linux and vice versa. Each operating system has a
different JVM, but the output produced by all the OS is the same after the execution of
the bytecode. That is why we call java a platform-independent language.
• Abstraction
• Encapsulation
• Inheritance
• Polymorphism
3. Simple: Java is one of the simple languages as it does not have complex features
like pointers, operator overloading, multiple inheritances, and Explicit memory
allocation.
4. Robust: Java language is robust which means reliable. It is developed in such a way
that it puts a lot of effort into checking errors as early as possible, that is why the java
compiler is able to detect even those errors that are not easy to detect by another
programming language. The main features of java that make it robust are garbage
collection, Exception Handling, and memory allocation.
6. Portable: As we know, java code written on one machine can be run on another
machine. The platform-independent feature of java in which its platform-independent
bytecode can be taken to any platform for execution makes java portable.
Before learning Java, one must be familiar with these common terms of Java.
1. Java Virtual Machine (JVM): This is generally referred to as JVM. There are three
execution phases of a program. They are written, compile and run the program.
// addition operator
System.out.println("a + b = " + (a + b));
// subtraction operator
System.out.println("a - b = " + (a - b));
// multiplication operator
System.out.println("a * b = " + (a * b));
// division operator
System.out.println("a / b = " + (a / b));
// modulo operator
System.out.println("a % b = " + (a % b));
}
}
Ex-05 Program for Increment operator
System.out.println("a =”+a);
System.out.println("b =”+b);
System.out.println("a + b = " + (++a));
System.out.println("a - b = " + (++b));
System.out.println("a++=” +a++);
System.out.println("b++=” +b++);
System.out.println("a =”+a);
}
}
}
}
Ex-07 Java program to swap two number using Bitwise Operator
Import java.util.Scanner;
public class SwapTwoNumbersExample1
{
public static void main(String args[])
{
int a, b;
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the first number: ");
a = scanner.nextInt();
System.out.print("Enter the second number: ");
b = scanner.nextInt();
System.out.println("Before swapping:");
System.out.println("a = " +a +", b = " +b);
a = a ^ b;
b = a ^ b;
a = a ^ b;
System.out.println("After swapping:");
System.out.println("a = " +a +", b = " +b);
}
}
Ex-08 Java program to find smallest of three number using Ternary Operator
import java.util.Scanner;
public class SmallestNumberExample5
{
public static void main(String args[])
{
int num1, num2, num3;
System.out.println("Enter three integers: ");
Scanner in = new Scanner(System.in);
num1=in.nextInt();
num2=in.nextInt();
num3=in.nextInt();
if (num1 < num2 && num1 < num3)
System.out.println("The smallest number is: "+num1);
else if (num2 < num1 && num2 < num3)
System.out.println("The smallest number is: "+num2);
else if (num3 < num1 && num3 < num2)
System.out.println("The smallest number is: "+num3);
else
System.out.println("The numbers are same.");
}
}