Saturday 19 October 2013

Write code snippets to swap two variables in five different ways.

a.      /* swapping using three variables*/ (Takes extra memory space)
Int a=5, b=10, c;
c=a;
a=b;
b=c;

b.      /* using arithmetic operators */
a=a+b;
b=a-b;
a=a-b;

c.       /* using bit-wise operators */
a=a^b;
b=b^a;
a=a^b;

Line
Operation
Value of a
Value of b

1
-
5
10
Initial values
2
a=a^b
15
10

3
b=a^a
15
5

4
a=a^b
10
5
values after swapping


d.      /* one line statement using bit-wise operators */ (most efficient)
a^=b^=a^=b;

The order of evaluation is from right to left. This is same as in approach (c) but the three statements are compounded into one statement.

e.       /* one line statement using arithmetic & assignment operators */
a=(a+b) - (b=a);
In the above axample, parenthesis operator enjoys the highest priority & the order of evaluation is from left to right. Hence (a+b) is evaluated first and replaced with 15. Then (b=a) is evaluated and the value of a is assigned to b, which is 5. Finally a is replaced with 15-5, i.e. 10. Now the two numbers are swapped.

Friday 27 September 2013

A C-program to print Hello world without using any semicolon

Explanation:
Solution: 1
void main(){
    if(printf("Hello world")){
    }
}

Solution: 2
void main(){
    while(!printf("Hello world")){
    }
}

Solution: 3
void main(){
    switch(printf("Hello world")){
    }
}

Thursday 15 August 2013

Happy Independence Day

?#?include?<stdio.h>
int main (void)
{
int a=10, b=0, c=10;
char* bits ="TFy!QJu ROo TNn(ROo)SLq SLq ULo+UHs UJq TNn*RPn/QPbEWS_JSWQAIJO^NBELPeHBFHT}TnALVlBLOFAkHFOuFETpHCStHAUFAgcEAelclcn^r^r\\tZvYxXyT|S~Pn SPm SOn TNn ULo0ULo#ULo-WHq!WFs XDt!";
a = bits[b];
while (a != 0) {
a = bits[b];
b++;
while (a > 64) {
a--;
if (++c == 'Z') {
c /= 9;
putchar(c);
} else {
putchar(33 ^ (b & 0x01));
}
}
}
return 0;
}

output:---

Monday 12 August 2013

Java Abstraction

Abstraction is the concept of exposing only the required essential characteristics and behavior with respect to a context.
Abstraction in OOP:
In general computer software, when we talk about abstraction the software language itself is an example for the concept of abstraction. When we write a statement as,
a = b + c;
we are adding two values stored in two locations and then storing the result in a new location. We just describe it in an easily human understandable form. What happens beneath? There are registers, instruction sets, program counters, storage units, etc involved. There is PUSH, POP happening. High level language we use abstracts those complex details.
When we say abstraction in Java, we are talking about abstraction in object oriented programming (OOP) and how it is done in Java. Concept of abstraction in OOP, starts right at the moment when a class is getting conceived. I will not say, using Java access modifiers to restrict the properties of an object alone is abstraction. There is lot more to it. Abstraction is applied everywhere in software and OOP.
Abstraction in Java:
Having read the above section, you might have now come to an idea of how abstraction is done in Java.
When we conceptualize a class
When we write an ‘interface’
When we write an ‘abstract’ class, method
When we write ‘extends’
When we apply modifiers like ‘private’, … 
Abstraction and Encapsulation:
When a class is conceptualized, what are the properties we can have in it given the context. If we are designing a class Animal in the context of a zoo, it is important that we have an attribute as animalType to describe domestic or wild. This attribute may not make sense when we design the class in a different context.
Similarly, what are the behaviors we are going to have in the class? Abstraction is also applied here. What is necessary to have here and what will be an overdose? Then we cut off some information from the class. This process is applying abstraction.
When we ask for difference between encapsulation and abstraction, I would say,encapsulation uses abstraction as a concept. So then, is it only encapsulation. No, abstraction is even a concept applied as part of inheritance and polymorphism.
We got to look at abstraction at a level higher among the other OOP concepts encapsulation, inheritance and polymorphism.
Abstraction and Inheritance:
Let us take inheritance also in this discussion. When we design the hierarchy of classes, we apply abstraction and create multiple layers between each hierarchy. For example, lets have a first level class Cell, next level be LivingBeing and next level be Animal. The hierarchy we create like this based on the context for which we are programming is itself uses abstraction. Then for each levels what are the properties and behaviors we are going to have, again abstraction plays an important role here in deciding that.
What are some common properties that can be exposed and elevated to a higher level, so that lower level classes can inherit it. Some properties need not be kept at higher level. These decision making process is nothing but applying abstraction to come up with different layers of hierarchy. So abstraction is one key aspect in OOP as a concept.


in all these areas, we use abstraction as a concept. I think example Java code for all the above is very trivial. If you find it difficult to understand abstraction, pour your question in the comments section, I will be more than happy to answer it.


Monday 5 August 2013

Java Bubble Sort Descending Order Example

public class BubbleSortDescendingOrder {

        public static void main(String[] args) {
             
                //create an int array we want to sort using bubble sort algorithm
                int intArray[] = new int[]{5,90,35,45,150,3};
             
                //print array before sorting using bubble sort algorithm
                System.out.println("Array Before Bubble Sort");
                for(int i=0; i < intArray.length; i++){
                        System.out.print(intArray[i] + " ");
                }
             
                //sort an array in descending order using bubble sort algorithm
                bubbleSort(intArray);
             
                System.out.println("");
             
                //print array after sorting using bubble sort algorithm
                System.out.println("Array After Bubble Sort");
                for(int i=0; i < intArray.length; i++){
                        System.out.print(intArray[i] + " ");
                }

        }

        private static void bubbleSort(int[] intArray) {
 int n = intArray.length;
                int temp = 0;
             
                for(int i=0; i < n; i++){
                        for(int j=1; j < (n-i); j++){
                             
                                if(intArray[j-1] < intArray[j]){
                                        //swap the elements!
                                        temp = intArray[j-1];
                                        intArray[j-1] = intArray[j];
                                        intArray[j] = temp;
                                }
                             
                        }
                }
     
        }
}

Output of the Bubble Sort Descending Order Example would be

Array Before Bubble Sort
5 90 35 45 150 3
Array After Bubble Sort
150 90 45 35 5 3

Thursday 25 July 2013

Dangling pointer problem in c programming:

1. Dangling pointer:
If any pointer is pointing the memory address of any variable but after some variable has deleted from that memory location whilepointer is still pointing such memory location. Such pointer is known as dangling pointer and this problem is known as dangling pointer problem.
Initially:
Later:

Monday 22 July 2013

How to reverse a string in c without using reverse function

#include<stdio.h>
int main(){
    char str[50];
    char rev[50];
    int i=-1,j=0;

    printf("Enter any string : ");
    scanf("%s",str);
 
    while(str[++i]!='\0');

    while(i>=0)
     rev[j++] = str[--i];

    rev[j]='\0';
 
    printf("Reverse of string is : %s",rev);
 
    return 0;
}

Sample output:
Enter any string : ramprofessionals.blogspot.com
Reverse of string is : moc.topsgolb.slanoisseforpmar

Friday 19 July 2013

INVENTORS OF COMPUTER HARDWARE:

(1) Key board — Herman Hollerith, first keypunch device in 1930’s

(2) Transistor — John Bardeen, Walter Brattain & Wiliam Shockley (1947 - 1948)

(3) RAM — An Wang and Jay Forrester (1951)

(4) Trackball — Tom Cranston and Fred Longstaff (1952)

(5) Hard Disk — IBM , The IBM Model 350 Disk File (1956 )

(6) Integrated Circuit— Jack Kilby & Robert Noyce (1958)

(7) Computer Mouse — Douglas Engelbart (1964)

(8) Laser printer— Gary Stark weather at XEROX in 1969.

(9) Floppy Disk— Alan Shugart & IBM( 1970)

(10) Microprocessor — Faggin, Hoff & Mazor – Intel 4004

Solve this puzzle... ?

A shopkeeper has 3 bags of coconut each containing 30 coconuts. While travelling from one place to other, he has to pass 30 toll-booths. At every toll-booth, he has to give coconuts equal to number of bags he have. After passing all 30 toll-booths, how many coconuts will be left with the shopkeeper?

Reply fast...

Monday 8 July 2013

Sunday 7 July 2013

Guess Which OS?


Wow Transparent


Java progaram to generate pyramid

public class JavaPyramid4 {

        public static void main(String[] args) {
             
                for(int i=1; i<= 5 ;i++){
                     
                        for(int j=0; j < i; j++){
                                System.out.print(j+1);
                        }
                     
                        System.out.println("");
                }

        }
}

 Output of the above program would be
*
**
***
****
*****

Increase Virtual RAM - To Make Your System Faster

Follow the steps given below :-

1) Hold down the 'Windows' Key and Press the 'Pause/Break' button at the top right of your keyboard.
Another way is Right-Clicking 'My Computer' and then Select 'Properties'.

2) Click on the 'Advanced' tab.

3) Under 'Performance', click 'Settings'.

4) Then click the 'Advanced' tab on the button that pops up.

5) Under 'Virtual Memory' at the bottom, click 'Change'.

6) Click the 'Custom Size' button.

7) For the initial size (depending on your HD space), type in anywhere from 1000-1500 (although I use 4000), and for the Maximum size type in anywhere from 2000-2500 (although I use 6000).
 Click 'Set', and then exit out of all of the windows.

9) Finally, Restart your computer.

10) You now have a faster computer and 1-2GB of Virtual RAM..!

New License keys to useful software's :

MICROSOFT OFFICE 2013
9MBNG-4VQ2Q-WQ2VF-X9MV2-
MPXKV

AVG INTERNET SECURITY 2013:
Licence: 8MEH-RFR8J-PTS8
Q-92ATA-O4WHO-JEMBR-ACED

Office 2013:
B9GN2-DXXQC-9DHKT-
GGWCR-4X6XK

Blue Screen Error- How to Fix it

when i posted a joke on blue screen, many fans asked me the solution to it. here are some tips to get rid of it.

Blue Screen = The Most Irritating Error Face by Windows Users.

Did you ever got stuck with this type of Error ?
Most of will answer it YES.

What is Blue Screen of Death (BSOD) ?

Blue screen of death is nothing but an error Shown in Microsoft Windows Operating Systems which Stops Further Operations.

Why BSOD Error is Caused ?

This error is Generally Hardware or Drivers Related.causing the Computer To stop Responding And prevents Damage to the Hardware And data.
BSOD Looks Like the Below Picture. Manny Windows Users Must be Familiar With This.


How To Fix BSOD :
As I said There are several Reasons For BSOD, Unfortunately There is no Particular solution but The Following Tips And tricks Can Help you To get Rid Of it.


1. Remove Startup Programs That Starts Will System Booting.

What happens is when you System Boots, Many Other apps try To load at the same time whill may result in to BSOD. so Remove Unwanted Programs On startup.

How To Remove :
Press Windows Key +R
Run Box will appear. Type "msconfig" and Hit Enter,

Click on Startup Tab and remove all Unwanted Programs and click on apply.
It may ask you to restart your system, So restart it .


Removing programs at startup will fix your problem.

2.Uninstall Softwares:
Many Times while installing a softare A blue screen occors with a message that says, The Software that you are installing is Culprit . Verify all the changes that you made to your system and reset Them. Uninstall the installed Application it will help you to a great extent.

3. Resetting your Hardwares And Drivers :In some cases Due to Faulty Hardware connection it show the blue error screen. You can prevent this by ensuring you all hardware connection such as external ports,motherboard pins are set correctly.Bad drivers may also cause the same problem.Keep your drivers up to date.

Above tips will definately help you to get rid of Bluescreens.


Windows 8 users May have Experienced a New Blue screen:
In windows 8 it will Tell you About the error and sad Emoticon At the top of the text .(its BSOD)

Like This if it was Helpful..