Category Archives: Java

Java 8 : Lambda in Functional Interfaces

Lambda expressions in Java is usual written using syntax (argument) -> (body).

Functional Interface is an interface with just one abstract method declared in it.

Example:

ActionListener Interface
Runnable Interface
We generally use Anonymous inner classes to instantiate objects of functional interface but with the help of Lambda expressions, this can be simplified.

1

 

 

 

 

 

 

 

Output:

2

Leave a comment

Filed under Java

Java Classes and Objects – Tutorial 2

1. Creating Objects.

2. Creating Class in the same File.

3. Default value of the Class instance variable and Local variable.

Code:

/*

Student Class

*/

public class Student {

private int id;
private String name;

public void setData(int tid,String tname)
{
id=tid;
name=tname;
}

public void display()
{
int testing=0;

System.out.println(“\n ID is:”+id);
System.out.println(“\n Name is:”+name);

System.out.println(testing);     //Not allowed without initialization
}
}

/*

Employee Class

*/
class Employee {

private int id;
private String name;

public void setData(int tid,String tname)
{
id=tid;
name=tname;
}

public void display()
{
System.out.println(“\nEmployee ID is:”+id);
System.out.println(“\nEmpoyee Name is:”+name);
}
}

/*

MainClass Class

*/
public class MainClass {

public static void main(String args[])
{
//Student Class
Student stuobj1=new Student(); //[ID/Name]

stuobj1.setData(1, “Vinod Pillai”);
stuobj1.display();

Student stuobj2;    //Reference created.

stuobj2=new Student(); //Memory is allocated now. [ID/Name]
stuobj2.display();        //Default values.
stuobj2.setData(2, “Vinod”);
stuobj2.display();

//Employee Class
Employee eobj=new Employee();
eobj.setData(1, “AbcXyz”);
eobj.display();
}
}

http://www.youtube.com/vinodthebest

Leave a comment

Filed under Java

Java Hello World – Tutorial 1

1. Java is an Object Oriented Programming language.

2. Importance of Class.

3. Creating simple “Hello World Application”.

4. Running the program.

5. Java works in two stage “Compiler and Interpreter” in Java.

Code:

public class MainClass
{
public static void main(String args[])
{
System.out.println(“\n Hello World \n”);
}
}
Prof. Vinod Pillai.
vinodthebest@gmail.com

http://www.youtube.com/vinodthebest

Leave a comment

Filed under Java

Creating Java Project in Eclipse IDE

Website for Eclipse IDE [http://eclipse.org/downloads/]

1. Creating Java Project in Eclipse.

2. Creating Package in Eclipse.

3. Creating class in Eclipse.

4. Running the java project in Eclipse.

Leave a comment

Filed under Java

Oracle Java SE Critical Patch Update

Description
This Critical Patch Update Pre-Release Announcement provides advance information about the Oracle Critical Patch Update for June 2012, which will be released on Tuesday, June 12, 2012. While this Pre-Release Announcement is as accurate as possible at the time of publication, the information it contains may change before publication of the Critical Patch Update Advisory.

This Critical Patch Update is a collection of patches for multiple security vulnerabilities in Oracle Java SE. This Critical Patch Update contains 14 new security vulnerability fixes. Due to the threat posed by a successful attack, Oracle strongly recommends that customers apply Critical Patch Update fixes as soon as possible.

Affected Products and Components
Security vulnerabilities addressed by this Critical Patch Update affect the following products:

  1. JDK and JRE 7 Update 4 and earlier
  2. JDK and JRE 6 Update 32 and earlier
  3. JDK and JRE 5.0 Update 35 and earlier
  4. SDK and JRE 1.4.2_37 and earlier
  5. JavaFX 2.1 and earlier


Oracle Java SE Executive Summary
This Critical Patch Update contains 14 new security fixes for Oracle Java SE. 12 of these vulnerabilities may be remotely exploitable without authentication, i.e., may be exploited over a network without the need for a username and password.

The highest CVSS Base Score of vulnerabilities affecting Oracle Java SE is 10.0.

The Oracle Java SE components affected by vulnerabilities that are fixed in this Critical Patch Update are:

Java Runtime Environment

Leave a comment

Filed under Java

Java Inner Classes

Four types of Inner classes:

  1. Inside the Class.
  2. Inside the Method.
  3. Anonymous Class.
  4. Static Inner Class.

1. So how exactly inner class look like:

class OuterClass
{
class InnerClass
{

}
}

2. So what will be the out put when we compile the class:

javac OuterClass.java

=> OuterClass.class
=> OuterClass$InnerClass.class

3. Modifiers applied to Inner Class:

-final,abstract,public,private, protected & static.

4. Modifiers applied to Inner Class in Method:

-final, abstract.

Class inside another class.

class OuterClass
{
private int x=200;

class InnerClass
{
private int ans;

public void getValue()
{
display();
System.out.println("Outer Class Value :"+x);
}
}

public void display()
{
System.out.println("Outer Class Display :");
}

public void accessInner()
{
InnerClass obj=new InnerClass();
obj.ans=500;

System.out.println("Inner Class Value :"+obj.ans);
}
}

public class Main
{
public static void main(String agrs[])
{
OuterClass outobj=new OuterClass();
OuterClass.InnerClass inobj=outobj.new InnerClass();

/*
* OuterClass.InnerClass inobj=new OuterClass().new InnerClass();
*/
inobj.getValue();

}
}

Class inside method.

class OuterClass
{
private int x=200;

public void innerClassMtd()
{
int rel=500;

//only final & abstract
class InnerClass
{
private int ans;

public void getValue()
{
System.out.println("Outer Class Value :"+x);
}
}

new InnerClass().getValue();
}
}

public class Main
{
public static void main(String agrs[])
{
OuterClass obj=new OuterClass();
obj.innerClassMtd();

}
}

Anonymous Class.

class OuterClass
{
public void display()
{
System.out.println("Outer Class");
}
}

class InnerClass
{
OuterClass obj=new OuterClass(){
public void display(){
System.out.println("Anonymous Class");
}
};
}

public class Main
{
public static void main(String agrs[])
{
InnerClass myobj=new InnerClass();
myobj.obj.display();

}
}

Static class inside another class.

class OuterClass
{
int rel=500;

static class InnerClass
{
public void display()
{
System.out.println("Inner Class");
}
}
}

public class Main
{
public static void main(String agrs[])
{
OuterClass.InnerClass obj=new OuterClass.InnerClass();
obj.display();
}
}

Leave a comment

Filed under Java