Pages

Wednesday, October 23, 2013

Difference Between Java & C++

 The Important and Main Difference Between The Java And C++ Programming Language.

main function

C++

// free-floating function
int main( int argc, char* argv[])
{
    printf( "Hello, world" );
}

Java

// every function must be part of a class; the main function for a particular
// class file is invoked when java <class> is run (so you can have one
// main function per class--useful for writing unit tests for a class)
class HelloWorld
{
    public static void main(String args[])
    {
        System.out.println( "Hello, World" );
    }
}

Compiling

C++

    // compile as
    g++ foo.cc -o outfile
    // run with
    ./outfile
    

Java

    // compile classes in foo.java to <classname>.class
    javac foo.java 

    // run by invoking static main method in <classname>
    java <classname>
    

Comments

Same in both languages (// and /* */ both work)

Class declarations

Almost the same, but Java does not require a semicolon

C++

    class Bar {};
    

Java

    class Bar {}
    

Method declarations

Same, except that in Java, must always be part of a class, and may prefix with public/private/protected

Constructors and destructors

Constructor has same syntax in both (name of the class), Java has no exact equivalent of the destructor

Static member functions and variables

Same as method declarations, but Java provides static initialization blocks to initialize static variables (instead of putting a definition in a source code file):
class Foo 
{
    static private int x;
    // static initialization block
    { x = 5; }
}

Scoping static methods and namespaces

C++

If you have a class and wish to refer to a static method, you use the form Class::method.
class MyClass
{
    public:
    static doStuff();
};

// now it's used like this
MyClass::doStuff();

Java

All scoping in Java uses the . again, just like accessing fields of a class, so it's a bit more regular:
class MyClass
{
    public static doStuff()
    {
        // do stuff
    }
}

// now it's used like this
MyClass.doStuff();

Object declarations

C++

    // on the stack
    myClass x;

    // or on the heap
    myClass *x = new myClass;
    

Java

    // always allocated on the heap (also, always need parens for constructor)
    myClass x = new myClass();
    

Accessing fields of objects

C++

If you're using a stack-based object, you access its fields with a dot:
myClass x;
x.my_field; // ok
But you use the arrow operator (->) to access fields of a class when working with a pointer:
myClass x = new MyClass();
x->my_field; // ok

Java

You always work with references (which are similar to pointers--see the next section), so you always use a dot:
myClass x = new MyClass();
x.my_field; // ok

References vs. pointers

C++

    // references are immutable, use pointers for more flexibility
    int bar = 7, qux = 6;
    int& foo = bar;
    

Java

    // references are mutable and store addresses only to objects; there are
    // no raw pointers
    myClass x;
    x.foo(); // error, x is a null ``pointer''

    // note that you always use . to access a field
    

Inheritance

C++

    class Foo : public Bar
    { ... };
    

Java

    class Foo extends Bar
    { ... }
    

Protection levels (abstraction barriers)

C++

    public:
        void foo();
        void bar();
    

Java

    public void foo();
    public void bar();
    

Virtual functions

C++

    virtual int foo(); // or, non-virtually as simply int foo();
    

Java

    // functions are virtual by default; use final to prevent overriding
    int foo(); // or, final int foo();
    

Abstract classes

C++

    // just need to include a pure virtual function
    class Bar { public: virtual void foo() = 0; };
    

Java

    // syntax allows you to be explicit!
    abstract class Bar { public abstract void foo(); }

    // or you might even want to specify an interface
    interface Bar { public void foo(); }

    // and later, have a class implement the interface:
    class Chocolate implements Bar
    {
        public void foo() { /* do something */ }
    }
    

Memory management

Roughly the same--new allocates, but no delete in Java since it has garbage collection.

NULL vs. null

C++

    // initialize pointer to NULL
    int *x = NULL;
    

Java

    // the compiler will catch the use of uninitialized references, but if you
    // need to initialize a reference so it's known to be invalid, assign null
    myClass x = null;
    

Booleans

Java is a bit more verbose: you must write boolean instead of merely bool.

C++

bool foo;

Java

boolean foo;

Const-ness

C++

    const int x = 7;
    

Java

    final int x = 7;
    

Throw Spec

First, Java enforce throw specs at compile time--you must document if your method can throw an exception

C++

int foo() throw (IOException)

Java

int foo() throws IOException

Arrays

C++

    int x[10];
    // or 
    int *x = new x[10];
    // use x, then reclaim memory
    delete[] x;
    

Java

    int[] x = new int[10];
    // use x, memory reclaimed by the garbage collector or returned to the
    // system at the end of the program's lifetime
    

Collections and Iteration

C++

Iterators are members of classes. The start of a range is <container>.begin(), and the end is <container>.end(). Advance using ++ operator, and access using *.
    vector myVec;
    for ( vector<int>::iterator itr = myVec.begin();
          itr != myVec.end();
          ++itr )
    {
        cout << *itr;
    }
    

Java

Iterator is just an interface. The start of the range is <collection>.iterator, and you check to see if you're at the end with itr.hasNext(). You get the next element using itr.next() (a combination of using ++ and * in C++).
    ArrayList myArrayList = new ArrayList();
    Iterator itr = myArrayList.iterator();
    while ( itr.hasNext() )
    {
        System.out.println( itr.next() );
    }

    // or, in Java 5
    ArrayList myArrayList = new ArrayList();
    for( Object o : myArrayList ) {
        System.out.println( o );
    } 
 
 
 
Differences between Java and C++ are:
Java
C++
Java is a true and complete object oriented language.
C++ is an extension of C with object oriented behavior. C++ is not a complete object oriented language as that of Java.
Java does not provide template classes.
C++ offers Template classes.
Java supports multiple inheritance using interface.
C++ achieves multiple inheritance by permitting classes to inherit from multiple classes.
Java does not provide global variables.
Global variables can be declared in C++.
Java does not support pointers.
C++ supports pointers.
In Java, destruction of objects is performed in finalize method.
In C++, destruction of objects is performed by destructor function.
Java doesn’t provide header files.
C++ has header files.

 

Monday, October 21, 2013

some info about Java

Hello All ,
 This is my  post about Java. Everything has its own and very popular history. So when I think about java  the very first question arrived in my mind is how and why java ? Because we have c with us for the core programming and we have c++ for the entire object oriented concept. After going through a long discussion and from the internet I founded some facts which are sufficient for my queries.

So Let' start with my first question

How we got java?

  • Java was created by a team led by James Gosling for Sun Microsystems, James Gosling, Mike Sheridan, and Patrick Naughton initiated the Java language project in June 1991. Java was originally designed for interactive television, but it was too advanced for the digital cable television industry at the time.

  • The language was initially called Oak after an oak tree that stood outside Gosling's office; it went by the name Green later, and was later renamed Java, from Java coffee, said to be consumed in large quantities by the language's creators. However, when Java 1.0 was released to the public in 1996, its main focus had shifted to use on the Internet.java language derives much of its syntax from c and c++ but has a simpler object model and fewer low-level facilities.

  • Java is a fully functional, platform independent, programming language it has powerful set of machine independent libraries, including windowing (GUI) libraries.Java applications are typically compiled to byte code (class file) that can run on any Java Virtual Machine (JVM) regardless of computer architecture.

  • The most interested thing about java is "write once, run anywhere" (WORA), meaning the code that runs on one platform does not need to be recompiled to run on another.

Why java ?


  • One characteristic of Java is portability, which means that computer programs written in the Java language must run similarly on any hardware/operating-system platform. This is achieved by compiling the Java language code to an intermediate representation called Java byte code, instead of directly to platform-specific machine code.

  • Java byte code instructions are analogous to machine code, but are intended to be interpreted by a virtual machine (VM) written specifically for the host hardware. End-users commonly use a Java Runtime Environment (JRE) installed on their own machine for standalone Java applications.

  • Java is very powerful language but it has its own pros and cons too. so lets discuss some strong and weak points of java.
Pros

  1.     Free.
  2.     The syntax is familiar to the programmers that know any other C based language.
  3.  Java (the platform) has a very large and standard class library, some parts of which are very well written.
  4. Java provides a platform for behavioral transfer from one address space to another. This is particularly evident in the dynamic class loading mechanisms of RMI (Remote Method Invocation).
  5.  Automatic Memory Management implemented by Garbage Collection
  6. Explicit Interfaces
  7. Improving performance
  8. Good portability (certainly better than that of nearly any compiled alternative)
  9. Simplified syntax (compared to C++
  10. Language design not committee driven
  11.  Lots of available code and third-party libraries
    If you love OOP, the only way to write functions is to make them class methods.
    Many standard interfaces defined in the standard library, which would have been vendor/OS specific otherwise, helps a lot in achieving portability and ease integration/selection of 3rd party libraries. E.g. JDBC, JMS, JCE, JAI, serial I/O, JAXP, JNDI, etc. Some have correspondence in other languages (e.g. ODBC) but not all.

Cons

    Performance: Java can be perceived as significantly slower and more memory-consuming than natively compiled languages such as C or C++.

    Look and feel: The default look and feel of GUI applications written in Java using the Swing toolkit is very different from native applications. It is possible to specify a different look and feel through the pluggable look and feel system of Swing.

    Single-paradigm language: Java is predominantly a single-paradigm language. However, with the addition of static imports in Java 5.0 the procedural paradigm is better accommodated than in earlier versions of Java.


So , this is all about java from my side. This are some very  basic things about java . I hope it will give all of u a good  start with java.

Source: wikipedia and my own work :)

Tuesday, September 24, 2013

10 Toughest Interview Questions: Answered

  • Why Should I Hire You?

The most overlooked question is also the one most candidates are unprepared to answer. This is often because job applicants don't do their homework on the position. Your job is to illustrate why you are the most qualified candidate. Review the job description and qualifications very closely to identify the skills and knowledge that are critical to the position, then identify experiences from your past that demonstrate those skills and knowledge.

  • Why Is There A Gap In Your Work History?

Employers understand that people lose their jobs and it's not always easy to find a new one fast. When answering this question, list activities you'??ve been doing during any period of unemployment. Freelance projects, volunteer work or taking care of family members all let the interviewer know that time off was spent productively.


  • Tell Me One Thing You Would Change About Your Last Job

Beware over sharing or making disparaging comments about former coworkers or supervisors, as you might be burning bridges. But an additional trouble point in answering this query is showing yourself to be someone who can'??t vocalize their problems as they arise. Why didn'??t you correct the issue at the time? Be prepared with an answer that doesn't criticize a colleague or paint you in an unflattering light. A safe scapegoat? Outdated technology.

  • Tell Me About Yourself

People tend to meander through their whole resumes and mention personal or irrelevant information in answering--a serious no-no. Keep your answer to a minute or two at most. Cover four topics: early years, education, work history, and recent career experience. Emphasize this last subject. Remember that this is likely to be a warm-up question. Don't waste your best points on it. And keep it clean--??no weekend activities should be mentioned.
  • Explain A Complex Database To Your Eight-Year-Old Nephew

Explaining public relations, explaining mortgages, explaining just about anything in terms an eight-year-old can understand shows the interviewer you have solid and adaptable understanding of what it is they do. Do your homework, know the industry and be well-versed.
  • What Would The Person Who Likes You Least In The World Say About You?

Highlight an aspect of your personality that could initially seem negative, but is ultimately a positive. An example? Impatience. Used incorrectly this can be bad in a workplace. But stressing timeliness and always driving home deadlines can build your esteem as a leader. And that'??s a great thing to show off in an interview.

  • Tell Me About A Time When Old Solutions Didn't Work

The interviewer is trying to identify how knowledgeable you are in today'??s work place and what new creative ideas you have to solving problems. You may want to explore new technology or methods within your industry to be prepared for. Twitter-phobes, get tweeting. Stat.

  • What's The Biggest Risk You've Ever Taken?

Some roles require a high degree of tenacity and the ability to pick oneself up after getting knocked down. Providing examples of your willingness to take risks shows both your ability to fail and rebound, but also your ability to make risky or controversial moves that succeed.
  • Have You Ever Had A Supervisor Challenge A Decision?

Interviewers are looking for an answer that shows humility--??and the ability to take direction. The anecdote should be telling, but it'??s the lesson learned, not the situation, that could land you the job.
  • Describe A Time When Your Team Did Not Agree

Questions pertaining to difficulties in the past are a way for employers to anticipate your future behavior by understanding how you behaved in the past and what you learned. Clarify the situation succinctly and explain what specific action you took to come to a consensus with the group. Then describe the result of that action.

Hope u friends u make cross by learning 10 Toughest Interview Questions: Answered


Top Gadgets that Changed the world......!

Top  Gadgets that Changed the world......!
  •  Light Bulb

It was invented by as many as 23 people, most notably Thomas Edison, who patented his system in 1878. His first bulb used a carbon filament and lasted 13.5 hours; early incandescent bulbs were assembled by hand.
 
  • Alarm Clock

Alarm clocks predate the Seth Thomas brand by centuries, but the clockmaker's 1876 model fit on a nightstand and helped drag the Industrial Revolution out of bed. 
 
  •  Telephone

Alexander Graham Bell's interest in the education of deaf people-he began teaching at the Boston School for Deaf Mutes in 1871-led him to invent the microphone and, in 1876, the telephone, which he called the "electrical speech machine." In a 1912 issue of Popular Mechanics, Bell said, "To tell the truth, as a practical man, I did not quite believe it; as a theoretical man, I saw a speaking telephone by which we could have the means of transmitting speech and reproducing it in distant places. But it really seemed too good to be true, that one could possibly create, by the action of the voice itself, electrical impulses intense enough to serve any practical purpose." The device debuted at the Centennial Exhibition in Philadelphia in 1876, leading Brazilian Emperor Dom Pedro to exclaim: "My God, it talks!"

  •  Personal Computer

The forerunners of modern personal computers were introduced in the mid-1970s as kits. Little did pioneers like Bill Gates and Paul Allen, who wrote programming language for the MITS Altair 8800 kit, or Steve Jobs and Steve Wozniak, who designed the skeletal Apple I, know what was in store. The Apple II, which debuted in 1977 with color graphics and an attachable floppy disk drive, ushered in a new technological era-and when IBM introduced its Personal Computer in 1981, the PC began its slow acceptance as a crucial business tool instead of merely a geeky toy. In 1983, there were 10 million personal computers in the U.S.; today 80 percent of American households have a notebook or PC, creating unprecedented levels of efficiency, capability, and access to news, music and entertainment. 
 
  • Hypodermic Syringe

The promise of the hollow needle, invented in 1844, was realized a century later as injected vaccines spared millions from polio, tuberculosis, rabies and more.
 

  •  Television

The origins of television stretch back to the late 19th century, to a time before it was even technically feasible. In 1877, civil servant George Carey was already sketching drawings for a "selenium camera" that would allow people to "see by electricity;" at the same time, Thomas Edison and Alexander Graham Bell were theorizing about telephones that could transmit images along with sound. Modern television was demonstrated in 1939 at the New York World's Fair-and soon TV beamed dramatic images of the Civil Rights movement; political debate and casualties of war; astronauts, pop musicians, sports heroes and more directly into American living rooms. In 1949, fewer than 1 million U.S. households had a TV; four years later, that number had ballooned to 25 million. For a half-century, TV has stood as the No. 1 source for Americans' news and entertainment, and today, 99 percent of U.S. households have a TV. We spend an average of 2.8 hours per day watching them.
  • Radio
Police switchboards jammed. Drivers fled cities. Doctors volunteered to treat the injured. Why all the ruckus? On Oct. 30, 1938-the day before Halloween-Orson Welles presented a radio play he based on H.G. Wells's sci-fi novel The War of the Worlds. The Mercury Theatre on the Air presentation sounded like a news broadcast of a Martian invasion, complete with fake bulletins that interrupted dance music. The resulting hysteria dramatically revealed the power of gadget No. 2, the first instrument of instant mass communication. Patented in England in 1896 as "wireless telegraphy" by Guglielmo Marconi-who based his work on technology developed by Nikola Tesla-radios were in 80 percent of U.S. homes by the time those aliens landed in New Jersey.
  •  Mobile/Smartphone

With origins tracing back to Finland and Japan in the '70s, mobile phones have fast become the most widely used gadgets in the world. The first billion units sold in 20 years, the second billion in four and the third billion in two. By the end of 2010, the subscription rate stood at 5 billion, or 75 percent of all people on earth. The tech leaped forward in 1983 with the Motorola DynaTAC 8000X, the first truly portable cellphone. The smartphone, with us since 2000, is now a pocket-size PC. Wireless and GPS- and multimedia-enabled, it facilitates instantaneous personal connections that make phone conversations seem like cave paintings. People of developing nations, even those without an electrical grid, can tap into the world's commerce and culture. After a scant 11 years of development, the device seems to have limitless potential.