Month: May 2014

Explanation of program:

Posted on

This example contains three preprocessor directives:

# include:

  • Is one of the most commonly used preprocessor directives.
  • When the preprocessor reaches this directive it looks for the file named in the brackets.
  • In the above example the preprocessor searches for the file hc705c8.h which contains device specific specification for the Motorola 68HC705C8.
  • If the file is found the preprocessor will replace the #includes directive with the entire contents of the file. If the file is not found the preprocessor will halt and give an error.
  • Here 3 include directive is used to include the contents of a header file.

#define ON 1 & # define OFF 0:

  • This directive is used to define symbolic constants.
  • Programs often use a constant number or value many times. Instead of typing in the actual number or value throughout the program, you can define a symbol which represents the value.
  • When the preprocessor reaches# define directive it will replace all the occurrences of the symbol name in your program with the associated constant.
  • In the statements # define ON 1 and # define OFF 0, the symbols ON and OFF are assigned the values 1 and 0 respectively.
  • Everywhere the preprocessor sees the symbol ON it will replace it with the constant 1; where it sees OFF it will replace it with the constant 0.

#pragma portrw portA @ 0X0A;

#pragma portw portAdir @ 0X8A;

  • #pragma directives instruct the compiler to behave in a certain way based on the description of the hardware resources of the target computer.
  • #pragma statements are most often used in header files which provide the hardware specification for a particular device. #pragma port directives for example, describe the port available on the target computer.
  • The description includes details on port location, whether they are read, write or read/write and the names the program uses to access ports.
  • In the above example the compiler is informed that two ports are available.
  • The name port A refers to physical Port A’s data register, which is available for reading and writing and is located at address 0X0A.
  • The name portADir refers to physical Port A’s data direction register, which is available for writing only and is located at address 0X8A.

 

Posted By-: Vissicomp Technology Pvt. Ltd.

Website -: http://www.vissicomp.com

Advertisements

JavaScript

Posted on

<html>

<head><title></title>

<script>

function checkAnswers()

{

var myQuiz=document.getElementById(“myquiz”);

if(myQuiz.elements[1].checked)

alert(“Congratulation,your answer is correct”);

else

alert(“Your answer is incorrect, please try again”);

}

</script>

</head>

<body>

<form id=”myquiz”  action=”onlinequiz.html”>

<p>Select the name of the tip that goes with the image shown<br/>

<img src=”” alt=””>

<input type=”radio” name=”radiobutton” value=”CPE”/>

<label> Common Programming Error</label>

<input type=”radio” name=”radiobutton” value=”EPT”/>

<label> Error Prevention Tip</label>

<input type=”radio” name=”radiobutton” value=”PERF”/>

<label> Performance Tip</label>

<input type=”radio” name=”radiobutton” value=”PORT”/>

<label> Protability Tip</label><br/>

<input type=”button” name=”submit” value=”submit” onClick=”checkAnswers()”/>

<Input type=”reset” name=”reset” value=”Reset”/>

</p>

</form>

</body>

</html>

6

Posted By-: Vissicomp Technology Pvt. Ltd.

Website -: http://www.vissicomp.com

Inheritance

Posted on

Inheritance

The mechanism that allows us to extend the definition of a class without making any physical changes to the existing class is inheritance.

Inheritance lets you create new classes from existing class. Any new class that you create from an existing class is called derived class; existing class is called base class.The inheritance relationship enables a derived class to inherit features from its base class. Therefore, rather than create completely new classes from scratch, you can take advantage of inheritance and reduce software complexity.

Forms of Inheritance

Single Inheritance: It is the inheritance hierarchy wherein one derived class inherits from one base class.
Multiple Inheritance: It is the inheritance hierarchy wherein one derived class inherits from multiple base class(es)
Hierarchical Inheritance: It is the inheritance hierarchy wherein multiple subclasses inherit from one base class.
Multilevel Inheritance: It is the inheritance hierarchy wherein subclass acts as a base class for other classes.
Hybrid Inheritance: The inheritance hierarchy that reflects any legal combination of other four types of inheritance.

 

In order to derive a class from another, we use a colon (:) in the declaration of the derived class using the following format :

class derived_class: memberAccessSpecifier base_class

{

};

Where derived_class is the name of the derived class and base_class is the name of the class on which it is based. The member Access Specifier may be public, protected or private. This access specifier describes the access level for the members that are inherited from the base class.

Member Access Specifier How Members of the Base Class Appear in the Derived Class
Private Private members of the base class are inaccessible to the derived class.
Protected members of the base class become private members of the derived class.
Public members of the base class become private members of the derived class.
Protected Private members of the base class are inaccessible to the derived class.
Protected members of the base class become protected members of the derived class.
Public members of the base class become protected members of the derived class.
Public Private members of the base class are inaccessible to the derived class.
Protected members of the base class become protected members of the derived class.
Public members of the base class become public members of the derived class.

 

class Shape

{

protected:

float width, height;

public:

void set_data (float a, float b)

{

width = a;

height = b;

}

};

 

class Rectangle: public Shape

{

public:

float area ()

{

return (width * height);

}

};

 

class Triangle: public Shape

{

public:

float area ()

{

return (width * height / 2);

}

};

 

int main ()

{

Rectangle rect;

Triangle tri;

rect.set_data (5,3);

tri.set_data (2,5);

cout << rect.area() << endl;

cout << tri.area() << endl;

return 0;

}

 

output :

15
5

 

Posted By-: Vissicomp Technology Pvt. Ltd.

Website -: http://www.vissicomp.com

Reverse the string using c

Posted on

#include<iostream.h>

#include<conio.h>

#include<string.h>

#include<stdio.h>

 

void main()

{

clrscr();

char a[3][50];

int i,j,k,len;

cout<<“Enter 3 strings:\n”;

 

for(i=0;i<3;i++)

{

gets(a[i]);

}

cout<<“\nThe list of orignal strings:\n” ;

 

for(i=0;i<3;i++)

{

cout<<a[i]<<“\n”;

}

cout<<“\nThe list of changed string:\n”;

 

for(i=0;i<3;i++)

{

len=strlen(a[i]);

for(j=0,k=len-1;k>=0;j++,k–)

{

cout<<a[i][k];

}

cout<<“\n”;

}

getch();

}

5

Posted By-: Vissicomp Technology Pvt. Ltd.

Website -: http://www.vissicomp.com

core java

Posted on

Search topic: Question and answer on java

  1. Can you call the main() method of  a class from another class?
  2. yes. We can call the main() method of  a class from another class using classname. Main(). At the time of calling the main() method, we should pass a string type array to it.

 

  1. Is string a class or data type?
  2. String is a class in java.lang.package. But in java, all classes are also considered as data types. So we can take String as a data type also.

 

  1. Out of do…while and while- which loop is efficient?
  2. In a do..while loop, the statements are executed without testing the condition, the first time. From the second time only the condition is observed. This means that the programmer does not have control right from the beginning of its execution. In a while loop, the condition is tested first and then only the statements are executed. This means it provides better control right from the beginning. Hence while is more efficient than do…while loop.

 

  1. What is the difference between System.exit(0) and System.exit(1)?
  2. System.exit(0) terminates the program normally. Whereas System.exit(1) terminates the program because of some error encountered in the program.

 

  1. On which memory, arrays are created in Java?
  2. Arrays are created on dynamic memory by JVM. There is no question of static memory in java, everything is created on dynamic memory only.

 

  1. Explain the difference between the following two statements:
  2. String s=”hello”;
  3. String s=new String(“Hello”);

In the first statement, assignment operator is used to assign the string literal to the String variable s. In this case, JVM first of all checks whether the same object is already available in the string constant pool. If it available, then it creates another reference to it. If the same object is not available, then it creates another object with the content “hello” and stores it into the string constant pool.

In second statement, new operator is used to create the string object. In this case, JVM always creates a new object without looking in the string constant pool.

  1. Can you declare a class as ‘private’?
  2. No. if we declare a class as private. Then it is not available to java complier and hence a compile time error occurs. But, inner classes can be declared as private.

 

  1. What are factory methods?
  2. A factory method is a method that creates and returns an object to the class to which it belongs. A single factory method replaces several constructors in the class by accepting different options from the user, while creating the object.

 

  1. What is object graph?
  2. Object graph is a graph showing relationship between different objects in memory.

 

  1. What is anonymous inner class?
  2. It is an inner class whose name is not written in the outer class and for which only one object is created.

Posted By-: Vissicomp Technology Pvt. Ltd.

Website -: http://www.vissicomp.com

window object methods

Posted on

<html>

<head><title></title>

<script type=”text/javascript”>

var mywindow

function openCenteredWindow(url)

{

var mywindow

mywindow=window.open(url,”subwind”,400,400,status.resizable);

}

function show_alert()

{

alert(“Hi!!!! I am alert box”)

}

function resizeWindow()

{

window.resizeBy(-100,-100);

}

function closeWindow()

{

if(window.confirm(“do you want to close the browser”))

window.close();

}

</script>

</head>

<body>

<input type=”button” value=”Open a New Window” onClick=”openCenteredWindow(‘WindowsMethods.html’)”/>

<input type=”button” value=”alert” onClick=”show_alert()”/>

<input type=”button” onClick=”resizeWindow()” value=”Resize window”>

<input type=”button” onClick=”closeWindow()” value=”close the window”>

</body>

</html>

1

Posted By-: Vissicomp Technology Pvt. Ltd.

Website -: http://www.vissicomp.com

 

 

Advance Java

Posted on

import javax.swing.*;

import javax.swing.*

import java.awt.*;

import java.awt.event.*;

 

public class JListDemo

{

public static void main(String[] args) {

myframe test = new myframe ();

test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

}

 

Class myframe extends JFrame {

JList list;

String[] listColorNames = { “black”, “blue”, “green”, “yellow”,”white” };

Color[] listColorValues = { Color.BLACK, Color.BLUE, Color.GREEN,               Color.YELLOW, Color.WHITE };

Container contentpane;

public JListDemo() {

super(“List Source Demo”);

contentpane = getContentPane();

contentpane.setLayout(new FlowLayout());

list = new JList(listColorNames);

list.setSelectedIndex(0);

list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

contentpane.add(new JScrollPane(list));

list.addListSelectionListener(new ListSelectionListener() {

public void valueChanged(ListSelectionEvent e) {                            contentpane.setBackground(listColorValues[list

.getSelectedIndex()]);

}

});

setSize(200, 200);

setVisible(true);

}

}

 

output

3

 

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

 

public class ComboBox{

JComboBox combo;

JTextField txt;

public static void main(String[] args) {

ComboBox b = new ComboBox();

}

 

public ComboBox(){

String course[] = {“BCA”,”MCA”,”PPC”,”CIC”};

JFrame frame = new JFrame(“Creating a JComboBox Component”);

JPanel panel = new JPanel();

combo = new JComboBox(course);

combo.setBackground(Color.gray);

combo.setForeground(Color.red);

txt = new JTextField(10);

panel.add(combo);

panel.add(txt);

frame.add(panel);

combo.addItemListener(new ItemListener(){

public void itemStateChanged(ItemEvent ie){

String str = (String)combo.getSelectedItem();

txt.setText(str);

}

});

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.setSize(400,400);

frame.setVisible(true);

}

}

Posted By-: Vissicomp Technology Pvt. Ltd.

Website -: http://www.vissicomp.com