CORE Java Practical Journal
CORE Java Practical Journal
CORE Java Practical Journal
CERTIFICATE
INDEX
SR.
AIM DATE SIGN REMARKS
NO.
1 Practical 1
2 Practical 2
3 Practical 3
4 Practical 4
5 Practical 5
6 Practical 6
7 Practical 7
8 Practical 8
PRACTICAL: - 1
A] Write a Java program that takes a number as input and prints its
multiplication table up to 10.
import java.util.Scanner;
num1 = in.nextInt();
* (i+1)));
Output :-
B] Write a java program to display the following pattern.
*****
****
***
**
Output:-
C]
Write a
java
program
to print
the area
and
perimeter of a circle.
class Test2
double PI=3.14;
Output:-
PRACTICAL: - 2
A] Write a java program to convert decimal number into binary and vice versa.
import java.util.*;
class test2
d=in.nextInt();
System.out.println("Binary no of "+d+"is");
System.out.println(Integer.toBinaryString(d));
System.out.println("Enter binary no"); String
b=in.next(); System.out.println("decimal no
of"+d+"is");
System.out.println(Integer.parseInt(b,2));
OUTPUT:-
class test3
String name="SYIT";
int l=name.length();
String rev="";
for(int i=l-1;i>=0;i--)
rev=rev+name.charAt(i);
}
System.out.println("Reverse of "+name+"is "+rev);
Output:-
PRACTICAL: - 3
A] Write a java program to implement method overriding: class
Vehicle
{
void run()
{
System.out.println("Vehicle is running");
}
}
B]
B]
B]
B]
B]
B]
B]
B]
Write a java program to implement single level inheritance.
class Employee
{
float salary=40000;
}
Output:-
C] Write a java program to implement multiple inheritance:
interface Printable
{
void print();
}
interface Showable
{
void show();
}
Output:-
PRACTICAL: - 5
A. Create a package, add the necessary classes and import the package in
java class.
\\PACKAGE :
package mypack;
public class a
{
public void display()
{
System.out.println("SYIT");
}
}
\\CLASS:
import mypack.*;
class pack
{
Public static void main(String args[])
{
a x= new a();
x.display();
}
}
Output:
B. Write a java program to add two matrices and print the resultant matrix.
import java.util.Scanner; class
AddTwoMatrix
{
public static void main(String args[])
{
int m, n, c, d;
Scanner in = new Scanner(System.in); System.out.println("Enter the number of
rows and columns of matrix");
m = in.nextInt(); n =
in.nextInt();
int first[][] = new int[m][n];
int second[][] = new int[m][n];
int sum[][] = new int[m][n];
System.out.println("Enter the elements of first matrix"); for ( c = 0 ; c <
m ; c++ )
for ( d = 0 ; d < n ; d++ ) first[c]
[d] = in.nextInt();
System.out.println("Enter the elements of second matrix"); for ( c = 0 ; c <
m ; c++ )
for ( d = 0 ; d < n ; d++ ) second[c]
[d] = in.nextInt(); for ( c = 0 ; c <
m ; c++ ) for ( d = 0 ; d < n ; d++ )
sum[c][d] = first[c][d] + second[c][d]; System.out.println("Sum
of entered matrices:-"); for ( c = 0 ; c < m ; c++ )
{
for ( d = 0 ; d < n ; d++ )
System.out.print(sum[c][d]+"\t");
System.out.println();
}
}
}
Output:
PRACTICAL :- 6
A) Write a java program to implement the vectors. import
java.util.Iterator;
import java.util.Vector;
public class SimpleVectorExample
{
public static void main(String[] args)
{
//create a Vector object Vector
v = new Vector(); v.add("1");
v.add("2");
v.add("3");
System.out.println("Getting elements of Vector");
System.out.println(v.get(0)); System.out.println(v.get(1));
System.out.println(v.get(2));
}
}
OUTPUT:-
B. Write
a java
program
to
OUTPUT:-
C. Write
a java
program
to
implement multithreading.
OUTPUT:-
PRACTICAL-7
A. Write a Java program to count the letters, spaces, numbers and other
characters of an input string.
import java.util.Scanner;
public class Exercise38
count(test);
letter = 0;
int space = 0;
int num = 0;
int other = 0;
if(Character.isLetter(ch[i]))
letter ++ ;
else if(Character.isDigit(ch[i]))
{
num ++ ;
else if(Character.isSpaceChar(ch[i]))
{
space ++ ;
else
other ++;
OUTPUT:
B. Implement a Java function that calculates the sum of digits for a given char array
consisting of the digits '0' to '9'. The function should return the digit sum as a long
value.
import java.util.Scanner;
{
Scanner sc = new Scanner(System.in);
sc.nextInt();
int sum = 0;
while (input != 0)
sum += lastdigit;
input /= 10;
}}
OUTPUT:
int a[] = new int[] { 23, 34, 13, 64, 72, 90, 10, 15, 9, 27 };
int min = a[0]; // assume first elements as smallest number int max =
max = a[i];
{ min = a[i];
}}
OUTPUT:
PRACTICAL NO: - 8
A) Write a java program to open a file and display the contents in the console
window.
import java.io.*;
{
FileInputStream fin=new FileInputStream("E:\\PRACT8\\a.txt"); int i=0;
while((i=fin.read())!=-1)
System.out.print((char)i);
fin.close();
Output:
B) Write a java program to copy the contents from one file to other file. import
java.io.*;
public class B
while((c=fin.read())!=-1)
fout.write(c);
System.out.print((char)c);
fout.close();
fin.close();
OUTPUT:-
C) Write a java program to read the student data from user and store it in the file.
import java.io.*;
import java.util.*;
public class C
f.write("\n");
f.write("student name"+studName);
f.write("\n");
f.write("student marks:"+studMarks);
scan.close();
f.close();
}}
Output:-