Java Packages – Tutorial 4

1. Expalin Package and what is need of package.

2. Creating Package.

/*

Code:

*/

package com.vinod;

public class Student {

private int id;
private String name;

public Student()
{
id=0;
name=null;
}
public Student(int tid,String tname)
{
id=tid;
name=tname;
}

public void setData()
{
id=0;
name=null;
}

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

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

package com.second;

public 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);
}
}

package com.vinod;

import com.second.*;

public class MainClass {

public static void main(String[] args) {

Student stu1=new Student();
stu1.setData(1,”Vinod Pillai”);
stu1.display();

Student stu2=new Student(2,”Abc User”); //Calling Constructor with argument.
stu2.display();

Employee emp1=new Employee();
emp1.setData(101, “Ramesh”);
emp1.display();

com.second.Employee emp2=new com.second.Employee();
emp2.setData(102, “Xyz”);
emp2.display();
}
}

http://www.youtube.com/vinodthebest

1 Comment

Filed under General

Java Constructor, Method and Static variable – Tutorial 3

1. Method Overloading.

2. Constructors.

3. Constructors Overloading.

4. Static variable and Methods.

/*

Code:

*/

public class Student {

private int id;
private String name;

private static int count;

//Constructor Overloading
public Student()
{
//id=0;
name=null;

count++;
}
public Student(int tid,String tname)
{
id=tid;
name=tname;

count++;
}

//Method Overloading
public void setData()
{
id=0;
name=null;
}

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

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

//Static Method.
public static int getCount()
{
//System.out.println(“\n ID is:”+id); //Error can’t access not static Variable/Method
return count;
}
}

public class MainClass {

public static void main(String[] args) {

Student stu1=new Student();        //Calling the user defined default constructor.
stu1.setData(1,”Vinod Pillai”);

Student stu2=new Student(2,”Abc User”); //Calling Constructor with argument.
stu2.display();

int rel=Student.getCount(); //Accessing the Static method.
System.out.println(“\nThe Static result is:”+rel);
rel=0;

rel=stu2.getCount();    //Its not the correct way but this is allowed.
System.out.println(“\nThe New Static result is:”+rel);

Student stu3=new Student();
stu3.display();
}
}

 

 

http://www.youtube.com/vinodthebest

3 Comments

Filed under General

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

C++: Exception Handling Part 3

1. Explain Exception Handling.

2. Explain about specifying rethrowing exception.

3. Example showing the use of specifying rethrowing exception in C++.


/*
Developed By: Prof. Vinod Pillai
vinodthebest@gmail.com
Exception Handling-Part 3.
*/

#include

using namespace std;

void testException1() throw(int,char)
{
int val;

cout<>val;

if(val<=0)
{
throw(100);

//throw(‘a’);

//throw(10.56);
}
}

void testException2() throw()
{
int val;

cout<>val;

if(val<=0)
{
throw(100);
}
}

int main()
{
try
{
testException1();

//testException2();
}
catch(int value)
{
cout<<”\n——-Rethrow Integer Exception occured——-”;
}
catch(char value)
{
cout<<”\n——-Rethrow Character Exception occured——-”;
}
catch(…)
{
cout<<”\n——-Rethrow All Exception occured——-”;
}
return 0;
}

1 Comment

Filed under C++, Exception Handling

C++ : Exception Handling Part 2

1. Explain Exception Handling.

2. Explain multiple catch blocks.

3. Explain re-throwing exception.

4. Explain catch all exception that is catch(…).

5. Example showing the use of multiple catch and re-throwing exception in C++.


/*
Developed By: Prof. Vinod Pillai
vinodthebest@gmail.com
Exception Handling-Part 2.
*/

#include

using namespace std;

void testException1()
{
try
{
//throw(100);

//throw(‘a’);

//throw(10.56);
}
catch(int val)
{
cout<<”\n——-Integer Exception occured——-”;
}
catch(char val)
{
cout<<”\n——-Character Exception occured——-”;
}
catch(…)
{
cout<<”\n——-All Exceptions handling——-”;
}
}

void testException2()
{
int val;

cout<>val;

if(val<=0)
{
throw(val);
}
}

int main()
{
testException1();

try
{
testException2();
}
catch(int value)
{
cout<<”\n——-Rethrow Exception occured——-”;
}
return 0;
}

Leave a comment

Filed under C++, Exception Handling

Facebook in Mobile Business

Don’t get shocked if you find a mobile phone by “Facebook” yes facebook is planning to launch a mobile phone mainly more concentrated towards to facebook application base. Hardware and OS wise not much surprise mostly probably it HTC + Android. Yes definitely it will he having modified Android as per the companies need.

photo_1364666529_temp

Read More Details

1 Comment

Filed under Android, General