Friday, 31 January 2014

FAQS AND INTERVIEW QUESTIONS IN JAVA LINK

Click here to download the pdf
https://drive.google.com/file/d/0B3ILIsWIQ3KsUW5XZEc5UnBjMUk/edit?usp=sharing

password: vnrvjiet

Tuesday, 28 January 2014

List of Programs for OOPS through JAVA Laboratory Record


Week1
a) Write a Java program that prints all real solutions to the quadratic equation ax2 + bx +c = 0.  Read in a, b, c and use the quadratic formula. If the discriminant b2 -4ac is negative, display a  message stating that there are no real solutions.



b) The Fibonacci sequence is defined by the following rule:  The fist two values in the sequence are 1 and 1. Every subsequent value is the sum of the two values preceding it. Write a Java program that uses both recursive and non
recursive functions to print the nth value in the Fibonacci sequence.



Week 2
a) Write a Java program that prompts the user for an integer and then prints out all prime numbers up tothat. integer.



b) Write a Java program to multiply two given matrices.



c) Write a Java Program that reads a line of integers, and then displays each integer, and the sum of all theintegers (Use StringTokenizer class of java.util)



Week 3
a) Write a Java program that checks whether a given string is a palindrome or not.  Ex: MADAM is a palindrome.



b) Write a Java program for sorting a given list of names in ascending order.



c)Write a Java program to make frequency count of words in a given text.



Week 4
a) Write a Java program that reads a file name from the user, then displays information about whether the file exists, whether the file is readable, whether the file is writable, the type of file andthe length of the file in bytes.



b) Write a Java program that reads a file and displays the file on the screen, with a line number before each line.



c) Write a Java program that displays the number of characters, lines and words in a text file.



Week 5
a) Write a Java program that:
i) Implements stack ADT. 

ii) Converts infix expression into Postfix form 
iii) Evaluates the postfix expression


Week 6
a) Develop an applet that displays a simple message.



b) Develop an applet that receives an integer in one text field, and computes its factorial value and returns itin another text field, when the button named “Compute” is clicked.



Week 7
a) Write a Java program that works as a simple calculator. Use a grid layout to arrangebuttons for the digits and for the +, -,*, % operations. Add a text field to display theresult.
Week 8
a) Write a Java program for handling mouse events.
Week 9
a) Write a Java program that creates three threads. First thread displays “Good Morning” every one second,the second thread displays “Hello” every two seconds and the third thread displays “Welcome” everythree seconds.
b) Write a Java program that correctly implements producer consumer problem using the concept of interthread communication.
Week 10
a) Write a program that creates a user interface to perform integer divisions. The userenters two  numbers in the textfields, Num1 and Num2. The division of Num1 andNum2 is displayed in the Result field when the Divide button is clicked. If Num1 orNum2 were not an integer, the program would throw a NumberFormatException. IfNum2 were Zero, the program would throw an ArithmeticException Display theexception in a message dialog box.
Week 11
a) Write a Java program that implements a simple client/server application. The clientsends data to a server. The server receives the data, uses it to roduce a result, andthen sends the result back to the client. The client displays the result on the console.

For ex: The data sent from the client is the radius of a circle, and the result produced by the server is thearea of the circle. (Use java.net)
Week 12
a) Write a java program that simulates a traffic light. The program lets the user select one of three lights :red, yellow, or green. When a radio button is selected, the light isturned on, and only one light can be on at a time No light is on when the programstarts.
b) Write a Java program that allows the user to draw lines, rectangles and ovals.
Week 13
a) Write a java program to create an abstract class named Shape that contains an empty method namednumberOfSides ( ).Provide three classes named Trapezoid, Triangle and Hexagon such that each one of theclasses extends the class Shape. Each one of the classes contains only the method numberOfSides ( ) thatshows the number of sides in the given geometrical figures.
b) Suppose that a table named Table.txt is stored in a text file. The first line in the file is the header, and theremaining lines correspond to rows in the table. The elements are seperated by commas. Write a javaprogram to display the table using JTable
component.
Week 14
a)Write a java program to establish connection to a database and perform DML operations over the data base.
b) Design a form which will submit data to a database.
c) Create a Form to receive data from database


Week 15
a)Write a java program to make use of APIs

Tuesday, 21 January 2014

Matrix Multiplication

import java.util.*;

public class MatrixMul
{
public static void main(String args[])
{
int i,j,k,m,n,x,y;
int a[][] =new int[100][100];
int b[][] =new int[100][100];
int c[][] =new int[100][100];
Scanner in=new Scanner(System.in);
System.out.println("Enter Size of First Matrix");
m=in.nextInt();
n=in.nextInt();
System.out.println("Enter Size of Second Matrix");
x=in.nextInt();
y=in.nextInt();
if(n!=x) 
System.out.println("Matrix Multiplication Not Possible");
else
{
System.out.println("Enter "+(m*n)+" Elements for First Matrix");
for(i=0;i<m;i++)
for(j=0;j<n;j++)
a[i][j]=in.nextInt();

System.out.println("Enter "+(x*y)+" Elements for Second Matrix");
for(i=0;i<x;i++)
for(j=0;j<y;j++)
b[i][j]=in.nextInt();


for(i=0;i<m;i++)
{ 
for(j=0;j<y;j++)
{
c[i][j]=0;
for(k=0;k<x;k++)
c[i][k]+=a[i][k]*b[k][j];
}
}

System.out.println("The Product Matrix is  :");
for(i=0;i<m;i++)
{
for(j=0;j<y;j++)
System.out.print(c[i][j]+"\t");
System.out.println();
}
}
}
}


// This program creates a custom exception type.


class MyException extends Exception
{

private int detail;

MyException(int a)
{
detail = a;
}

public String toString()
{
return "MyException[" + detail + "]";
}
}


class ExceptionDemo
{
static void compute(int a) throws MyException
{
System.out.println("Called compute(" + a + ")");
if(a > 10)
throw new MyException(a);
System.out.println("Normal exit");
}

public static void main(String args[])
{
try
{
compute(1);
compute(20);
}
catch (MyException e)
{
System.out.println("Caught " + e);
}
}
}


// Demonstrate finally.

class FinallyDemo {


// Through an exception out of the method.
static void procA()
{
try {
System.out.println("inside procA");
throw new RuntimeException("demo");
}
finally {
System.out.println("procA's finally");
}
}


// Return from within a try block.
static void procB()
{
try
{
System.out.println("inside procB");
return;
}
finally
{
System.out.println("procB's finally");
}
}

// Execute a try block normally.
static void procC()
{
try
{
System.out.println("inside procC");
}
finally
{
System.out.println("procC's finally");
}
}

public static void main(String args[])
{
procA();
procB();
procC();
}
}


Demonstrate nested try

class MethNestTry {
static void nesttry(int a) {
try { // nested try block
/* If one command-line arg is used,
then a divide-by-zero exception
will be generated by the following code. */
if(a==1) a = a/(a-a); // division by zero
/* If two command-line args are used,
then generate an out-of-bounds exception. */
if(a==2) {
int c[] = { 1 };
c[42] = 99; // generate an out-of-bounds exception
}
} catch(ArrayIndexOutOfBoundsException e) {
System.out.println("Array index out-of-bounds: " + e);
}
}
public static void main(String args[]) {
try {
int a = args.length;
/* If no command-line args are present,
the following statement will generate
a divide-by-zero exception. */
int b = 42 / a;
System.out.println("a = " + a);
nesttry(a);
} catch(ArithmeticException e) {
System.out.println("Divide by 0: " + e);
}
}
}



// This program creates a custom exception type.

class MyException extends Exception {
private int detail;
MyException(int a) {
detail = a;
}
public String toString() {
return "MyException[" + detail + "]";
}
}

class ExceptionDemo {

public static void compute(int a) throws MyException
{
System.out.println("Called compute(" + a + ")");
if(a > 10)
throw new MyException(a);
System.out.println("Normal exit");
}

public static void main(String args[]) {
try {
compute(1);
compute(20);
} catch (MyException e) {
System.out.println("Caught " + e);
}
}
}


// Demonstrate throw.

class ThrowDemo {
static void demoproc() {
try {
throw new NullPointerException("demo");
} catch(NullPointerException e) {
System.out.println("Caught inside demoproc.");
throw e; // rethrow the exception
}
}
public static void main(String args[]) {
try {
demoproc();
} catch(NullPointerException e) {
System.out.println("Recaught: " + e);
}
}
}



Demonstrate Throws.

class ThrowsDemo {
static void throwOne() throws IllegalAccessException {
System.out.println("Inside throwOne.");
throw new IllegalAccessException("demo");
}
public static void main(String args[]) {
try {
throwOne();
} catch (IllegalAccessException e) {
System.out.println("Caught " + e);
}
}
}