[go: up one dir, main page]

0% found this document useful (0 votes)
14 views7 pages

Javarecord

The documents provide examples of Java programs demonstrating different types of operators in Java like arithmetic, increment, relational, bitwise and ternary operators. The programs include the use of basic operations, variables, printing outputs and taking user inputs.

Uploaded by

hawod70567
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views7 pages

Javarecord

The documents provide examples of Java programs demonstrating different types of operators in Java like arithmetic, increment, relational, bitwise and ternary operators. The programs include the use of basic operations, variables, printing outputs and taking user inputs.

Uploaded by

hawod70567
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Ex-01 INTRODUCTION TO JAVA

1. Java is a high-level, object-oriented programming language that was


first released in 1995.
2. Java was developed by James Gosling at Sun Microsystems Inc in the
year 1995
3. Java is platform-independent, which means that code written in Java
can run on any platform that has a Java Virtual Machine (JVM)
installed.
4. Java code is compiled into bytecode, which can then be executed by
the JVM.
5. Java is known for its “write once, run anywhere” philosophy, which
makes it a popular choice for cross-platform development.
6. Java provides automatic memory management through garbage
collection, which makes it easier to write and maintain code.
7. Java has a vast standard library that provides a wide range of tools for
common programming tasks.
8. Java is widely used in enterprise applications, web development, and
Android app development.
9. Java is a strongly typed language, which means that every variable and
expression has a specific type that must be declared before use.
10.Java has a robust exception-handling mechanism that makes it easier
to handle errors and unexpected behaviour in code.
11.Java supports multithreading, which makes it possible to write
programs that can perform multiple tasks simultaneously.
EX-2 FEATURES OF JAVA

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.

2. Object-Oriented Programming Language: Organizing the program in the terms of


a collection of objects is a way of object-oriented programming, each of which
represents an instance of the class. The four main concepts of Object-Oriented
programming are:

• 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.

5. Multithreading: Java supports multithreading. It is a Java feature that allows


concurrent execution of two or more parts of a program for maximum utilization of the
CPU.

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.

7. Write Once Run Anywhere: As discussed above java application generates a


‘.class’ file that corresponds to our applications(program) but contains code in binary
format. It provides ease t architecture-neutral ease as bytecode is not dependent on any
machine architecture. It is the primary reason java is used in the enterprising IT industry
globally worldwide.
EX-3 JAVA TERMINOLOGY

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.

• Writing a program is done by a java programmer like you and me.


• The compilation is done by the JAVAC compiler which is a primary Java
compiler included in the Java development kit (JDK). It takes the Java
program as input and generates bytecode as output.
• In the Running phase of a program, JVM executes the bytecode generated
by the compiler.
Now, we understood that the function of Java Virtual Machine is to execute the
bytecode produced by the compiler. Every Operating System has a different JVM but
the output they produce after the execution of bytecode is the same across all the
operating systems. This is why Java is known as a platform-independent language.
2. Bytecode in the Development Process: As discussed, the Javac compiler of JDK
compiles the java source code into bytecode so that it can be executed by JVM. It is
saved as .class file by the compiler. To view the bytecode, a disassembler like javap can
be used.
3. Java Development Kit (JDK): While we were using the term JDK when we learn
about bytecode and JVM. So, as the name suggests, it is a complete Java development
kit that includes everything including compiler, Java Runtime Environment (JRE), java
debuggers, java docs, etc. For the program to execute in java, we need to install JDK
on our computer in order to create, compile and run the java program.
4. Java Runtime Environment (JRE): JDK includes JRE. JRE installation on our
computers allows the java program to run, however, we cannot compile it. JRE includes
a browser, JVM, applet support, and plugins. For running the java program, a computer
needs JRE.
5. ClassPath: The classpath is the file path where the java runtime and Java compiler
look for .class files to load. By default, JDK provides many libraries. If you want to
include external libraries, they should be added to the classpath.
Ex-04 Program for Arithmetic operator

Public class Arithmeticoperator


{
public static void main(String[] args)
{
// declare variables
int a = 12, b = 5;

// 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

Public class incrementoperator


{
public static void main(String[] args)
{
int a = 20, b = 30;

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-06 Program for Relational Operator

Public class relationaloperator


{
public static void main(String[] args)
{
int a = 25, b = 30, c=40;
System.out.println("a =”+a);
System.out.println("b =”+b);
System.out.println("c =”+c);
System.out.println("a > b = " + (a>b));
System.out.println("a < b = " + (a<b));
System.out.println("a < c = " + (a<c));
System.out.println("a > c = " + (a>c));
System.out.println("a == b =" + (a==b));

}
}
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.");
}
}

You might also like