Sunday, April 19, 2015

INTRODUCTION TO JAVA PROGRAMMING

33 comments


INTRODUCTION TO JAVA PROGRAMMING


¨ Introduced by [James Gosling & team-mates] at Sun Micro-Systems.
¨ Was called Oak but then introduced as Java.

¨ Purpose:-
    à Platform Independence. 
    àNetworking & Internet
    àCan be used with electronic consumer devices.

¨ Java SE (standard edition)

¨ Java EE (Enterprise Edition)

¨ Java ME (Micro edition)



How JAVA is plat-form Independent


¨ Due to Java Architecture it is plat-form independent

¨ Main features of Java Architecture:-
à Java programming language (source program created).
à Java class files
à Java Application program Interface (java API)
à Java Virtual Machine (JVM).


JAVA Architecture


JAVA Architecture


¨ Java does not have its own editor so we can use [Notepad]   to write programs.
¨ Source program is compiled using “javac” compiler in JDK     & after compilation java class file is created.
¨  These class Files are in the form of “Byte-Codes”.

Java Platform


¨JVM+API = Java platform
¨Java platform is different for different machines.

¨i.e. for UNIX, Windows , Mac are different for one another.
¨The variation in hardware environment is taken care by JVM.

¨Which makes Java programming Platform Independent.
    [ Write Once Compile Once & Run On Any Platform]


Role of JVM [Java Virtual Machine]


¨Most important component of java programming.
üJVM executes Java class files & Java API files as required to get output.
üJava API files have native methods that interact with local operating system [Unix , Mac , Windows etc].

Before you run your programs, you must compile them.

¨ compiler: Translates a computer program written in one language into another language.

¤ Java Development Kit includes a Java compiler.
¤ byte code: The Java compiler converts your source code   into a format named byte code that can be executed on   many different kinds of computers.

Compile execute java program

Feature Of JAVA 

¨ Safe
¨ Robust
¨ Multi-threaded
¨ Architecture Neutral
¨ Internet Ready
¨ Simple

Types of Java Program


¨ Using Java language two types of programs can be written.

¨ Application Programs
¨ Applet

¨ Application Programs:-


  •     Used to run program in PC under control of O.S in that machine are called application programs.

¨ Applets:-

  •     Java applets are form of Byte-codes that run in web browser using JVM and executed without any control of O.S in that machine.

  •      Used to add interactive contents to web pages , giving animations etc.

Read full post »

Monday, April 6, 2015

Pointers in C++

0 comments


Pointers in C++



 Introduction to Pointers in C and c++


Introduction to Pointers


o When we declare a variable some memory is allocated for it. The memory location can be referenced through the identifier “i”. Thus, we have two properties for any variable : its address and its data value. The address of the variable can be accessed through the referencing operator “&”. “&i” gives the memory location where the data value for “i” is stored.

o A pointer variable is one that stores an address. We can declare pointers as follows int* p; .This means that p stores the address of a variable of type int.



o Q: Why is it important to declare the type of the variable that a pointer points to? Aren’t all addresses of the same length?

o A: It’s true that all addresses are of the same length, however when we perform an operation of the type “p++” where “p” is a pointer variable, for this operation to make sense the compiler needs to know the data type of the variable “p” points to. If “p” is a character pointer then “p++” will increment “p” by one byte (typically), if “p” were an integer pointer its value on “p++” would be incremented by 2 bytes (typically).


o Summary of what was learnt so far:


n Pointer is a data type that stores addresses, it is declared 
as follows:  int* a; char* p; etc.

n The value stored in a pointer p can be accessed through 
the dereferencing operator “*”.

n The address of a memory location of a variable can be 
accessed through the reference operator “&”.

n Pointer arithmetic: only addition and subtraction are 
allowed.


 Introduction to Pointers in C and c++




Pointers and Arrays



o The concept of array is very similar to the concept of pointer. The identifier of an array actually a pointer that holds the address of the first element of the array.

o Therefore if you have two declarations as follows:

n int a[10];” “int* p;” then the assignment “p = a;” is 
perfectly valid

n Also “*(a+4)” and “a[4]”  are equivalent as are “*
(p+4)” and “p[4]” .

n The only difference between the two is that we can change the value of “p” to any integer variable address whereas “a” will always point to the integer array of length 10 defined.

o The concept of array is very similar to the concept of pointer. The identifier of an array actually a pointer that holds the address of the first element of the array.

o Therefore if you have two declarations as follows:

n int a[10];” “int* p;” then the assignment “p = 
a;” is perfectly valid

n Also “*(a+4)” and “a[4]”  are equivalent as are 
“*(p+4)” and “p[4]” .

n The only difference between the two is that we can change the value of “p” to any integer variable address whereas “a” will always point to the integer array of length 10 defined.


Character Pointers, Arrays and Strings



o What is a String?

n A string is a character array that is ‘\0’ terminated.
n E.g. “Hello”

o What is a Character array?

n It is an array of characters, not necessarily ‘\0’ terminated
n E.g. char test[4] = {‘a’, ‘b’, ‘c’, ‘d’}; <this char array is not zero terminated>

o What is a character pointer?

n It is a pointer to the address of a character variable.

n E.g. char* a; <this pointer is not initialized>

o How do we initialize a Character pointer

n Initialize it to NULL. char* a = NULL;

n Let it point to a character array.

o char* a; char b[100]; a = b

n Initialize to a character string.

o char* a = “Hello”; a pointer to the memory location where  ‘H’ is stored. Here “a” can be viewed as a character array of size 6, the only difference being that a can be reassigned another memory location.


Examples

o char* a = “Hello”;
n  a -> gives address of ‘H’
n *a -> gives ‘H’
n a[0] -> gives ‘H’
n a++ -> gives address of ‘e’
n *a++ -> gives ‘e’
n a = &b; where b is another char  variable is perfectly LEGAL. However “char a[100];” “a =&b;” where b is another char variable is ILLEGAL.


Read full post »

Saturday, April 4, 2015

what is Flowchart in computer programming - "Flowchart"

1 comments

what is Flowchart in computer programming - "Flowchart"



Flowcharts





Indicate flow of program 




Decision denote a decision-


making operation in a program


Connector – a link between parts of a 


flowchart if a flowchart is large and 


unfit in a single page 



what is Flowchart in computer programming - "Flowchart"

Rules for Drawing a Flowchart


It should contain only one starter and one end symbol.



The direction of arrows should be top to bottom 

and left to right.


It should be simple and drawn clearly and neatly.



The branches of decision box must be labeled. 





Advantages Flowcharts



Provides convenient method to


 understand the solution. 


Good tool for documentation.


Provide guide for coding.




DisadvantageFlowcharts


Not suitable for large programs.



Complex logic: Sometimes, the 


program  logic is quite complicated.



Alterations and Modifications: 


If alterations are required the flowchart

may require re-drawing completely.



Example #1



Convert temperature from


Fahrenheit to Celsius











Example #2



Convert days into months and days












what is Flowchart in computer programming - "Flowchart"





Read full post »