Thursday, February 20, 2014

Sample Meeting Room Scheduler Design

Meeting Object

public class Meeting
{
    public long startTime;
    public long endTime;

    public Meeting(long sTime, long eTime)
    {
        startTime = sTime;
        endTime = eTime;
    }
}


Room Object

public class Room
{
    public List meetings;

    public Room()
    {
        meetings = new ArrayList();
    }
    public boolean tryScheduleMeeting(Meeting meeting)
    {
       for (Meeting scheduledMeeting : meetings) {
   if ((meeting.startTime < scheduledMeeting.endTime) && (meeting.endTime > scheduledMeeting.startTime))
                return false;
        }
     
        meetings.add(meeting);
        return true;
    }
}


Meeting Scheduler

public class Scheduler
{
    List rooms;

    public Scheduler()
    {
        rooms = new ArrayList();
    }
    public List scheduleMeetings(List meetings)
    {
       for (Meeting meeting : meetings)
        {
       
            boolean IsMeetingScheduled = false;
           for (Room room : rooms)
            {
                if (room.tryScheduleMeeting(meeting))
                {
                    IsMeetingScheduled = true;
                    break;
                }
            }

            if(!IsMeetingScheduled)
            {
                Room newRoom = new Room();
                newRoom.tryScheduleMeeting(meeting);
                rooms.add(newRoom);
            }
        }

        return rooms;
    }
 
    public static void main(String[] args)
    {
        List meetings = new ArrayList();
        Meeting m1 = new Meeting(8, 10);
        Meeting m2 = new Meeting(9, 10);
        Meeting m3 = new Meeting(10, 11);
        Meeting m4 = new Meeting(8, 12);

        meetings.add(m1);
        meetings.add(m2);
        meetings.add(m3);
        meetings.add(m4);

        Scheduler s = new Scheduler();
        List rooms = s.scheduleMeetings(meetings);
     
        System.out.println("Number of Rooms: "+ rooms.size());

        int i = 1;
        for (Room room : rooms)
        {
            System.out.println("Room: "+ i++);

            int j = 1;

            for(Meeting m : meetings)
            {
            System.out.println("Meeting: "+ j++);
            System.out.println("\tStart: "+ m.startTime);
            System.out.println("\t  End: "+ m.endTime);
           
            }
            System.out.println();
        }
    }
}

Thursday, February 6, 2014

7 Things Smart Learners Do Differently

They always learn.

People often divide their time between learning and non-learning. Learning is usually much more focused, dedicated time. Even our education systems are built around that concept — first we learn for several years, and then we work. Smart learners do it differently. They use every occasion to learn something new — about the food they eat, the way things work, different cultures, different roles in the same organization, history, and the people around them. The world is a great source of knowledge and skills, available 24/7, so they ask tons of questions and connect the dots.

They are good observers.

Walking or driving the same route hundreds of times does not guarantee that you will learn about all the buildings and other interesting things on the way. To do it, you have to look at the world with curiosity. Smart learners focus on the here and now, ready to observe the changes and the world surrounding them. They don’t have to talk much; they will instead ask questions.
They make mistakes.
Most people have a great fear of failure. It seems better not to do something rather than make a mistake. Smart learners exchange the word “mistake” with “lesson.” There is no better way to learn something than simply trying it, so experiment and observe. If one way didn’t work, try another one. Of course, sometimes many lessons have to be taken before something is mastered. As Thomas Edison said, “I have not failed 700 times. I have not failed once. I have succeeded in proving that those 700 ways will not work. When I have eliminated the ways that will not work, I will find the way that will work.”
They don’t give up too early.
With great fear of failure comes giving up too early. Today, we are tempted to try new things just a few times and then resign. When we can’t master something quickly, why bother? However, turn back time and imagine yourself as a child learning how to walk. How many times did you fall down in that process? Probably hundreds! Now you possess that great skill without thinking about it, but what would have happened if you had given up too early? Learning takes time and falling down often — smart learners understand that.
They connect with smart people.
The world is a big network of connections. Some of them are better quality than others, and your time on this planet is limited. Smart learners understand that they need high quality connections — people around them who will inspire them, shake their worlds, and ask good and deep questions. We learn best when we are relaxed and have a real friend and mentor around.
They try new things.
To be able to learn, our brain needs stimulation and then a good rest. Just look at how a small child explores the world, looks at everything with curiosity, then tries to put the pieces together and checks the taste. Later, the child “sleeps like a baby!” Smart learners possess that spark of curiosity and often try something new. Take part in some workshops or online courses, watch TED, and meet new people. They do some things differently and it keeps them from being bored.
They don’t think they are smart.
Smart learners don’t talk much. The knowledge and skills they have are not merely to impress others, but comes from their inner passion. They are humble enough to acknowledge how much they don’t know, and at the same time they feel good about and are energized by that. When they don’t know they don’t pretend to; they simply ask questions.
We all waste so much of our potential by not learning smart enough. Let us take the right lesson from smart learners. You life will definitely be more creative, happy, relaxed and full of passion.
JQuery - Deep and Shallow copy
Shallow copy
var newObject = jQuery.extend({}, oldObject);
Deep copy
var newObject = jQuery.extend(true, {}, oldObject);
Best Practices - Phishing scams

Never respond to emails that request personal financial information

Banks or e-commerce companies generally personalize emails, while phishers do not. Phishers often include false but sensational messages ("urgent - your account details may have been stolen") in order to get an immediate reaction. Reputable companies don't ask their customers for passwords or account details in an email. Even if you think the email may be legitimate, don't respond - contact the company by phone or by visiting their website. Be cautious about opening attachments and downloading files from emails, no matter who they are from. Sophos uses SPF (Sender Policy Framework). This is an anti-forgery solution which involves publishing a list detailing which servers are allowed to send Sophos emails.

Visit banks' websites by typing the URL into the address bar 

Phishers often use links within emails to direct their victims to a spoofed site, usually to a similar address such as mybankonline.com instead of mybank.com. When clicked on, the URL shown in the address bar may look genuine, but there are several ways it can be faked, taking you to the spoofed site. If you suspect an email from your bank or online company is false, do not follow any links embedded within it.

Keep a regular check on your accounts

Regularly log into your online accounts, and check your statements. If you see any suspicious transactions report them to your bank or credit card provider.

Check the website you are visiting is secure

Before submitting your bank details or other sensitive information there are a couple of checks you can do to help ensure the site uses encryption to protect your personal data:

Check the web address in the address bar. If the website you are visiting is on a secure server it should start with "https://" ("s" for security) rather than the usual "http://".

Also look for a lock icon on the browser's status bar. You can check the level of encryption, expressed in bits, by hovering over the icon with your cursor.

Note that the fact that the website is using encryption doesn't necessarily mean that the website is legitimate. It only tells you that data is being sent in encrypted form.

Be cautious with emails and personal data 

Most banks have a security page on their website with information on carrying out safe transactions, as well as the usual advice relating to personal data: never let anyone know your PINS or passwords, do not write them down, and do not use the same password for all your online accounts. Avoid opening or replying to spam emails as this will give the sender confirmation they have reached a live address. Use common sense when reading emails. If something seems implausible or too good to be true, then it probably is.

Keep your computer secure 

Some phishing emails or other spam may contain software that can record information on your internet activities (spyware) or open a 'backdoor' to allow hackers access to your computer (Trojans). Installing anti-virus software and keeping it up to date will help detect and disable malicious software, while using anti-spam software will stop phishing emails from reaching you. It is also important, particularly for users with a broadband connection, to install a firewall. This will help keep the information on your computer secure while blocking communication from unwanted sources. Make sure you keep up to date and download the latest security patches for your browser. If you don't have any patches installed, visit your browser's website, for example users of Internet Explorer should go to the Microsoft website.

Always report suspicious activity 
If you receive a suspicious email, forward it to the spoofed organization (many companies have a dedicated email address for reporting such abuse).

Your inputs are welcome....

Wednesday, February 5, 2014

For Java resources - 0 to 2 years

Java Static

Q. When are static variables loaded in memory ?
Correct Answer. Runtime, when the class is loaded.

Q. Difference between static and instance methods in memory ?
Correct Answer. Instance methods have context as refernce to the instance whereas static methods don't have.

Q. Does Java allow overriding static methods?
Correct Answer. No

Q. Can we serialize static members? 
Correct Answer. No.

Q. Can interface have static member variables?
Correct Answer. Yes.

Q. Can we declare an interface method static?
Correct Answer. No.

Q. Are Nested Interfaces static by default ?
Correct Answer. Yes.

Q. Can we have runtime polymorphism using static methods ?
Correct Answer. No.

Q. Which of the following is true ?
Correct Answer. Class cannot be declared static but nested class can be.

Q. Which of the following is true about static block ?
Correct Answer. It get's executed when the class is loaded.

Java abstract Classes and Interfaces

Q. Can we declare an interface method private ?
Correct Answer. No.

Q. Can interface have static members ?
Correct Answer. Static variables only.

Q. Can we declare a class abstract and final ?
Correct Answer. No.

Q. Can an interface extend another interface ?
Correct Answer. Yes

Q. Can a class implement multiple interfaces ?
Correct Answer. Yes

Q. Which of the following are marker interfaces ?
Correct Answer. Serializable.

Q. Interface method declarations are implicitly .. 
Correct Answer. public

Q. Do interfaces have constructors ?
Correct Answer. No.

Q. Can an interface be final ?
Correct Answer. No.

Q. We can nest interface within ..
Correct Answer. Both of them.

Struts  1+ Framework

Q.Struts is a
Correct Answer.Framework

Q.MVC is
Correct Answer.Design Pattern

Q.Which configuration files are used in struts for Validation Framework ?
Correct Answer.Validator-rules.xml and Validation.xml

Q.Which of following is true about Struts 1 and Struts 2
Correct Answer.Both a and b

Q.How many struts config file we can have ?
Correct Answer.Multiple

Q.Where do we specify servlet Mapping ?
Correct Answer.web.xml

Q.Where do we specify action Mapping ?
Correct Answer.struts-config,xml

Q.validate and Reset methods are defined in
Correct Answer.Form Beans

Q.What is controller in Struts ?
Correct Answer.Servlet

Q.How many instances of servlet usually run in a struts application
Correct Answer.1

#############################################################

Q. Which of the following is not true for abstract classes ?
Correct Answer. We can't have an abstract class without abstract methods.

Q. Which of the following is not true for static keyword ?
Correct Answer. We can override static methods.

Q. Which of the following is an Immutable Class ?
Correct Answer. String

Q. What is the difference between .equal and == ?
Correct Answer. == matches to see if they are same object whereas .equal matches the content of the objects.


Q. Which of the following is not the method of object class ?
Correct Answer. system

Q. Which of the following is True about final keyword ?
Correct Answer. We can't declare a class abstract as well as final.

Q. Which of the following is false about collections in Java ?
Correct Answer. list , Map and Set are abstract classes

Q. Which of the following is incorrect ?
Correct Answer. JVM is Java Visual Machine.

Q. Following are the class loaders used by JVM ?
Correct Answer. Bootstrap , Extension and Virtual

Q. Which of the following is not true for hashtable and hasmaps ?
Correct Answer. HashMaps are synchronized whereas hashtables are not.