Showing posts with label JAVA. Show all posts
Showing posts with label JAVA. Show all posts

Wednesday, 1 March 2017

Java collection Notes



Java Collections and Generics
·        The Java Collections Framework
·        Java Generics
13.1. The Java Collections Framework
·        Java arrays have limitations.
o   They cannot dynamically shrink and grow.
o   They have limited type safety.
o   Implementing efficient, complex data structures from scratch would be difficult.

·        The Java Collections Framework is a set of classes and interfaces implementing complex collection data structures.
o   collection is an object that represents a group of objects.

·        The Java Collections Framework provides many benefits:
o   Reduces programming effort (already there)
o   Increases performance (tested and optimized)
o   Part of the core API (available, easy to learn)
o   Promotes software reuse (standard interface)
o   Easy to design APIs based on generic collections

Monday, 15 August 2016

Sanfoundry 1000 Java MCQS Notes

Networking:
How many ports of TCP/IP are reserved for specific protocols?
1024

Which of these exception is thrown by URL class’s constructors?
MalformedURLException

Which of these methods is used to know the full URL of an URL object?
toExternalForm()

What is the output of this program?
                URL obj = new URL("http://www.sanfoundry.com/javamcq");
                System.out.print(obj.getPort());
Ans. -1

Which of these method of DatagramPacket is used to find the port number?
port()

Which of these method of DatagramPacket is used to obtain the byte array of data contained in a datagram?
getData()

Sunday, 7 August 2016

Java Random Notes


throws is used to postpone the handling of a checked exception and throw is used to invoke an exception explicitly. Mainly used for user defined exceptions.
public class className
{
   public void deposit(double amount) throws RemoteException
   {
      // Method implementation
      throw new RemoteException();
   }
   //Remainder of class definition
}

Monday, 3 August 2015

Core Java Technical Questions

What is the difference between a JDK and a JVM?
JDK is Java Development Kit which is for development purpose and it includes execution environment also. But JVM is purely a run time environment and hence you will not be able to compile your source files using a JVM.

What is the base class of all classes?
java.lang.Object and java.lang package is imported by default even without a package declaration.

Is Java a pure object oriented language?
Java uses primitive data types and hence is not a pure object oriented language.

Are arrays primitive data types?
In Java, Arrays are objects.

Monday, 20 July 2015

JAVA OOP Notes

1. Inheritance
public class Animal{
}
public class Mammal extends Animal{
}
public class Dog extends Mammal{   //Dog IS-A Animal as well 
}
instanceof shows if object belongs to class or not
The implements keyword is used by classes by inherit from interfaces. Interfaces can never be extended by the classes.
public interface Animal {}
public class Mammal implements Animal{
}
public class Dog extends Mammal{
}
Java only supports only single inheritance. This means that a class cannot extend more than one class. However, a class can implement one or more interfaces. This has made Java get rid of the impossibility of multiple inheritance.
Therefore following is illegal: public class extends Animal, Mammal{}

Friday, 17 July 2015

Java Basic Concept Notes

1.Basic Programme
import java.io.*;
public class MyFirstJavaProgram {
    public static void main(String []args) {
       System.out.println("Hello World");
    }
}
C : > javac MyFirstJavaProgram.java
C : > java MyFirstJavaProgram

2.Naming
Class Names - For all class names the first letter should be in Upper Case.
If several words are used to form a name of the class, each inner word's first letter should be in Upper Case.
Method Names - All method names should start with a Lower Case letter.
If several words are used to form the name of the method, then each inner word's first letter should be in Upper Case.
Program File Name - Name of the program file should exactly match the class name. There can be only one public class per source file.