Java Programing laungage

Core Java Tutorial

Introduction of Core Java

How To Install JDk and Set of Path

Syntax of java Program

Difference between Java and C/C++

Advantage and Disadvantage of Java

What is Java

Why Java is not Pure Object Oriented Language

Java has Following Features/Characteristics

Limitation of Java Language and Java Internet

Common Misconception about Java

Simple Program of Java

Integrated Development Environment in java

Compile and Run Java Program

Applet and Comments in Java

Tokens in Java

Keywords in Java

Identifier and Variables in Java

Literals/Constants

Data Type in Java

Assignments and Initialization in Java

Operators in Java

Rule of Precedence in Java

Operator on Integer and Separators in Java Programming

Java Control Flow of Statements

If and If-else Selection Statement

Nested If-else and If-else-If Selection Statement

switch case and conditional operator Selection Statement

for and while Loop

do..while and for each Loop

break and labeled break statement

continue and labeled continue statement

return Statement and exit() Method

Escape Sequence for Special Characters and Unicode Code

Constants and Block or Scope

Statement in Java

Conversions between Numeric Types in Java

Import Statement in Java

User Input in Java using Scanner Class

User Input in Java using Console Class

Array in Java

One Dimensional Array

Two Dimensional Array

Two Dimensional Array Program

Command Line Argument in Java

String args Types in Java

Uneven/Jagged array in java

Math Class Function and Constant

Math Class all Function used in a program

Enumerated Types in Java

Object Oriented Programming v/s Procedural Programming

Object Oriented Programming Concepts in Java

Introduction to Class,Object and Method in Java

Class Declaration in Java

Class & Objects in java

Encapsulation in Java

Modifiers/Visibility for a Class or Interrface or member of a Class

Polymorphism in Java

Runtime polymorphism (dynamic binding or method overriding)

jdk1.7 Interview Questions Answers
Previous Home Next
in jdk1.7 int data type allows underscore?

Sample.java

Before Jdk1.7

int datatype allows only numbers.

In Java1.7

int allows numbers and underscore.

So, it is easy to read the numbers. Especially when declare amount, in integer itís easy to read it and avoid confusion.

 import java.io.*;
class Sample
{
public static void main(String args[])throws IOException
{
int i;
//Java 7 allows underscore in integer
i=2386_49_5;
System.out.println(i);
}
}
in jdk 7 It doesnít need to specify the type of ArrayList at the end. yes or no ?

Yes

SampleArrayList

Before Java 7

List<String> al=new ArrayList<String>();

In Java 7

List<String> al=new ArrayList<>();

It doesnít need to specify the type of ArrayList at the end.

//SampleArrayList.java
 import java.util.*;
class SampleArrayList
{
public static void main(String args[])
{
List<String> a=new ArrayList<>();
a.add("one");
a.add("two");
System.out.println(a);
}
}

Output:

[one, two]

Java 7 allows String in switch statement. So, we can directly use strings in switch statement.Explain.

SampleSwitch.java

Before Java 7

String not allowed in switch statement. Switch allows only character and numeric. If we need to compare a string in switch statement, assign string values to an numeric and use it in switch statement.

In Java 7

//Java 7 allows String in switch statement.
 So, we can directly use strings in switch statement.
 //SampleSwitch.java
class SampleSwitch
{
public static void main(String args[])
{
String s="java";
//switch allows string from java7
switch(s)
{
case "java":
System.out.println("This is java");
break;
case "j2ee":
System.out.println("This is j2ee");
break;
}
}
}

Output:

This is java

Multiple catch can be handle in one catch statement. explain with example.?

SampleException.java

Before Java 7

catch(ArithmeticException e){}
catch(NumberFormatException){}
catch(NullPointerException){}
catch(IOException){}

In Java 7: catch(ArithmeticException|NumberFormatException|NullPointerException|IOException e){}

Itís more simple than the previous. Multiple catch can be handled in one catch statement.

//SampleException.java
import java.io.*;
class SampleException
{
public static void main(String args[])
{
try
{
DataInputStream d=new DataInputStream(System.in);
int a,b,c;
System.out.println("Enter First No.");
a=Integer.parseInt(d.readLine());
System.out.println("Enter Second No.");
b=Integer.parseInt(d.readLine());
c=a/b;
System.out.println("a/b= "+c);
}
//Multiple exception catch in single catch statement using "|" symbol.
catch(ArithmeticException|NumberFormatException|NullPointerException|IOException e)
{
System.out.println("this is exception"+e);
}
}
}

Output:

Enter First No.
4
Enter Second No.
this is exceptionjava.lang.NumberFormatException: For input string:
In jdk 7 Resources are need to be closed manually. After processing. yes or not explain ?

TryWithResource.java

Before Java 7

Resources are need to be closed manually. After processing.

In Java 7

It implements autoclosable method.

Close method run automatically.

Need not to close the resources manually.

TryWithResource.java

public class TryWithResource {
public static void main(String[] args) {
try(Resource res = new Resource("Resource closing")){
res.put("Listen to Put");
} catch(Exception e){
System.out.println("Exception: "+
e.getMessage()+" Thrown by: "+e.getClass().getSimpleName());
}
}
}

Resource.java

 class Resource implements AutoCloseable{
String closingMessage;
public Resource(String closingMessage) {
this.closingMessage = closingMessage;
}
public void put(String work) throws ExceptionA{
System.out.println(work);
throw new ExceptionA("ExceptionA");
}
public void close() throws ExceptionB{
System.out.println(closingMessage);
throw new ExceptionB("ExceptionB");
}
public void put(Resource res) throws ExceptionA{
res.put("Put method runs");
}
}

ExceptionA.java

public class ExceptionA extends Exception
{
public ExceptionA(String a)
{
super(a);
}
}

ExceptionB.java

public class ExceptionB extends Exception
{
public ExceptionB(String a)
{
super(a);
}
}

Output:

Listen to Put
Resource closing
Exception: ExceptionA Thrown by: ExceptionA

what is the diffrence b/w jdk1.6and jdk1.7 ?
  1. Java 1.6 runs faster than Java 1.5.
  2. Java 1.6 makes programming easier by implementing various tools such as SwingWorker and JTable to develop user interface.
  3. In java 1.6,Java DB, a new database management tool, has been included. Java DB is based on the open-source Apache Derby and is supported by Sun.
  4. Jdk 6 provides high performance, reliability, and UI improvements.
  5. Jdk 6 is having expanded monitoring and diagnositics capacities which delivers dramatic out-of-the-box benefits without any coding changes or even a re-compile necessary.
  6. Java SE 6 streamlines web service and XML development, simplifies GUI development and augments native desktop support, expands programmatic access to native security facilities, and is the first release to offer a standardized framework for scripting languages.
Previous Home Next