import java.net.InetAddress; import java.net.UnknownHostException; import java.util.Arrays; /* * @author Pandey */ public class IPAddress { public static void main(String args[]) { // First get InetAddress for the machine, here localhost InetAddress myIP = null; try { myIP = InetAddress.getLocalHost(); } catch (UnknownHostException e) { // TODO Auto-generated catch block e.printStackTrace(); } // getHostAddress() returns IP address of a machine String IPAddress = myIP.getHostAddress(); // getHostname returns DNS hostname of a machine String hostname = myIP.getHostName(); System.out.printf("IP address of Localhost is %s %n", IPAddress); System.out.printf("Host name of your machine is %s %n", hostname); } } Output: IP address of Localhost is 192.168.1.41 Host name of your machine is Jaachase
Thursday, 6 March 2014
How to Find IP address of Localhost, Server or Your Machine
Java interview question: Why Strings are immutable?
Lets start with immutability itself. An immutable object is an object which state is guaranteed to stay identical over its entire lifetime. This is really a good definition. Isn’t it? It means that the state of object once initialized, can never be changed anyhow.
Normally immutability in java is achieved through following steps :
1) Security : The first and undeniably most important reason is security. Well, its not only about your application, but even for JDK itself. Java class loading mechanism works on class names passed as parameters, then these classes are searched in class path. Imagine for a minute, Strings were mutable, then anybody could have injected its own class-loading mechanism with very little effort and destroyed or hacked in any application in a minute.
[ Well, I think in this case java didn't have got any popularity today...
and nobody would be using it]. It means Strings were immutable that’s why java is still around in the game.
2) Performance : I believe that it is not the immutability of String class that gives it performance, rather it is string pool which works silently behind the scene. But at the same time, string pool is not a possibility without making String class immutable. So, it all again comes down to immutability of String class which allowed string pools, and thus better performance.
3) Thread safety: Immutable objects are safe when shared between multiple threads in multi-threaded applications. Just understand and learn it. There is no super logic. If something can’t be changed, then even thread can not change it.
As String class is main building block of java programming language, because of its use in class loading mechanism, it was indeed a must use case to prevent the String class from being dirty in case of multiple thread. Immutability does the magic here.
I think its enough reasoning to satisfy the need of interviewer. If after these explanations he is not satisfied, he never will be
Normally immutability in java is achieved through following steps :
- Don’t provide mutator methods for any field
- Make all fields final and private
- Don’t allow subclasses by declaring the class final itself
- Return deep cloned objects with copied content for all mutable fields in class
1) Security : The first and undeniably most important reason is security. Well, its not only about your application, but even for JDK itself. Java class loading mechanism works on class names passed as parameters, then these classes are searched in class path. Imagine for a minute, Strings were mutable, then anybody could have injected its own class-loading mechanism with very little effort and destroyed or hacked in any application in a minute.
[ Well, I think in this case java didn't have got any popularity today...
2) Performance : I believe that it is not the immutability of String class that gives it performance, rather it is string pool which works silently behind the scene. But at the same time, string pool is not a possibility without making String class immutable. So, it all again comes down to immutability of String class which allowed string pools, and thus better performance.
3) Thread safety: Immutable objects are safe when shared between multiple threads in multi-threaded applications. Just understand and learn it. There is no super logic. If something can’t be changed, then even thread can not change it.
As String class is main building block of java programming language, because of its use in class loading mechanism, it was indeed a must use case to prevent the String class from being dirty in case of multiple thread. Immutability does the magic here.
I think its enough reasoning to satisfy the need of interviewer. If after these explanations he is not satisfied, he never will be
Sunday, 10 November 2013
How to Use An Antivirus Boot Disc or USB Drive to Ensure Your Computer is Clean
Why You Should Use an Antivirus Boot Disc
Antivirus boot discs deal with this by approaching the malware from outside Windows. You boot your computer from a CD or USB drive containing the antivirus and it loads a specialized operating system from the disc. Even if your Windows installation is completely infected with malware, the special operating system won’t have any malware running within it.This means the antivirus program can work on the Windows installation from outside it. The malware won’t be running while the antivirus tries to remove it, so the antivirus can methodically locate and remove the harmful software without it interfering.
Any rootkits won’t be able to set up the tricks they use at Windows boot time to hide themselves from the rest o the operating system. The antivirus will be able to see the rootkits and remove them.
These tools are often referred to as “rescue disks.” They’re meant to be used when you need to rescue a hopelessly infected system.
Bootable Antivirus Options
As with any type of antivirus software, you have quite a few options. Many antivirus companies offer bootable antivirus systems based on their antivirus software. These tools are generally free, even when they’re offered by companies that specialized in paid antivirus solutions. Here are a few good options:- avast! Rescue Disk – We like avast! for offering a capable free antivirus with good detection rates in independent tests. avast! now offers the ability to create an antivirus boot disc or USB drive. Just navigate to the Tools -> Rescue Disk option in the avast! desktop application to create bootable media.
- BitDefender Rescue CD – BitDefender always seems to receive good scores in independent tests, and the BitDefender Rescue CD offers the same antivirus engine in the form of a bootable disc.
- Kaspersky Rescue Disk – Kaspersky also receives good scores in independent tests and offers its own antivirus boot disc.
How to Use an Antivirus Boot Disc
Using an antivirus boot disc or USB drive is actually pretty simple. You’ll just need to find the antivirus boot disc you want to use and burn it to disc or install it on a USB drive. You can do this part on any computer, so you can create antivirus boot media on a clean computer and then take it to an infected computer.Insert the boot media into the infected computer and then reboot. The computer should boot from the removable media and load the secure antivirus environment. (If it doesn’t, you may need to change the boot order in your BIOS or UEFI firmware.) You can then follow the instructions on your screen to scan your Windows system for malware and remove it. No malware will be running in the background while you do this.
Antivirus boot discs are useful because they allow you to detect and clean malware infections from outside an infected operating system. If the operating system is severely infected, it may not be possible to remove — or even detect — all the malware from within it.
Sunday, 15 September 2013
Why Does RAM Have to be Volatile?
The Answer
it’s due to physics.In other words, the only way to make the RAM as high speed as we need it for modern computer operations is to keep the resistance between state changes extremely low (and thus make the RAM volatile and susceptible to data erasure in the face of power loss).
Any non-volatile memory must store its bits in two states which have a large energy barrier between them, or else the smallest influence would change the bit. But when writing to that memory, we must actively overcome that energy barrier.
Designer have quite some freedom in setting those energy barriers. Set it low0 . 1, and you get memory which can be rewritten a lot without generating a lot of heat: fast and volatile. Set the energy barrier high0 | 1and the bits will stay put almost forever, or until you expend serious energy.
DRAM uses small capacitors which leak. Bigger capacitors would leak less, be less volatile, but take longer to charge.
Flash uses electrons which are shot at high voltage into an isolator. The energy barrier is so high that you can’t get them out in a controlled way; the only way is to clean out an entire block of bits.
RAM Is Cheap So Why Don’t We Run Everything From It?
The Answer
There are a few reasons RAM is not used that way:
- Common desktop (DDR3) RAM is cheap, but not quite that cheap. Especially if you want to buy relatively large DIMMs.
- RAM loses its contents when powered off. Thus you would need to reload the content at boot time. Say you use a SSD sized RAMDISK of 100GB, that means about two minutes delay while 100GB are copied from the disk.
- RAM uses more power (say 2–3 Watt per DIMM, about the same as an idle SSD).
- To use so much RAM, your motherboard will need a lot of DIMM sockets and the traces to them. Usually this is limited to six or less. (More board space means more costs, thus higher prices.)
- Lastly, you will also need RAM to run your programs in, so you will need the normal RAM size to work in (e.g. 18GiB, and enough to store the data you expect to use).
Sunday, 11 August 2013
How to Browse the Web Anonymously On Your Android Smartphone
When you access a website on your smartphone, your cellular carrier,
network operator, and government all know you accessed that website. If
you’re in a country that blocks websites
, like China, you may not even be able to access certain websites. Tor allows you to browse anonymously and bypass web censorship on your desktop. Orbot brings Tor to Android, so you can do the same from your smartphone.
Whether you’re connected to a cellular data connection or Wi-Fi, Orbot works the same. Like the Tor browser bundle for PCs, it connects to the Tor network and allows you to browse the web anonymously.


Bear in mind that Tor is significantly slower than a standard connection for browsing, as the routing process adds some overhead
, like China, you may not even be able to access certain websites. Tor allows you to browse anonymously and bypass web censorship on your desktop. Orbot brings Tor to Android, so you can do the same from your smartphone.
Whether you’re connected to a cellular data connection or Wi-Fi, Orbot works the same. Like the Tor browser bundle for PCs, it connects to the Tor network and allows you to browse the web anonymously.
Connect to Tor With Orbot
Bear in mind that Tor is significantly slower than a standard connection for browsing, as the routing process adds some overhead
Wednesday, 1 May 2013
[rexofcyber explain] ::What Is The Difference Between DDR2 & DDR3 RAM
RAM or Random Access Memory,
is your computer’s short term memory. If your computer needs
information and does not find the RAM, it then needs to journey to the hard drive
to try and retrieve the data, which is far more time consuming. Many
older computers that feel sluggish can be given new life if upgraded
with additional RAM.
However, capacity is only one specification. RAM is also available in a variety of versions and speeds. A 2GB stick of DDR2 800 RAM is not the same thing as a 2GB stick of DDR3 1333 RAM. Understanding the difference is important because computers will generally accept only certain types of RAM.
However, capacity is only one specification. RAM is also available in a variety of versions and speeds. A 2GB stick of DDR2 800 RAM is not the same thing as a 2GB stick of DDR3 1333 RAM. Understanding the difference is important because computers will generally accept only certain types of RAM.
Subscribe to:
Posts (Atom)