You are on page 1of 15

Department of Information Science and

1
Engineering
Department of Information Science
and Engineering

JAVA AND J2EE LAB


[18IS6DLJVA ]

Faculty : Mrs.Radhika T V
Assistant Professor , Dept of ISE
DSCE

2
Introduction:
• Java is a high-level programming language developed by Sun Microsystems and
released in 1995.

• Java runs on a variety of platforms, such as Windows, Mac OS, and the various
versions of UNIX,

• Syntax is similar to C++, but is strictly an object-oriented programming


language.

• Java is also known for being more strict than C++, meaning variables and
functions must be explicitly defined.

• Java programs are interpreted by the Java Virtual Machine, or JVM, which
runs on multiple platforms
Key Features of Java
• Object Oriented 

• Platform Independent

• Simple 

• Secure 

• Architecture-neutral

• Portable 

• Robust
Example
  /* FileName : "HelloWorld.java". */
class HelloWorld
{
    // Your program begins with a call to main().
    // Prints "Hello, World" to the terminal window.
    public static void main(String args[])
    {
        System.out.println("Hello, World");
    }
}
Steps for Execution
• Create the program by typing it into a text editor and saving it
to a file – HelloWorld.java.

• Compile it by typing “javac HelloWorld.java” in the terminal


window.

• Execute (or run) it by typing “java HelloWorld” in the


terminal window.
Software Requirements
• Windows 7/8/10
• JDK 1.8
• Eclipse 7
Course Outcomes-
JAVA AND J2EE LAB
[18IS6DLJVA ]
CO1 - Write, compile and execute java programs.
CO2- Apply the basic concepts of object oriented
programming in writing java programs.
CO3-Design and use classes, packages and interfaces
CO4-Analyze and implement exception handling, event
handling
CO5-Develop graphical user interface using swings
CO6-Construct web applications using Servlets and JSP
SAMPLE PROGRAMS
Program 1
/*
Here is short example.
*/
class Example1 {
public static void main(String args[]) {
int num;
num = 100;
System.out.println("This is num: " + num);
num = num * 2;
System.out.print("The value of num * 2 is ");
System.out.println(num);
}
}
Output:
When you run this program, you will see the following output:
This is num: 100
The value of num * 2 is 200
Program 2
Program 2:
Write a Program that illustrates the if statement:
/*
Demonstrate the if.
Call this file "IfSample.java".
*/
Output:
class IfSample {
x is less than y
public static void main(String args[]) {
x now equal to y
int x, y;
x now greater than y
x = 10;
y = 20;
if(x < y) System.out.println("x is less than y");
x = x * 2;
if(x == y) System.out.println("x now equal to y");
x = x * 2;
if(x > y) System.out.println("x now greater than y");
// this won't display anything
if(x == y) System.out.println("you won't see this");
}
}
Program 3
Program 3:
Write a Program that illustrates the for loop:
/*
Demonstrate the for loop. Output:
Call this file "ForTest.java". This is x: 0
This is x: 1
*/ This is x: 2
This is x: 3
class ForTest { This is x: 4
public static void main(String args[]) { This is x: 5
This is x: 6
int x; This is x: 7
This is x: 8
for(x = 0; x<10; x = x+1) This is x: 9
System.out.println("This is x: " + x);
}
}
Program 4
Write a Program to illustrate one dimensional Array

class Array {
public static void main(String args[]) {
int month_days[];
month_days = new int[12]; // intmonth_days[] = new int[12];

// int month_days[] = new int[12]; Output:


month_days[0] = 31; April has 30 Days
month_days[1] = 28;
month_days[2] = 31;
month_days[3] = 30;
month_days[4] = 31;
month_days[5] = 30;
month_days[6] = 31;
month_days[7] = 31;
month_days[8] = 30;
month_days[9] = 31;
month_days[10] = 30;
month_days[11] = 31;
System.out.println("April has " + month_days[3] + " days.");
Program 5
Write a Program to demonstrate the basic arithmetic operators.

class BasicMath {
public static void main(String args[]) { Output:
// arithmetic using integers Integer Arithmetic
System.out.println("Integer Arithmetic"); a=2
int a = 1 + 1; b=6
int b = a * 3; c=1
int c = b / 4; d = -1
int d = c - a; e=1
int e = -d; Floating Point Arithmetic
System.out.println("a = " + a); da = 2.0
System.out.println("b = " + b); db = 6.0
System.out.println("c = " + c); dc = 1.5
System.out.println("d = " + d);
System.out.println("e = " + e);
// arithmetic using doubles
System.out.println("\nFloating Point Arithmetic");
double da = 1 + 1;
double db = da * 3;
double dc = db / 4;
Assignment Programs

1. Write a Program to find Factorial of a Number Using


Recursion.
2. Write a Program to check whether a string is Palindrome or
not.
3. Write a Program to Generate Fibonacci Series
4. Write a Program to demonstrate Binary Search Algorithm.

You might also like