Monday 27 May 2013

interface in java

An interface in the Java Programming language is an abstract type that is used to specify an interface(in the generic sense of the term) that classes must implement.
Interfaces are declared using the interface keyword, and may only contain method signature and constant declarations (variable declarations that are declared to be both static and final).
An interface never contain method definitions.
Interfaces cannot be instantiated, but rather are implemented.
A class that implements an interface must implement all of the methods described in the interface, or be an abstract class. Object references in Java may be specified to be of an interface type; in which case, they must either be null, or be bound to an object that implements the interface.
One benefit of using interfaces is that they simulate multiple inheritance. All classes in Java must have exactly one base class, the only exception being java.lang.Object(the root class of the Java type system); multiple classes of classes is not allowed.
A Java class may implement, and an interface may extend, any number of interfaces; however an interface may not implement an interface.
Example:

Program:
interface B {
}
interface C extends B {
}
interface D extends B, C {
}
interface E {
}
class Simple implements B, C, D {
}
public class A {
public static void main(String[] args) {
}
}
Which is not possible in interface?
We cant implement an interface with interface
interface B {
}
interface C implements B {
}
CTE--->Compile Time Error

CTE:Syntax error on token "implements", extends expected

interface B {
public void study(){
}
}
CTE:Abstract methods do not specify a body
Remove method body

Program:
interface B {
public void study();
}

class Simple implements B {

@Override
public void study() {
System.out.println("Hai i am the impl for study method in interface B");
}
}
public class A {
public static void main(String[] args) {
B b=new B();
}
}
Cannot instantiate the type B

Program:
interface B {
public void study();
}
class Simple implements B {
}
public class A {
public static void main(String[] args) {
Simple s = new Simple();
s.study();
}
}
--->the type Simple must implement the inherited abstract method B.study()
Solution:
interface B {
public void study();
}
class Simple implements B {
@Override
public void study() {
System.out.println("Hai i am in impl for study method in interface B");
}
}
public class A {
public static void main(String[] args) {
Simple s = new Simple();
s.study();
}
}
O/P:Hai i am in impl for study method in interface B

Major Points in interface:
possible:
interface extends interface
interface extends interface1,interface2
class implements interface
class implements interface1,interface2
interface B {
}
interface C extends B {
}
interface D extends B, C {
}
interface E {
}
class Sam implements B{
}
class Simple implements B,C{
}
public class A {
public static void main(String[] args) {
}

}

Important packages in core java

java.io
Provides for system input and output through data streams, serialization and the file system.

java.lang

Provides classes that are fundamental to the design of the Java programming language.

java.util

Contains the collections framework, legacy collection classes, event model, date and time facilities, internationalization, and miscellaneous utility classes (a string tokenizer, a random-number generator, and a bit array).

java.sql

Provides the API for accessing and processing data stored in a data source (usually a relational database) using the Java programming language.

java.awt

Contains all of the classes for creating user interfaces and for painting graphics and images.

java.applet

Provides the classes necessary to create an applet and the classes an applet uses to communicate with its applet context.

java.beans

Contains classes related to developing beans -- components based on the JavaBeansTM architecture.

java.math

Provides classes for performing arbitrary-precision integer arithmetic (BigInteger) and arbitrary-precision decimal arithmetic (BigDecimal).

java.net

Provides the classes for implementing networking applications.

java.nio

Defines buffers, which are containers for data, and provides an overview of the other NIO packages.

java.security

Provides the classes and interfaces for the security framework.

java.text


Provides classes and interfaces for handling text, dates, numbers, and messages in a manner independent of natural languages.

Saturday 25 May 2013

constraints in sql

Constraints are used to prevent in valid data entry into our tables.Constraints are created on table columns.Oracle server supports following types
1)not null
2)unique
3)primary key
4)foreign key
5)check
All the above constraints are defined in 2 levels
i)column level
ii)table level

I)All constraints information stored under user_constraints(data dictionary)
SQL>desc user_constraints
Query:select constraint_type,constraint_name from user_constraints where table_name='EMP';(EMP should be capital)
II)If we want to view constraint names along with column names we are using USER_CONS_COLUMNS.
SQL>desc user_cons_columns
Query:select constraint_type,column_name from user_cons_columns where table_name='EMP';
III)If we want to view logical condition of the check constraint we are using  search_condition property from user_contraints
SQL>desc user_constraints;
Query:select constraint_name,constraint_type,search_condition  from user_constraints where table_name='EMP';



Screen shot program


//By using this program you can take screen shot with gif format.After completion of that run as java application enter as a.gif  and refresh in the java project

import javax.swing.*;
import javax.imageio.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.io.*;

public class Screenshot {
public static void main(String[] args) throws Exception {
Screenshot ss = new Screenshot();
}

public Screenshot() {
JFrame frame = new JFrame("Screen Shot Frame.");
JButton button = new JButton("Capture Screen Shot");
button.addActionListener(new MyAction());
JPanel panel = new JPanel();
panel.add(button);
frame.add(panel, BorderLayout.CENTER);
frame.setSize(400, 400);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}

public class MyAction implements ActionListener {
public void actionPerformed(ActionEvent ae) {
try {
String fileName = JOptionPane.showInputDialog(null,
"Enter filename : ", "developer", 1);
if (!fileName.toLowerCase().endsWith(".gif")) {
JOptionPane.showMessageDialog(null,
"Error: file name must end with \".gif\".",
"developer", 1);
} else {
Robot robot = new Robot();
BufferedImage image = robot
.createScreenCapture(new Rectangle(Toolkit
.getDefaultToolkit().getScreenSize()));
ImageIO.write(image, "gif", new File(fileName));
JOptionPane.showMessageDialog(null,
"Screen capturedsuccessfully.", "developer", 1);
}
} catch (Exception e) {
}
}
}
}

Tuesday 21 May 2013

Increase java heap size tomcat eclipse


  • Open the server tab in eclipse
  • right click open
  • click on open lauch configuration
  • Go to arguments
  • Here you can add in VM arguments after endorsed
    -Xms64m -Xmx256m

Increase java heap memory in eclipse


It is possible to increase heap size allocated by the JVM in eclipse directly In eclipse IDE goto
Run---->Run Configurations---->Arguments
Enter -Xmx1g(It is used to set the max size like Xmx256m or Xmx1g...... m-->mb g--->gb)



increase java heap memory command prompt

It is possible to increase heap size allocated by the JVM by using command line options Here we have 3 options

-Xms<size>        set initial Java heap size
-Xmx<size>        set maximum Java heap size
-Xss<size>        set java thread stack size

java -Xms16m -Xmx64m ClassName
In the above line we are setting minimum heap to 16mb and maximum heap 64mb