EXPERIMENT NO.
-1
AIM: Use Java compiler and eclipse platform to write and execute java program.
Procedure: Open Eclipse and click File > New > Java Project. Step 2: Provide the Project Name
and click on the Finish button. Step 3: In the Package Explorer (left-hand side of the window) select
the project which you have created. Step 4: Right-click on the src folder, select New > Class
Step 1: Open Eclipse and click File > New > Java Project. How to Run Java Program in eclipse.
Step 2: Provide the Project Name and click on the Finish button
Step 3: In the Package Explorer (left-hand side of the window) select the project which you
have created.
10
Step 4: Right-click on the src folder, select New > Class from the submenu. Provide the Class name and
click on Finish button.
Source Code:
class CSE4_nd_Yr
{ public static void main (String
args[])
{
System.out.println("Hello Java");
System.out.println("Welcome to IMS Engineering College");
}
Type your text
} Output:
--------------------------------------------------------------------------------------------------------------------- 2.
11
class Btech
{ public void
aa()
{ int
a=100; a++;
++a;
System.out.println(a);
} public void
bb()
{ int b=200;
int c;
c=b++ + b++; System.out.println(c);
} public static void main(String
args[])
{
Btech obj=new Btech();
obj.aa(); obj.bb(); }}
Output:
---------------------------------------------------------------------------------------------------------------------------
3.
class A {
public void Login()
{ int k=100;
System.out.println(k++);
} public void
Password()
{
String pass="imsec";
System.out.println(pass);
} } class B { public static void
main(String args[])
{
A obj=new A(); obj.Login(); obj.Password();
}
}
12
Output:
13
Experiment-2
AIM:-Creating simple java programs using command line arguments.
Procedure: The java command-line argument is an argument i.e. passed at the time of running the java
program. The arguments passed from the console can be received in the java program and it can be used as
an input. So, it provides a convenient way to check the behavior of the program for the different values. You
can pass N (1,2,3 and so on) numbers of arguments from the command prompt.
Source Code: class
MCA
{
public static void main(String args[])
{
System.out.println("Your first argument is: "+args[0]);
}
} Output:
---------------------------------------------------------------------------------------------------------------------------------
1.
class
abc
{ public static void main(String args[])
{ for(int
i=0;i<args.length;i++)
{ System.out.println(args[i]);
}
}
}
Output:
14
Experiment-3
AIM: Understand OOP concepts and basics of Java programming.
Procedure:
Object-Oriented Programming is a paradigm that provides many concepts, such as inheritance, data binding,
polymorphism, etc.
Object:-
Java Object Any entity that has state and behavior is known as an object. For example, a chair, pen, table,
keyboard, bike, etc. It can be physical or logical.
Class:-
Collection of objects is called class. It is a logical entity. A class can also be defined as a blueprint from which
you can create an individual object. Class doesn't consume any space.
Inheritance:-
When one object acquires all the properties and behaviors of a parent object, it is known as inheritance. It
provides code reusability. It is used to achieve runtime polymorphism.
Polymorphism:-
If one task is performed in different ways, it is known as polymorphism. For example: to convince the
customer differently, to draw something, for example, shape, triangle, rectangle, etc.
In Java, we use method overloading and method overriding to achieve polymorphism.
Abstraction:-
Hiding internal details and showing functionality is known as abstraction. For example phone call, we don't
know the internal processing.
Encapsulation:-
Binding (or wrapping) code and data together into a single unit are known as encapsulation. For example, a
capsule, it is wrapped with different medicines. A java class is the example of encapsulation. Java bean is the
fully encapsulated class because all the data members are private here.
Source Code: class aa
{
15
String name; protected
int roll; public void
aa_method()
{
name="Vikas maurya"; roll=261;
System.out.println(name);
System.out.println(roll);
} } class pp
extends aa
{
int arr[]={100,50,4,2,3};
int i;
public void pp_mehod()
{
roll =1022;
System.out.println(roll); for(i=0; i<arr.length;i++)
{ System.out.println(arr[i]);
}
} } class bb { public static void
main(String args[])
{ aa obj=new aa();
obj.aa_method(); pp
obj2=new pp();
obj2.pp_mehod();
}
} Output:
-----------------------------------------------------------------------------------------------------------------
class student
{
String name ; int
roll_no;
16
public void stu_method(String aa,int r1) {
name=aa; roll_no=r1;
}
} class
method {
public static void main(String args[])
{
int k;
student ss=new student();
ss.name="Vikas maurya"; ss.roll_no=261;
System.out.println(ss.name);
System.out.println(ss.roll_no);
//k=ss.stu_method("ancc" ,10); //System.out.println(k);
ss.stu_method("aaaaa",100);
}}
---------------------------------------------------------------------------------------------------------------------------
Output :
17