Proxy > Gmail Facebook Yahoo!

This trick will shutdown a selected pc from Your LAN network. You can apply this trick in your office or school.. but i take no responsibilities fro any action. Its just for fun. Here is how to use this trick :



1. Go to Start > Run and type in cmd

2. You will see the command prompt window . Now type in this command line.

shutdown.exe -i
And hit Enter. You will see remote shutdown Window. If you know someone’s IP on a computer in your Local Area network, type in their IP Address after clicking the add button.

3. After entering the IP Address click OK . Now watch the person’s face as their computer shuts down.
[Read More...]


Automatic Window refresh



Whenever you make a change to your windows you have to press F5 or do a manual refresh sometimes its very annoying Now with this trick you can tell windows to increase the rate at which it does the refreshing.
Just follow given steps:

1) Type Regedit in run.
2) In Registry editor window go toHKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Update.
3) Create a new DWORD value, or modify the existing value, namedUpdateMode and set it to equal 0 for faster updates. Restart Windows for the change to take effect.

Its done.




free glitter text and family website at FamilyLobby.com
[Read More...]


Nokia Codes



IMEI no: : *#06#

Reset to factory settings : *#7780#

Clear the LCD display (operator logo) : *#67705646#

Bluetooth device address : *#2820#

Sim clock status : *#746025625#

Default Security Code : 12345

On Enhanced Full Rate Codec : *3370#

Off Enhanced Full Rate Codec : *#3370#

On Half Rate Codec. : *4720#

Off Half Rate Codec : *#4720#

Software Version : *#0000# or *#9999#

Display the MAC address of the WLAN adapter : *#62209526#
(Available only in newer models that support WLAN like N80)

Lock Status of ur Phone : #pw+1234567890+1#

Lock Status of ur SIM : #pw+1234567890+4#

Security Code of ur Phone : *#2640#

Game Score & Timer: *#73# free glitter text and family website at FamilyLobby.com
[Read More...]


Problem:: My Windows Login Screen has changed to "Classic Logon Box". I want the new Welcome Screen back



Solution:

Type "control userpasswords" in RUN dialog box or Open "User Accounts" in Control Panel. Then click on "Change the way Users log on and off". Now check the option "Use Welcome Screen". If you get following error:

Uninstall client services for netware.


Then Open "Network Connections" and open Properties of your Internet Connection. Now goto "Networking" tab and select "Client services on Netware" option and click on the"Uninstall" button.
[Read More...]


Trick to hack administrator Account using Guest account in XP- 100% works



Follow these steps:


1. ok, First of all login through your guest account and open C:\WINDOWS\system32


2. Now look for cmd.exe and sethc.exe


3. copy these both exe files and place it any safe location


4. Now again go to C:\WINDOWS\system32, now rename cmd.exe into sethc.exe...... As sethc.exe is already exist, so a window will open... says..would you want to replace..... press yes...







5. Now Restart your system.


6. When login screen come.... press Shift key for 5 times.... then command prompt will open.


7. Now you can hack an administrator account in 2 way:
  • By hacking recent administrator's account by changing its password.
  • By giving Administrator's privileges to your guest account 

      So decide what you want to do....

8. Now

      8.1    if  you choose 1st one i.e. "Hacking recent administrator's account by changing its password".>>> then go to my post Hack administrator account and follow step 3 & 4 there.

      8.2     Or if you choose 2nd one then write in command prompt:
                   net localgroup administrators your_guest_account_name /add


9. Done!!!!! :)

By Suneel Kumar @ TCS

Enjoy :)
[Read More...]


Program to find the LCM of a number



#include<iostream>
 
void main()
{
 using namespace std;
 
 int num1,num2,a,b;
 cout<<"Enter 1st no. ";
 cin>>num1;
 cout<<"Enter 2nd no. ";
 cin>>num2;
 a=num1;
 b=num2;
 while(a!=b)
 {
  if(a<b)
  {
   a+=num1;
  }
  else
  {
   b+=num2;
  }
 }
 
 cout<<"LCM is = "<<a;
 cin.get();
}
[Read More...]


Program to find the GCD of a number using C++



 
#include<iostream>
 
void main()
{
 using namespace std;
 
 int num1,num2;
 cout<<"Enter 1st no. ";
 cin>>num1;
 cout<<"Enter 2nd no. ";
 cin>>num2;
 while(num1!=num2)
 {
  if(num1>num2)
  {
   num1 = num1-num2;
  }
  else
  {
   num2 = num2-num1;
  }
 }
 
 cout<<"GCD is = "<<num1;
 cin.get();
}
[Read More...]


Program to Demonstrate Inheritance in Java



Instructions:
1.)Save this program to a file and name it Inheritance.java
 
import javax.swing.JOptionPane;
class SuperClass //The Superclass
{
 String str="We Got Copieeed!!!";
 void func()
 {
  JOptionPane.showMessageDialog(null, str); //Prints the string 'str' in a window.
 }
}
 
class SubClass extends SuperClass //The SubClass inheriting SuperClass
{
}
 
public class Inheritance {
 
 public static void main(String[] args)  //Our main
 {
  SubClass sub1= new SubClass(); //SubClass Object Initialization.
  sub1.func(); //Call to function of SuperClass via object of the Subclass
 }
 
}
Tested in compilers: Eclipse and Command Line.
[Read More...]


JAVA program to demonstrate Abstract class example



abstract class Abs
{
 abstract void display();
}
class B extends Abs
{
 void display()
 {
  System.out.println("Hello");
 }
}
public class A {
 public static void main(String args[])
 {
  B objB = new B();
  objB.display();
 
 }
}
 
In the above program, the display() function in class B completes the display() 
function in abstract class A.  
[Read More...]


C++ program to open a file



This program will show you how to open a file in C++.We’ll need to include the fstream header file. The fstream header file contains the necessary classes to read, write files. It includes
ofstream: Stream class to write on files
ifstream: Stream class to read from files
fstream: Stream class to both read and write from/to files.

#include <iostream>
#include <fstream>
using namespace std;
int main()
 
{
 
 ofstream obj;  //Creating an object for class ofstream 
 obj.open("filename.txt"); //Opening the file "filename.txt"
 obj << "Hello";  //Writing to filename.txt
 obj.close(); //Closing file
 cin.get();
 return 0;
}
[Read More...]


Applet to make a smiley face



In this applet, we’ll be making a face using different shapes. The applet package contains methods to draw an Oval, a line, rectangle, rounded rectangle, arc, etc.
To make a smiley face, we will be using Ovals and arcs.
Syntax for drawing an Oval:
1
obj.drawOval(x,y,width,height);
In the above syntax, drawOval() method needs to be supplied four arguments. The first two arguments to set the position of the oval along the x axis and the y axis and the last two arguments to set the width and height of the oval.
Syntax for drawing an Arc:
1
obj.drawArc(x,y,width,height,starting angle,arc angle);
The drawArc() method needs to be accessed using an object with the dot operator. It needs to be supplied six arguments. The first two arguments to set the position of the arc along the x axis and the y axis and the next two to set the width and height of the arc respectively. The last two arguments determine the starting angle of the arc and angle of the arc.
Difference between drawOval() and fillOval().
‘draw’ is used to draw the outline of the given shape whereas ‘fill’ will fill the shape with the color which is set in the color pallet. To understand the difference properly, please refer the program given below.

import java.applet.*;
import java.awt.*;
public class Smiley extends Applet 
{
 public void paint(Graphics g)
 {
  g.setColor(Color.orange); //Setting color pallet to orange to paint the face
  g.fillOval(50, 50, 75, 75); //Draws Face
  g.setColor(Color.black); //Setting color pallet to black to paint the following shapes
  g.fillOval(65, 65, 15, 15); //Draws left eye
  g.fillOval(95, 65, 15, 15); //Draws right eye
  g.drawOval(90,63,25,25); //Draws  right outer eye
  g.drawOval(60,63,25,25); //Draws left outer eye
  g.drawArc(70, 90, 40,15, 180, 180); //Draws mouth
 }
 
}
[Read More...]


C++ Program to demonstrate Insertion Sort



Insertion sort is a simple sorting algorithm: a comparison sort in which the sorted array (or list) is built one entry at a time.
How it works:
  1. In insertion sort,elements are entered into the array(or list) 1-by-1.
  2. When the first element is entered, it is placed at the 1st position in the list(0th position in an array).
  3. When a new element is entered, it is compared to our already entered element and is decided whether to place before or after it in the list(array).
  4. Now when the third element is entered is entered, it is compared with the greater element of the 2 already existing elements. If smaller, then it is swapped. If not, then the array can be considered sorted.
    If swapped, then is compared with the smaller element of the 2 already existing elements and swapped again with it if it is even smaller.
  5. Similarly, all the the numbers to be placed in the list(array) are entered 1-by-1 and placed into the correct position right when they’re entered.
Example:
The following table shows the steps for sorting the sequence 5 7 0 3 4 2 6 1. On the left side the sorted part of the sequence is shown in red. For each iteration, the number of positions the inserted element has moved is shown in brackets. Altogether this amounts to 17 steps.

5 7 0 3 4 2 6 1
(0)
5 7 0 3 4 2 6 1
(0)
0 5 7 3 4 2 6 1
(2)
0 3 5 7 4 2 6 1
(2)
0 3 4 5 7 2 6 1
(2)
0 2 3 4 5 7 6 1
(4)
0 2 3 4 5 6 7 1
(1)
0 1 2 3 4 5 6 7
(6)
In our program, We have used:
  1. double arr[8]: A double datatype array of size 8 to store and sort any 8 numbers. Modify it to increase or decrease the number of elements to be entered and sorted (Also modify the conditions in the for loops.)
  2. int swaps: Integer variable to count the number of swaps performed.
  3. 1st for loop: To traverse through the array 8 times, accept 8 numbers and place them in their appropriate place (With the help of a nested while loop).
  4. int j=i: To start the array index for the while loop from i(location where the latest element has been placed).
  5. Nested while loop: This loop is nested in the above for loop. It compares and swaps the elements until the newly-inputted element reaches its appropriate place.
  6. swap(arg1,arg2): It is a predefined function and it swaps the data values of the 2 arguments passed to it.
The Program:
//Variables:
//double arr[8]: An array to store and sort 8 elements.
//int swaps: Integer variable to count the number of swaps performed.

#include<iostream>

int main()
{
 using namespace std;

 double arr[8]={0,0,0,0,0,0,0,0}; //Declare our array and initialize to 0
 int swaps=0; //Variable to count the number of swaps performed

 cout<<"Insertion sort Demonstration."<<endl<<endl;

 for (int i=0;i<8;i++) //To traverse through the array 8 times and accept 8 numbers
 {
  cout<<"Enter element number "<<i+1<<": "; //We use i+1 just to start the display of numbers from 1 rather than 0
  cin>>arr[i];

  int j = i;
  while(j>0 && arr[j]<arr[j-1]) //Runs until the new number has been placed in its correct place
  {
   swap(arr[j],arr[j-1]); //Swap if the elements are out of order.
   swaps++; //Increase swap counter
   j--; //decrease array index
  }
 }

 cout<<endl<<"Array After Sorting = ";
 for(int i=0;i<8;i++) //Loop to print our sorted array.
 {
  cout<<arr[i]<<" ";
 }
 cout<<endl;

 cout<<"Total number of swaps performed: "<<swaps<<endl<<endl;
 cout<<"Press any key to close this window...";

 cin.get();
 return 0;
}
[Read More...]


Java program to to convert Octal number into Decimal number



Octal to Decimal: How to Convert
Octal to decimal conversion is one of the most commonly taught problem solving exercises in computer basics. So is there an octal to decimal formula? Yes, an octal number can be converted to a decimal number using the following formula:

Decimal Form = Æ©(ai x 8i)

In this formula, ‘a’ is the individual digit being converted, while ‘i‘ is the number of the digit counting from the right-most digit in the number, the right-most digit starting with 0.
For example:
Convert (765)8 into decimal:
(765)8 = (7 x 82) + (6 x 81) + (5 x 80)
= (7 x 64) + (6 x 8 ) + (5 x 1)
= 448 + 48 + 5
= 501
Hence (765)8 = (501)10
Similarly,
(1336)8 = (734)10
(5467)8 = (2871)10
(6345)8 = (3301)10(
(76534)8 = (32092)10
(724635)8 = (240029)10
Try out yourselves!
How the Program works?
This program accepts the octal number from the user, saves individual digits to individual spaces in the array in the 1st ‘for’ loop and applies the above formula on them in the second ‘for’ loop.

import java.util.Scanner;
public class OctalToDecimal{
  static Scanner MyScan = new Scanner(System.in);
  public static void main(String args[])
  {
    int arr[] = new int[20];
    int DecNum=0,i=0;
    System.out.println("Enter the octal number: ");
    int num = MyScan.nextInt();
    for(i=0; num>0; i++) //Save the individual digits of the Octal number to the array.
    {
      arr[i] = num % 10;
      num = num / 10;
    }
    for(int power=0, j=0; j<i ; j++,power++)
    {
      DecNum = (int) (DecNum + arr[j] * Math.pow(8,power));
    }
    System.out.println("Decimal number: "+ DecNum);
  }
}
[Read More...]


Tic Tac Toe in C++



This program is a game program, Tic Tac Toe. Most of us have played this game in school days, we will be making a C++ program on it now. This program is quite lengthy, so I’ll first explain each variable and function.
Variables used:
(global) int gameover: This variable is initialized to 0 and its value is altered to 1 when the game is over. The program stops execution at gameover = 1.

int pos[9]
: This array contains the positions 1 – 9. This array is just used in one function (void print_board_start())
(global) char set[9] : This array is initialized to values 1 to 9. The values of 1 to 9 are altered to either X or O depending on user input. For instance: Player 1 (X) selects position 5 to mark as ‘X’. The function input_board_x() sets the value of set[5-1] = X. Similar process happens with Player 2(O).
(global) int taken[9]: This array to check if a position is taken. For instance, if a user selects position 5, taken[5-1] will be set to 1. While taking input from user, the program first checks if taken[x_pos - 1] = 1. If it is, it would tell the Player 1 that the position is already taken and asks to re-enter the position.
count: To count the number of moves. This variable cannot exceed 8 as there can only be 9 moves in a tic tac toe game.
void print_board_start(): This objective of this function is basically to print the starting board without any ‘X’ or ‘O’.
print_board_start()
void input_board_x()/void input_board_y(): These two functions alter the values of the positions of set[] to ‘X’ or ‘O’ depending on the users’ choice.
check_gameover();: This function tests if the game is over. If it is, then the value of gameover is set to 1.
check_duplicate();: Checks if user has entered a position that is already taken.
Program:
#include <iostream>
#include <conio.h>
using namespace std;
int gameover= 0;
int pos[9]={1,2,3,4,5,6,7,8,9};
char set[9]={'1','2','3','4','5','6','7','8','9'};
int taken[9]={0,0,0,0,0,0,0,0,0};
char cPlayer1 = 'X';
char cPlayer2 = 'O';
void print_board_start()  //Prints board at the start of the program
{
 cout<<"Welcome to Tic Tac Toe."<<endl;
 cout<<"|"<<pos[0]<<"|"<<pos[1]<<"|"<<pos[2]<<"|"<<endl;
 cout<<"-------"<<endl;
 cout<<"|"<<pos[3]<<"|"<<pos[4]<<"|"<<pos[5]<<"|"<<endl;
 cout<<"-------"<<endl;
 cout<<"|"<<pos[6]<<"|"<<pos[7]<<"|"<<pos[8]<<"|"<<endl;
 cout<<"-------"<<endl;
}
void input_board_x(int user_pos_x) //Sets the value for Player 1(X).
{
 set[user_pos_x-1]= 'X';

void input_board_y(int user_pos_y) //Sets position for Player 2(O)
{
 set[user_pos_y-1]= 'O';
}
void final_result_board() //Prints board after the game is won.
{
cout<<"|"<<set[0]<<"|"<<set[1]<<"|"<<set[2]<<endl;
cout<<"-------"<<endl;
cout<<"|"<<set[3]<<"|"<<set[4]<<"|"<<set[5]<<endl;
cout<<"-------"<<endl;
cout<<"|"<<set[6]<<"|"<<set[7]<<"|"<<set[8]<<endl;
cout<<"-------"<<endl;
}

int check_gameover() // Checks if the game is over
{
 //***---Checking if game is over.***---//
  //First possibilty
  if(set[0] == set[1] && set[2] == set[0])
  {
   cout<<"GAME OVER!"<<endl;
   gameover = 1;
   if(set[0] == cPlayer1)
   {
   cout<<"Player 1 wins!"<<endl;
   }
   else
    cout<<"Player 2 wins!"<<endl;
  }
   //Second possiblity
  if(set[0] == set[3] && set[6] == set[0])
  {
   cout<<"GAME OVER!"<<endl;
   gameover = 1;
   if(set[0] == cPlayer1)
   {
   cout<<"Player 1 wins!"<<endl;
   }
   else
    cout<<"Player 2 wins!"<<endl;
  }
  //Third possibility
  if(set[0] == set[4] && set[8] == set[0])
  {
   cout<<"GAME OVER!"<<endl;
   gameover = 1;
   if(set[0] == cPlayer1)
   {
   cout<<"Player 1 wins!"<<endl;
   }
   else
    cout<<"Player 2 wins!"<<endl;
  }
  //Fourth possibility
  if(set[1] == set[4] && set[7] == set[1])
  {
   cout<<"GAME OVER!"<<endl;
   gameover = 1;
   if(set[1] == cPlayer1)
   {
   cout<<"Player 1 wins!"<<endl;
   }
   else
    cout<<"Player 2 wins!"<<endl;
  }
  //Fifth possibility
  if(set[2] == set[5] && set[2] == set[8])
  {
   cout<<"GAME OVER!"<<endl;
   gameover = 1;
   if(set[2] == cPlayer1)
   {
   cout<<"Player 1 wins!"<<endl;
   }
   else
    cout<<"Player 2 wins!"<<endl;
  }
  //Sixth possibilty
  if(set[2] == set[4] && set[4] == set[6])
  {
   cout<<"GAME OVER!"<<endl;
   gameover = 1;
   if(set[2] == cPlayer1)
   {
   cout<<"Player 1 wins!"<<endl;
   }
   else
    cout<<"Player 2 wins!"<<endl;
  }
  //Seventh possibilty
  if(set[6] == set[7] && set[8] == set[6])
  {
   cout<<"GAME OVER!"<<endl;
   gameover = 1;
   if(set[2] == cPlayer1)
   {
   cout<<"Player 1 wins!"<<endl;
   }
   else
    cout<<"Player 2 wins!"<<endl;
  }
  return gameover;
}
int check_duplicate(int i) //Checks if any of the two players add a duplicate data.
{
 while(taken[i-1] == 1)
 {
  cout<<i<<" is already taken, please select another spot ";
  cin>>i;
 }
 return i;
}
int main()
{
 int count = 0;
 int x_pos,y_pos;
 print_board_start();
 cout<<"Player 1 : X"<<endl<<"Player 2 : 0"<<endl;
 while(gameover==0 && count<=8)
 {
  count++;
  cout<<"Enter the position for X :"<<endl;
  cin>>x_pos;
  while(x_pos>9 || x_pos <1 )
  {
   cout<<"Invalid Move! Please select position from 1 to 9:  ";
   cin>>x_pos;
  }

  if(taken[x_pos-1] == 1)
  {
   x_pos=check_duplicate(x_pos);
  }
  input_board_x(x_pos); //Setting the position of X.
  taken[x_pos -1] = 1; ////Setting the user entered position to taken.
  check_gameover();  //Check if the game is over.
  if(gameover == 1) //If game ends, this part of code will terminate the while loop
  {
   break;
  }
  if(count == 9) //If there have been 9 moves till now, loops stop executing
  {
   break;
  }
  count++;
  final_result_board(); //Prints current game progress
  cout<<"Enter the position for 0 : "<<endl;
  cin>>y_pos;
  while(y_pos>9 || y_pos <1 ) //If user enters invalid move. That is more than 9 and less than 0.
  {
   cout<<"Invalid Move! Please select position from 1 to 9:  ";
   cin>>y_pos;
  }
  if(taken[y_pos-1] == 1)
  {
   y_pos=check_duplicate(y_pos);
  }
  input_board_y(y_pos); //Setting the position of Y.
  taken[y_pos -1] = 1; //Setting the user entered position to taken.
  check_gameover();  // Checks if the game is over
  final_result_board(); //Prints current game progress
  if(gameover == 1) //If game ends, this part of code will terminate the while loop
  {
   break;
  }
 }
 if(gameover == 0) //If there is no result, i.e gameover stays at 0 after 9 iteration.
 {
  cout<<"Draw"<<endl;
 }
 final_result_board();
 getch();
}
[Read More...]


Java program to perform binary search



Example:
Consider an sorted array containing 5,15,25,30,35,40
Sorted array for binary search
Suppose we want to search for the number 30 in the given array. The algorithm performs the search in the following steps.
Step 1:
Compare the number to be searched with the middle element i.e 20 in this case. So the algorithm compares the number 30 with 20.

Step 2:
If the number to be searched is greater than the middle number, search operation is performed on the second part of the array. Else, on the first part of the array.

The procedure continues till array[mid] is the number requested by the user.
Program:
import javax.swing.*;
public class BinarySearch {
 public static void main(String[] args) {
  int array[] = new int[11];
  array[0] = 10;
  array[1] = 20;
  array[2] = 30;
  array[3] = 40;
  array[4] = 50;
  array[5] = 60;
  array[6] = 70;
  array[7] = 80;
  array[8] = 90;
  array[9] = 100;
  array[10] = 110;
  int size = array.length;
  int low = 0;
  int mid = low+size/2;
  int num=0;
  System.out.println("The current array contains following data: ");
  for(int i = 0 ; i<=10 ; i++)
  {
   System.out.print(array[i]+"\t");
  }
  System.out.println();
  String input_box = JOptionPane.showInputDialog("Enter the element to be searched: ");
  try //Putting the main code in the try block.
  {
  num = Integer.parseInt(input_box);
  if(num>array[size-1] || num < array[0]) //Main if
  {
   System.out.println("Number doesn't exist.");
  }
  else{
  while(array[(low+size)/2]!= num){
   if(num>array[(low+size)/2])
   {
    System.out.println("Setting low to "+mid);
    low = mid;
    mid=(mid+size)/2;
   }//End if
   else{

    System.out.println("Setting size to "+mid);
    size = mid;
    mid=mid/2;
    }  
  }//Close while loop
  System.out.println("The number is at position: "+(low+size)/2);
  }//End main if
  }//End try
  catch(Exception e)//Catching exception
  {
   JOptionPane.showMessageDialog(null, "Error:\nYou need to enter a number,not string", "Invalid Number!", JOptionPane.WARNING_MESSAGE);
  }
 }
}
[Read More...]


Java program to generate the Hailstone sequence (Collatz conjecture).



import java.util.Scanner;
public class HailStone {
  static Scanner MyScanner = new Scanner(System.in);
  public static void main(String[] args) {
    System.out.println("This program will generate the HailStone sequence. ");
    System.out.println("Enter a number: ");
    int num = MyScanner.nextInt(); //Taking input from user
    while(num>1)
    {
      if (num%2 == 0)
      {
        num /= 2; //Dividing num by 2 if it is even
        System.out.print(num+"\t");
      }
      else
      {
        num = (num*3)+ 1; // Adding num*3 + 1 to num if the num is odd
        System.out.print(num+"\t");
      }
    }
  }
 
}
[Read More...]


Java interview questions and answers



What is an abstract method?

An abstract method is a method which doesn’t have a body, just declared with modifier abstract.

Explain the use of the finally block.

Finally block is a block which always executes. The block executes even when an exception is occurred. The block won't execute only when the user calls System.exit()

What is the initial state of a thread?

It is in a ready state.

What is time slicing?

In time slicing, the task continues its execution for a predefined period of time and reenters the pool of ready tasks.

What are Wrapper Classes?

Wrapper Classes allow to access primitives as objects.

What is List interface?

List is an ordered collection of objects.

Can you explain transient variables in java?

They are the variables that cannot be serialized.

What is synchronization?

Synchronization ensures only one thread to access a shared resource, thus controls the access of multiple threads to shared resources.

What is serialization?

Serialization helps to convert the state of an object into a byte stream.

What is HashMap and Map?

Map is Interface and Hashmap is class that implements that.

Explain the usage of serialization.

Objects are serialized when need to be sent over network.
They are serialized when the state of an object is to be saved.

How are Observer and Observable used?

The observable class represents an observable object.
The object to be observed can be represented by sub-classing observable class.
When there is a change in an observable instance, an application calling the Observable's notifyObservers method causes all of its observers to be notified of the change by a call to their update method.

Difference between Swing and Awt.

AWT are heavy-weight components. Swings are light-weight components. Thus, swing works faster than AWT.

Define inner class in Java

Class that is nested within a class is called as inner class. The inner class can access private members of the outer class. It is mainly used to implement data structure and some time called as a helper class.

Differences between constructors and methods.

A constructor is used to create objects of a class. A method is an ordinary member in a class.
Constructor does not have a return type. A method should have a return type.
Constructor name is the name of the class. A method name should not be the name of the class
Constructor is invoked at the time of creation of the class. Method needs to be invoked in another method by using the dot operator.
Constructor can not have ‘return’ statement. All methods that return non-void return type should have ‘return’ statement.

Define Method overriding. Explain its uses.

Method overriding is the process of writing functionality for methods with same signature and return type, both in super class and subclass The uses of method overriding:
Time to invest method signature is reduced
Different functionality in both super class and sub class by sharing same signature
The functionality can be enhanced
The behavior can be replaced in the sub class

What is the purpose of the File class?

The File class provides access to the files and directories of a local file system.

What is StringBuffer class?

StringBuffer class is same as String class with the exception that it is mutable. It allows change and doesn’t create a new instance on change of value.

How can you force garbage collection?

It is not possible to force GC. We can just request it by calling System.gc().

Is it possible an exception to be rethrown?

Yes, an exception can be rethrown.

What is the return type of a program’s main() method?

A program’s main() method has a void return type.

Which package is always imported by default?

The java.lang package is always imported by default.

Java interview questions and answers - April 19, 2011

What is a Class?

A class implements the behavior of member objects by describing all the attributes of objects and the methods.

What is an Object?

An object is the members of a class. It is the basic unit of a system. It has attributes, behavior and identity.

Explain the use of "instanceOf" keyword.

"instanceOf" keyword is used to check the type of object.

How do you refer to a current instance of object?

You can refer the current instance of object using "this" keyword.

What is the use of JAVAP tool?

JAVAP is used to disassemble compiled Java files. This option is useful when original source code is not available.

In which package is the applet class located?

Applet classes are located in "java.applet" package.

Java array vs. ArrayList class.

ArrayList is a dynamic array that can grow depending on demand whereas Java arrays are fixed length.

Explain Enumeration Interface.

It defines the methods using which we can enumerate the elements in a collection of objects.

What are access modifiers?

Access modifiers determine if a method or a data variable can be accessed by another method in another class.

Explain the impact of private constructor.

Private constructor prevents a class from being explicitly instantiated by callers.

What is an exception?

An exception is an abnormal condition that arises in a code sequence at run time

What are ways to create threads?

There are two ways to create a thread:
extend the java.lang.Thread class
implement the java.lang.Runnable interface

How can we stop a thread programmatically?

thread.stop;

What are daemon threads?

Daemon threads are designed to run in background. An example of such thread is garbage collector thread.

What are the different types of locks in JDBC?

There are four types of major locks in JDBC:
Exclusive locks
Shared locks
Read locks
Update locks

What are Servlets?

Servlets are program that run under web server environments.

What are the different ways to maintain state between requests?

There are four different ways:
URL rewriting
Cookies
Hidden fields
Sessions

What are wrapper classes?

In Java we have classes for each primitive data types. These classes are called as wrapper class. For example, Integer, Character, Double etc.

What are checked exceptions?

There are exceptions that are forced to catch by Java compiler, e.g IOException. Those exceptions are called checked exceptions.

What is the Locale class?

Locale class is a class that converts the program output to a particular geographic, political, or cultural region

Is main a keyword in Java?

No, main is not a keyword in Java.

What is the most important feature of Java?

Platform independency makes Java a premium language.

What is a JVM?

JVM is Java Virtual Machine which is a run time environment for the compiled java class files.

Does Java support multiple inheritances?

No, Java doesn't support multiple inheritances.

What is the base class of all classes?

java.lang.Object

Can a class be declared as protected?

A class can't be declared as protected. Only methods can be declared as protected.

Can an abstract class be declared final?

No, since it is obvious that an abstract class without being inherited is of no use.

Can we declare a variable as abstract?

Variables can't be declared as abstract. Only classes and methods can be declared as abstract.

Define Marker Interface.

An Interface which doesn't have any declaration inside but still enforces a mechanism.

What is an abstract method?

An abstract method is a method whose implementation is deferred to a subclass.

When can an object reference be cast to an interface reference?

An object reference is cast to an interface reference when the object implements the referenced interface.

Which class is extended by all other classes?

The Object class is extended by all other classes.

What is the return type of a program's main() method?

void.

What are the eight primitive Java types?

The eight primitive types are byte, char, short, int, long, float, double, and boolean.

Difference between a public and a non-public class.

A public class may be accessed outside of its package. A non-public class may not be accessed outside of its package.

Which Java operator is right associative?

The = operator is right associative.

What is a transient variable?

Transient variable is a variable that may not be serialized.
[Read More...]


C, C++ OOPs Question



What is Operator, Operand, Expression, Statement in 'C'?

What is polymorphism?

What is operator overloading?

What are templates?

Declare a void pointer.

Declare a function pointer which takes a pointer to char as an argument and returns a void pointer.

Type-define a function pointer which takes a int and float as parameter and returns a float *.

What does the following C statement do?

while(*c++ = *d++); assuming c and d are pointers to characters.

How do you call a C module within a C++ module.

What is the difference between run time binding and compile time binding? Discuss.

Compare and contrast C++ and Java.

Why does C/C++ give better run-time performance then Java?

Does C++ come with in-built threading support.

Class A derives B derives C. All have foo(). I cast C to A and call foo(). What happens?

All classes A, B, C have default constructor, foo() that calls parent foo() and allocates 100 bytes to their own private local variable, and a destructor that frees the 100 bytes. I create a C object and then destroy it. What's the problem? Did all the memory get freed? What if I create C, cast to A, and then destroy it. How would I make sure memory is freed? (destructor must be "virtual" and each destructor must call parent destructor)

What errors are caught at compile time vs link time?

What is the value of "a" after this?
int (*a) [10];
a++;
2.5196What is wrong with this?
main(){
int *ptr;
*ptr=10;
}

Given int n, i=10, j=20, x=3, y = 100;
What is the value of n and y at the end of each of the following expressions?
a) n = (i > j) && (x < ++y);
b) n = (j - i) && (x < y++);
c) n = (i < j) || (y+=i);
2.5127int x = 5;
int y = 7;

What is the value of x and y after the expression y+=x++;

What's the difference between C and C++?

What does Public and Private mean in C++


[Read More...]


18. Goldbach's Conjecture. Goldbach's Conjecture is that any even number is the sum of two primes. Write a program to test Goldbach's Conjecture over a range of numbers.



import java.util.*;

public class Goldbach
{
  public static void main(String [] args)
  {
    Scanner scan=new Scanner(System.in);
   
    System.out.println("Enter Ending Range:");
    int endRange=scan.nextInt();
   
    System.out.println("Goldbach's Conjecture to Range=:");
    for(int num=4;num<=endRange;num=num+2)
    {
      int firstPrime=2;
      int secondPrime=0;
      while(true)
      {
        secondPrime=num-firstPrime;
        if(!isPrime(secondPrime))
        {
          firstPrime=getNextPrime(firstPrime);
        }
        if(num==(firstPrime+secondPrime)&&isPrime(secondPrime)&&isPrime(firstPrime))
        {
          System.out.println(num+"\t=  "+firstPrime+" + "+secondPrime);
          break;
        }
      }
     
    }
  }
  public static int getNextPrime(int num)
  {
    for(int i=num+1;;i++)
    {
      for(int j=2;j<=i;j++)
      {
        if(i%j!=0)
        {
          return i;
        }
      }
    }
  }
  public static boolean isPrime(int num)
  {
    for(int i=2;i<num;i++)
    {
      if(num%i==0)
      {
        return false;
      }
    }
    return true;
  }
}
[Read More...]


What is the Sieve of Eratosthenes?



A prime number is a natural number greater than 1 that can be divided without remainder only by itself and by 1. Natural numbers n that can be divided by a number less than n and greater than 1 are composite numbers. The Sieve of Eratosthenes identifies all prime numbers up to a given number n as follows:

Write down the numbers 1, 2, 3, ..., n. We will eliminate composites by marking them. Initially all numbers are unmarked.
Mark the number 1 as special (it is neither prime nor composite).
Set k=1. Until k exceeds or equals the square root of n do this:
Find the first number in the list greater than k that has not been identified as composite. (The very first number so found is 2.) Call it m. Mark the numbers
 2m, 3m, 4m, ...

as composite. (Thus in the first run we mark all even numbers greater than 2. In the second run we mark all multiples of 3 greater than 3.)
m is a prime number. Put it on your list.
Set k=m and repeat.
Put the remaining unmarked numbers in the sequence on your list of prime numbers.
[Read More...]


11. Sieve of Eratosthenes. Using the Sieve principle, write a program that can produce all the prime numbers greater than zero and less than or equal to some largest number Max.



import java.util.*;
public class Eratosthenes
{
  int max;
  static int primes[];
 
  public static void main(String args[])
  {
    Eratosthenes erat = new Eratosthenes();
    erat.find_primes();
    for(int i=0;i<primes.length;i++)
    {
      System.out.print(primes[i]+",");
    }
  }
  public Eratosthenes()
  {
    System.out.print("Enter End Range of list:");
    Scanner scan = new Scanner(System.in);
    max=scan.nextInt();
  }
 
  public void find_primes()
  {
    int i,j,k, divisor, offset;
   
    double sqrt = Math.sqrt(max)+1;
    int tmp[];
   
    if(max  > 100)
    {
      primes = new int[max/2];
    }
    else
    {
      primes = new int[max];
    }
    primes[0] = 2;
    primes[1] = 3;
   
    for(i=2,j=5; j < max ; j+=2)
    {
      if(j % 3 != 0)
      {
        primes[i++] = j;
      }
    }
   
    for(i=2, divisor=5, offset = primes.length; divisor < sqrt ; )
    {
      j = i*i;
      tmp = new int[offset];
      offset = j;
     
      /*
       * Copy the numbers that have already been sieved to a new array.
       */
      System.arraycopy(primes,0,tmp,0,j);
      while( j < tmp.length)
      {
        k = primes[j++];
        if(k==0)
        {
          /*
           * The array may contain some zeros at the end. It's too much
           * trouble to calculate the exact size for the array. Easier
           * to pad with zeros
           */
          break;
        }
        if(k % divisor != 0)
        {
          tmp[offset++] = k;
        }
      }
      primes = null;
      primes = tmp;
      tmp = null;
      divisor = primes[i++];
    }
  }
}
[Read More...]


Junior Java programmer interview questions




1.    What is the purpose of finalization? - The purpose of finalization is to give an unreachable object the opportunity to perform any cleanup processing before the object is garbage collected.
2.    What is the difference between the Boolean & operator and the && operator? - If an expression involving the Boolean & operator is evaluated, both operands are evaluated. Then the & operator is applied to the operand. When an expression involving the && operator is evaluated, the first operand is evaluated. If the first operand returns a value of true then the second operand is evaluated. The && operator is then applied to the first and second operands. If the first operand evaluates to false, the evaluation of the second operand is skipped.
3.    How many times may an object’s finalize() method be invoked by the garbage collector? - An object’s finalize() method may only be invoked once by the garbage collector.
4.    What is the purpose of the finally clause of a try-catch-finally statement? - The finally clause is used to provide the capability to execute code no matter whether or not an exception is thrown or caught.
5.    What is the argument type of a program’s main() method? - A program’s main() method takes an argument of the String[] type.
6.    Which Java operator is right associative? - The = operator is right associative.
7.    Can a double value be cast to a byte? - Yes, a double value can be cast to a byte.
8.    What is the difference between a break statement and a continue statement? - A break statement results in the termination of the statement to which it applies (switch, for, do, or while). A continue statement is used to end the current loop iteration and return control to the loop statement.
9.    What must a class do to implement an interface? - It must provide all of the methods in the interface and identify the interface in its implements clause.
10.                        What is the advantage of the event-delegation model over the earlier event-inheritance model? - The event-delegation model has two advantages over the event-inheritance model. First, it enables event handling to be handled by objects other than the ones that generate the events (or their containers). This allows a clean separation between a component’s design and its use. The other advantage of the event-delegation model is that it performs much better in applications where many events are generated. This performance improvement is due to the fact that the event-delegation model does not have to repeatedly process unhandled events, as is the case of the event-inheritance model.
11.                        How are commas used in the intialization and iteration parts of a for statement? - Commas are used to separate multiple statements within the initialization and iteration parts of a for statement.
12.                        What is an abstract method? - An abstract method is a method whose implementation is deferred to a subclass.
13.                        What value does read() return when it has reached the end of a file? - The read() method returns -1 when it has reached the end of a file.
14.                        Can a Byte object be cast to a double value? - No, an object cannot be cast to a primitive value.
15.                        What is the difference between a static and a non-static inner class? - A non-static inner class may have object instances that are associated with instances of the class’s outer class. A static inner class does not have any object instances.
16.                        If a variable is declared as private, where may the variable be accessed? - A private variable may only be accessed within the class in which it is declared.
17.                        What is an object’s lock and which object’s have locks? - An object’s lock is a mechanism that is used by multiple threads to obtain synchronized access to the object. A thread may execute a synchronized method of an object only after it has acquired the object’s lock. All objects and classes have locks. A class’s lock is acquired on the class’s Class object.
18.                        What is the % operator? - It is referred to as the modulo or remainder operator. It returns the remainder of dividing the first operand by the second operand.
19.                        When can an object reference be cast to an interface reference? - An object reference be cast to an interface reference when the object implements the referenced interface.
20.                        Which class is extended by all other classes? - The Object class is extended by all other classes.
21.                        Can an object be garbage collected while it is still reachable? - A reachable object cannot be garbage collected. Only unreachable objects may be garbage collected.
22.                        Is the ternary operator written x : y ? z or x ? y : z ? - It is written x ? y : z.
23.                        How is rounding performed under integer division? - The fractional part of the result is truncated. This is known as rounding toward zero.
24.                        What is the difference between the Reader/Writer class hierarchy and the InputStream/OutputStream class hierarchy? - The Reader/Writer class hierarchy is character-oriented, and the InputStream/OutputStream class hierarchy is byte-oriented.
25.                        What classes of exceptions may be caught by a catch clause? - A catch clause can catch any exception that may be assigned to the Throwable type. This includes the Error and Exception types.
26.                        If a class is declared without any access modifiers, where may the class be accessed? - A class that is declared without any access modifiers is said to have package access. This means that the class can only be accessed by other classes and interfaces that are defined within the same package.
27.                        Does a class inherit the constructors of its superclass? - A class does not inherit constructors from any of its superclasses.
28.                        What is the purpose of the System class? - The purpose of the System class is to provide access to system resources.
29.                        Name the eight primitive Java types. - The eight primitive types are byte, char, short, int, long, float, double, and boolean.
30.                        Which class should you use to obtain design information about an object? - The Class class is used to obtain information about an object’s design.

[Read More...]



Send mail to your Friends.  

Expert Feed

 
Return to top of page Copyright © 2011 | My Code Logic Designed by Suneel Kumar