SCJP - Last Minute Revision Notes

1. Check for any obvious complier errors first like two else statements , accessing ofprivate variable/method , accessing a variable declared in a for loop outside the for loop.

2. If you try to unbox a null Integer value to int , it will result in a NullPointerException.

3. If method having the same name as Class name and having a return type is not a constructor but a ordinary method.

4. Map is the only interface that does not extend Collection. List , Set and Queue extends the Collection interface.

Collection is a interface ,
Collections is Class which extends Object class.

Map: key , value pair
Hashtable , HashMap , LinkedHashMap , TreeMap

Set : unique values
HashSet , TreeSet , LinkedHashSet

List : List of values allows duplicates, accessed by index
ArrayList , Vector , LinkedList

Queue : stack or queue. to-do list. priority queue is sorted based on the natural order or based on the object of Comparator or Comparable.LinkedList , PriorityQueue
The twins clases.

a. The Hashtable and HashMap: Both are atmost same except that Hashtable methods are synchronized and it does not allow null key/value, whereas HashMap allows one null key and many null values and its methods are not synchronized . The Hashtable is oldest class in java. The t in Hashtable is indeed a small letter rather than capital letter.

b. The Vector and ArrayList have same functionalities except that Vector Methods are synchronized , while ArrayList methods are not. Both ArrayList and Vector implementes RandomAccess interface (which is marker interface having no methods) as of java 5

c. The LinkedList can be used to access values in insertion order. The LinkedHashMap can be used access values in insertion or access order. The LinkedList implements Queue(as of java 5) and List. The LinkedList now implements queue methods like offer, poll and peek.

d. The TreeSet , TreeMap and PriorityQueue sorts the values.

e. The HashSet , Hashtable and HashMap are unordered and unsorted. if you add n values in these Collection objects , iteration will not give you a particular ordering ie no insertion or access or natural order. It iterates in a random order.

f. The LinkedHashSet is ordered form of HashSet , The LinkedHashMap is the ordered form of HashMap.

g. the offer() method adds a element in queue. the poll method returns the first method and removes it from queue. the peek just returns the first method from queue. The higgest priority is stored first in PriorityQueue. if you poll each value from PriorityQueue then values returned will be of Higgest proririty to lowest priorirty.

h. The Object of class which need to be added in HashSet , Hashtable , LinkedHashSet or HashMapt must override the below methods
The exception are all Wrapper classes. The class Number , StringBuffer and StringBuilder.

For example object of Student class need to be added in LinkedHashSetA student class contains id , name. As id is a primaray key , we should not have rwo students with the same id. if the Student class does not override the above methods then

Student d = new Student(44); //44 is id
Student d 1= new Student(44); //44 is id
public int hashCode(){}
public boolean equals(Object o){}
public boolean equals(Object o { if (o instanceof Student) {
Student t= (Student) o;
if(o.getId() ==this.id ) {
return true;
} //if
} //ifreturn false;
} //method
public int hashCode() {
//use any of the below
return id*4;
return id;
return 1038; //any constant
//do no use any of the below
Random r =new Random(44);
return r.nextInt();
//here t is transient variable
return t*id;
}
if above method is implemented then d and d1 will be same object.
both d and d1 are different object accoring to the LinkedHashSet , as a result both will be added to the Set

i. The Object of class which need to be added in TreeMap , TreeSet and PriorityQueue must implement Comparable or Comparator interface

j. java.lang.Comparabl e declaresompareTo( ) and accepts one Object as argument.k. java.util.Comparato r declares compare() which accepts 2 Object as argument.

l. in generics if you declare a variable it must be instantiated with the same type or no type at all

//valid

Listlisto1 =new ArrayList ();
List listo2 =new ArrayList();
List listo3 =new ArrayList ();
List list3 =new ArrayList();
m1(list01);/ /error
m2(list01);/ /ok
m1(list02);/ /error
m2(list02);/ /ok
m1(list03);/ /ok
m2(list03);/ /ok
m1(list3);// ok
m2(list3);// error

//invalid

List listo =new ArrayList(); //compiler error

// functions
static void m1( a) {}
static void m2( a) {}

//The argument that Child class can be applied to a parent class i s not at all applicable to generics . if you specified a type in the variable declaration it must be followed while instantiating also.

In the Exam , there will be drag-drop quetion . in which there will be 4 variable instanciated with the genreic and passed as arguemnt to a function. you have drag and drop , if the code compiles or not.

m.
public class {} and
public class {}
are invalid syntax and leads to compiler error

but it can be defined as

public class {} or
public class {}
public class {} public class {}
public T getObject() {} //correct
public T computeArrays( Y y) {}
//correct, the font-size of s is increased to differentiate from the interface Collection
//here Y is the argument and T is the return type.

5. For garbage collection , you must focus on the value and its reference . there may be a question . which is earliest line in which the value referred by object in line 5(some line) is eligible for garbage collection . The reference variable will be given other values in the consecutive steps but focus if the value which was created/defined in line 5 (example) is referenced by any other variable. The variable can be instance or local variable. if it is a local variable , its scope will be till the method ends but except in the situation the value is returned.
For example below :

Object o= new Object//line 5
Object s =o;//line 6
// the value created in line 5 is referred by s

case 1 .

o = new Object(); //7 //o is set to different value
s=null; //8 s is null or
s = new Object(); // s is set to a new value
}
so old value has no reference.

here the value created in line 5 will be eligible for gc after line 5

case 2.

o= new Object();//5
Object s =o;//6
o = new Object();//7
return s;//8 }
The value created in line 5 will not be eligible for garbage collection even after the method has ended as it is returned.

case 3:

private Object o;
public void data() {
Object o = new Object();//1
doSomething( o);//2
o = new Object();//3
o=null;//4
doSomething( null);//5
Object s = new Object();//6
Object nothing = new Object();//7
return s;//8
}//9

In the above example value created in line 1 is eligible for garbage collection after the line 5. The value created in the line 3 is eligible for garbage collection after the line 4.

The value created in line 6 will not be eligible for garbage collection even after the method ends as the value is returned. The value created in line 7 is eligible for garbage collection after the line 9.

public void doSomething( Object obj) {
o= obj;
}

JavaScript Tricks: Edit Websites in Browser (Live)

Imagine a world where you are a God and have ultimate control on what happens and more importantly, how it happens. Seems too good a dream. Now it has come true, at least for the online world.

Edit Websites Browser

Using this trick, you will be able to edit any webpage live in your browser as if it was a Wiki and change the details according to your wish. Yes, you read that right. You can edit Google or even Facebook for that matter right in your browser and that too without requiring any technical know-how or getting deep into hacking and cracking.

Here is an example picture demonstrating the Google Homepage edited by me to say that I own Google.

This is just an example. You can use it for anything like showing wrong traffic stats or for fooling people by showing that someone said something about them on Facebook or Twitter. It depends only on your creativity. But I would advise you to stay ethical and use it for entertainment purposes only.

(Mozilla Firefox does not support this. If you use Firefox, you can use the bookmarklets given at the end of this post. If you use Google Chrome and the code does not seem to work, precede it with "javascript:" without quotes.)

To use this trick, all you need to do is just copy the code given below and paste it in your address bar [make sure its in single line] after you have opened the website you wish to edit. And start editing.

javascript:document.body.contentEditable%20=%20'true';
%20document.designMode='on';%20void%200

You can capture a screenshot by pressing the Print Screen key or by using the Snipping Tool if you use Windows 7 or Windows Vista. If you wish to again make the website non-editable to give a more authentic look, copy and paste the code given below in the address bar [make sure its in single line] after you are done editing (does not work in Firefox).

javascript:document.body.contentEditable%20=%20'false'; 
%20document.designMode='off';%20void%200

Or, alternatively you can use the following bookmarklets by dragging them to your Bookmarks bar.
The editing that you do will however be temporary as it is not server-sided. You can also save the modified website through your browser by File>Save. This works on all common web browsers including Chrome, Firefox, Opera and Internet Explorer.

Transfer Files Between Devices & Your Windows 7 PC via Bluetooth

Bluetooth devices are very common nowadays. By using this technology it is so easy to share files between very different devices. If your computer or laptop has a Bluetooth dongle or built-in module, Windows 7 can use it for exchanging files with other Bluetooth enabled devices such as mobile phones, iPods, iPhones, PSP devices, etc. In this guide I will show you how to verify that your dongle or built-in module works, how to connect your computer to another Bluetooth enabled device and how to exchange files between them.


Verify that Bluetooth is Working Correctly

The first thing you should do before starting a Bluetooth connection is to make sure that the Bluetooth dongle or integrated module is inserted in the computer and turned on.
Windows 7 will then install the drivers needed for the Bluetooth device. It has drivers for most Bluetooth dongles and built-in devices but, if it's not able to find any suitable drivers for it, then you should install those which are bundled by the manufacturer of your product via an install disc or on its official website.
Next, you will see a Bluetooth icon in the system tray or notification area which means that Bluetooth is active.

Bluetooth

If it is not active, you'll have to enable Bluetooth on your computer. By default, the wireless and Bluetooth connections are active. If, for some reason, they're not, look for a button on the surface of your laptop that should enable both wireless and Bluetooth connections. If you can't find that button please read the laptop's manual to find it and learn how to turn on Bluetooth.
Now, you need to make sure that the Bluetooth works properly. Type in the Start menu search box the word bluetooth and click on the 'View devices and printers' search result. Another way is to go to 'Control Panel -> Hardware and Sound -> Devices and Printers'.

Bluetooth

In the new window you will see a list with all devices and printers that are connected to your computer. The Bluetooth dongle or integrated module will be on that list as well. If your Bluetooth device has a yellow exclamation point on its icon it means that there is a problem with it. Otherwise it means that the device is working properly.

Bluetooth

If the device has problems, select it and then click on the Troubleshoot button from the top menu. Follow the wizard's instructions and hopefully, Windows will find a solution to the problem.

Bluetooth

NOTE: If the device that you want to connect via Bluetooth to your computer has specific software applications made exactly for this kind of task, I recommend you to use that software. For example, if you have a phone with Bluetooth support it is a good idea to use that phone's "PC Suite" application on your computer.

Connect a Device to Your Computer Using Bluetooth

First you need to make sure that your computer can be seen by the Bluetooth device. In other words, you need to make sure the computer is discoverable via Bluetooth. You can access the Bluetooth settings on your computer by right-clicking the Bluetooth icon in the system tray or notification area, and selecting 'Open Settings'.

Bluetooth

Or you can simply search in the Start Menu's search box for bluetooth and click on the 'Change Bluetooth settings' search result.

Bluetooth

The Bluetooth settings window will now open. In the Options tab, at the Discovery section, check 'Allow Bluetooth devices to find this computer'. This will allow other devices to see your computer. When done, click on OK.
NOTE: Enable this option only if you want the Bluetooth device to find and connect to your computer. The other way around, connecting from the computer to the device, works without having this option enabled.

Bluetooth

Next, you have to activate Bluetooth on your device. Search for discoverable devices, select the computer and pair with it. Then you have to enter a password for this connection. On your computer you will see a system notification about a device that wants to connect with it. Click on that balloon or, if you missed it, double click on the Bluetooth icon from the system tray or notification area.

Bluetooth

In the new 'Add a device' window you have to type the same password as you did in in the device that is connecting to the computer. Then click on Next.

Bluetooth

Now Windows 7 will search for drivers and it will install them for the device that is connecting to your computer. To verify that the device has been properly installed click the Devices and Printers link from the 'Add a device' window.

Bluetooth

There you can also see if the device is working properly or if it requires troubleshooting.
NOTE: If Windows doesn't find suitable drivers for the Bluetooth Peripheral Device, don't worry, you will still be able to send and receive files.

Bluetooth

Now, assuming that there are no problems, let's see how to send a file from the device to the computer through Bluetooth.

Connect the Computer to a Device Using Bluetooth

Turn on the Bluetooth function on the device and make it discoverable so that your computer will find it. Then open up the Bluetooth device window either by double-clicking the Bluetooth icon from the system tray or notification area. Click on the 'Add device' button or simply search in the Start Menu's search box for bluetooth and select the 'Add a Bluetooth device' result.

Bluetooth

Next Windows 7 will search for Bluetooth enabled devices. When it finds your Bluetooth device, select it and click on Next.

Bluetooth

Then Windows 7 will show you a password or PIN that you have to type in the device. After you typed the PIN in your device, click on Next.

Bluetooth

Now you can see the newly added device in the Bluetooth Devices window. There you can also see if the device is working properly or if it requires troubleshooting.

How to Send a File via Bluetooth

In order to send a file either right-click the Bluetooth icon from the system tray/notification area and select the 'Send a file' option or search for bluetooth in the Start Menu's search box and click on 'Bluetooth File Transfer'. Then select the 'Send a file' action.

Bluetooth

Now select the device to which you want to send a file from the computer and click on Next. In the next window, click on Browse to select the file that you want to send and then click on Next.

Bluetooth

Tip: Hold down the Shift or Ctrl key to select multiple files.
You might need to allow the transfer on your device as well, and only then the computer will connect with it and it will send the file. In the next window you will see a summary of the files that were delivered to the device through the Bluetooth connection. Click on Finish to exit the window.

Bluetooth

If you want to send other files, repeat the same steps as above.

How to Receive a File via Bluetooth

In order to receive a file from the device to your computer, you can either right-click the Bluetooth icon from the system tray or notification area and select 'Receive a file' or search for bluetooth in the Start Menu's search box and click on 'Bluetooth File Transfer'. Then select the 'Receive a File' option.

Bluetooth

Windows 7 will wait until you select a file on your device. Select the file to be sent to the computer through the Bluetooth connection, wait until the device finds the computer, select it, and then your computer will receive the file. In the next window you will see the name and the size of the file and you have to possibility to choose where to save it. Click on Browse to choose a different location than the default one and then click on Finish.

Bluetooth

The file is now received and stored in the location you selected.

Conclusion

As you can see, sending or receiving files through a Bluetooth connection is quite easy, even if some problems can happen. The lucky part is that the troubleshooting wizards are definitely better at offering solutions then those from Windows Vista and, when using them, you will get some good solutions to your problems.

The wide range of devices that have support for Bluetooth can be a disadvantage because Microsoft can't collect and deliver driver support for every product that has Bluetooth capabilities. That's why every topic about Bluetooth connections between devices and computers is full of people complaining about problems with the connection, drivers or anything in between. If you have problems, solutions or you know some great tips and tricks about Bluetooth connections don't hesitate to share them with us in a comment.


Connect two Computers using Cross Cable

 
Sharing the high Disk Space file between two computer is littel bit of difficult incase you don’t have high GB pen drive. Many use LAN Cable to connect the two computers but they can’t.

Here I bring you to How to connect two computers/Laptops using LAN Cable. so that you built your own network to share files, play counter strike, and much more…

Basic things required while building up a network are
LAN Cable with rj45 connectors
Computers/Netbook between the networking is to be done.

RJ45 is basically called as Register Jacket. It is a piece of plastic bound with different types of wires in a particular and sequential range for the purpose of running of different of different applications. This jack helps to enable you to ping with the other node.

We do networking by using TCP/IP ports. Each computer have its individual IP address. IP address are basically classified in 3 types A, B, C ranging from 1 to 225.

Class A – 0 to 127
Class B – 128 to 191
Class C – 192 to 223

Here are step which can help you to built a network at your home on your own.
  • The First and the basic step before setting up a network is to check whether LAN drivers are successfully installed on both the computers.
  • Insert the cable in connectors on both computers.
  • Go to Start>Control Panel>Network Connections>right click on Local Area Connection>properties>(TCP/IP)>properties.
  • Click on “use the following IP address“.
  • Remember you have to put IP addresses ranging from 1 to 254 only.
For instance you can put the following setting in first PC
IP address: 192.168.1.1
Subnet mask: 255.255.255.0 (appear default)
Default Gateway: Leave blank



Follow the same steps for the second PC but here you just have to change the IP address, for instance you can keep it 192.168.1.2 and other two kept same.




Save the settings for both the computers. To test whether both computers are connect we ping the each other IP. If you get a reply, then your network is setup successfully.

All are set, know enjoy sharing and gaming.

-Snehal-