Presentation is loading. Please wait.

Presentation is loading. Please wait.

Basic Of Java Mr. Dharmesh M Shah, (Asst. Prof) Kalol Inst. Of Management (MCA) MCA Semester- III Subject : Fundamentals Of JAVA Programming (630002) Mr.

Similar presentations


Presentation on theme: "Basic Of Java Mr. Dharmesh M Shah, (Asst. Prof) Kalol Inst. Of Management (MCA) MCA Semester- III Subject : Fundamentals Of JAVA Programming (630002) Mr."— Presentation transcript:

1 Basic Of Java Mr. Dharmesh M Shah, (Asst. Prof) Kalol Inst. Of Management (MCA) MCA Semester- III Subject : Fundamentals Of JAVA Programming (630002) Mr. Dharmesh M Shah, Asst. Prof, Kalol Inst. Of Management (MCA)

2 History of JAVA JAVA is an object oriented programming language. It was developed by Sun Microsystems in 1991 as a part of the research work to develop software for consumer electronics. It was designed to be small, simple and portable across platforms and operating systems, both at the source and at the binary level. It was developed as a full-fledged programming language in which one can accomplish the same sorts of tasks and solve the similar problems that one can in other programming languages, such as C++, BASIC etc. Mr. Dharmesh M Shah, Asst. Prof, Kalol Inst. Of Management (MCA)

3 About JAVA Modeled after C++, the Java language was designed to be small, simple, and portable across platforms and operating systems, both at the source and at the binary level. Mr. Dharmesh M Shah, Asst. Prof, Kalol Inst. Of Management (MCA)

4 Why JAVA Java language was developed at Sun Microsystems in 1991 as part of a research project to develop software for consumer electronics devices- television sets, VCRs, toasters, and the other sorts of machines you can buy at any department store. Java's goals at that time were to be small, fast, efficient, and easily portable to a wide range of hardware devices. It is those same goals that made Java an ideal language for distributing executable programs via the World Wide Web, and also a general-purpose programming language for developing programs that are easily usable and portable across different platforms. This is the major reason why Java is said to be the most successful platform independent language. Mr. Dharmesh M Shah, Asst. Prof, Kalol Inst. Of Management (MCA)

5 Advantages of Java Java as a language has significant advantages over other languages and other programming environments that make it suitable for just about any programming task. Some of them are listed as follows: Applets Appletsappear in a Web page much in the same way as images do, but unlike images, applets are dynamic and interactive. Applets can be used to create animations, figures, or areas that can respond to input from the reader, games, or other interactive effects on the same Web pages among the text and graphics. Java enabled browsers can successfully run applets and thus give a truly rich experience at the user ends. Mr. Dharmesh M Shah, Asst. Prof, Kalol Inst. Of Management (MCA)

6 Platform Independence Platform independence is one of the most significant advantages that Java has over other programming languages, particularly for systems that need to work on many different platforms. Java is platform-independent at both the source and the binary level. Platform- independence is a program's capability of moving easily from one computer system to another. Java binary files called byte-codes are also platform-independent and can run on multiple platforms without the need to recompile the source. Byte-codes are a set of instructions that look a lot like machine code, but are not specific to any one processor. Because of them, compilation happens just once; interpretation occurs each time the program is executed. Java byte-codes help make "write once, run anywhere possible Mr. Dharmesh M Shah, Asst. Prof, Kalol Inst. Of Management (MCA)

7 Simplicity In addition to its portability and object- orientation, one of Java's initial design goals was to be small and simple, and therefore easier to write, easier to compile, easier to debug, and, best of all, easy to learn. Keeping the language small also makes it more robust because there are fewer chances for programmers to make difficult-to-find mistakes. Despite its size and simple design, however, Java still has a great deal of power and flexibility. Mr. Dharmesh M Shah, Asst. Prof, Kalol Inst. Of Management (MCA)

8 Better Cousin of C, C++ Java is modeled after C and C++, and much of the syntax and object-oriented structure is borrowed from the latter. If you are familiar with C++, learning Java will be particularly easy for you, because you have most of the foundation already. Although Java looks similar to C and C++, most of the more complex parts of those languages have been excluded from Java, making the language simpler without sacrificing much of its power. There are no pointers in Java, nor is there pointer arithmetic. Strings and arrays are real objects in Java. Memory management is automatic. To an experienced programmer, these omissions may be difficult to get used to, but to beginners or programmers who have worked in other languages; they make the Java language far easier to learn. Mr. Dharmesh M Shah, Asst. Prof, Kalol Inst. Of Management (MCA)

9 Applets and Applications The most common types of programs written in the Java programming language are applets and applications.If you've surfed the Web, you're probably already familiar with applets. An applet is a program that adheres to certain conventions that allow it to run within a Java-enabled browser. An application is a standalone program that runs directly on the Java platform. A special kind of application known as a server serves and supports clients on a network. Examples of servers are Web servers, proxy servers, mail servers, and print servers. Mr. Dharmesh M Shah, Asst. Prof, Kalol Inst. Of Management (MCA)

10 Another specialized program is a servlet. A servlet can almost be thought of as an applet that runs on the server side. Java Servlets are a popular choice for building interactive web applications, replacing the use of CGI scripts. Servlets are similar to applets in that they are runtime extensions of applications. Instead of working in browsers, though, servlets run within Java Web servers configuring or tailoring the server. Mr. Dharmesh M Shah, Asst. Prof, Kalol Inst. Of Management (MCA)

11 Dual Utility of JAVA The programs developed in Java fall into two main categories : applications and applets. The Java Applications are general programs like any other programming language. They can perform any required operation/task or application. The Java Applets are Java Programs that are downloaded over the World Wide Web and are executed as a part of Web page, by a Web Browser on the machine. The Applets can create games, interactive programs, animations and develop multimedia effects on the web page. A program written in JAVA can be either an application or an applet or both, depending on the writing structure of the program. Mr. Dharmesh M Shah, Asst. Prof, Kalol Inst. Of Management (MCA)

12 Character set of JAVA Letters A-Z and a-z, 0-9 digits, special symbols like Space, +, -, *, /, ^, \, (, ), {, }, [, ], =, !=,,.,,, $, ;, :, %, !, &, ?, -, #, @, = and white spaces like blank space, horizontal tab, carriage return, newline, form feed etc Mr. Dharmesh M Shah, Asst. Prof, Kalol Inst. Of Management (MCA)

13 Tokens of JAVA JAVA comprises of tokens as smallest element of the program. They implement various features within a program. *Keywords *Identifiers *Literals *Separators *Operators Mr. Dharmesh M Shah, Asst. Prof, Kalol Inst. Of Management (MCA)

14 STRUCTURE OF A JAVA PROGRAM The program written in Java has two main parts : *Enclosure of the program in a class definition. *Enclosure of the body of the program in the functions. Example Program in JAVA Class exampleprogram { public static void main(stringargs[ ]) { System.out.println(HailThe World !); } }; Mr. Dharmesh M Shah, Asst. Prof, Kalol Inst. Of Management (MCA)

15 In the above program, the first line declares a class named exampleprogram, where class is the reserve word. Exampleprogram is an identifier as supplied by the programmer. This is followed by brace {, which indicates the beginning of the block of executable statements. The third line : public static void main(string args[ ]) defines the function main( ). The declaration of the main() function contains the following keywords: Public, Static and Void. The Public keyword acts as an access specifier which declares the main function to be publically accessible for other classes. Mr. Dharmesh M Shah, Asst. Prof, Kalol Inst. Of Management (MCA)

16 The Static definition declares that the very function or method is independent of the entire class and does not figure as a part of any objects of the class. In the above program, the class example program is unchanging or static, as a state. The term static means unchanging and implicitly final. The Void is a data type modifier which defines the main() function of no return type. The argument of the main() function lies within braces eg. (String args[ ]), here String args[ ] declares an argument parameter as argsc ontaining an array of objects of the class type String. It specifies that the main method takes an argument that is an object of string. Mr. Dharmesh M Shah, Asst. Prof, Kalol Inst. Of Management (MCA)

17 Programming Instructions In JAVA Output Statements: The println ( ) method or the function is used to display information on the screen. It also provides a line feed i.e. transfers the control to the next line of the output. Example: System.out.println(Hello); Mr. Dharmesh M Shah, Asst. Prof, Kalol Inst. Of Management (MCA)

18 Remark Statement of JAVA The Java language offers provision of remark within its program in the following three ways : (i). Using /* and */ eg. /* This program prints the sum of two numbers */ (ii). Using // for a single line of comment. eg. // This program prints the sum of two numbers (iii). Using /** and */ eg. /** This program prints the sum of two numbers */ Mr. Dharmesh M Shah, Asst. Prof, Kalol Inst. Of Management (MCA)

19 Data Types (int) Type Size Min. Range Max.Range byte One Byte -128 127 short Two Bytes -32,768 32,767 int Four Bytes - 2,147,483,648 To 2,147,483,647 long Eight Bytes -9,223,372,036,854,775,808 To 9,223,372,036,854,775,807 Mr. Dharmesh M Shah, Asst. Prof, Kalol Inst. Of Management (MCA)

20 Data Types (float) This type of data includes numbers with decimal part or fractional numbers. It is further classified into two types as float and double with references as : Type Size Min. Range Max. Range float 4 3.4e-038 to 3.4e+038 double 8 1.7e-308 to 1.7e+308 Mr. Dharmesh M Shah, Asst. Prof, Kalol Inst. Of Management (MCA)

21 Escape Sequences in JAVA Escape Meaning \n Newline \t Tab \b Backspace \r Carriage return \f Form feed \\ Backslash \ Single Code \ Double Code \ddd Octal \xdd Hexadecimal \udddd Unicode Character Mr. Dharmesh M Shah, Asst. Prof, Kalol Inst. Of Management (MCA)

22 Declaration of Variables in JAVA A Declaration of a variable refers to the following: (i). Specification of the name of the variable. (ii). Specification of the data type of the variable. (iii). Specification of the scope of usage of the variable. eg. Int age; String name; Boolean isAbsent; Mr. Dharmesh M Shah, Asst. Prof, Kalol Inst. Of Management (MCA)

23 Arithmetic Operators Operator Meaning Format + Addition a+b - Substraction a-b * Product a*b / Division a/b % Modulus a%b where a and b are the two numeric constants. Mr. Dharmesh M Shah, Asst. Prof, Kalol Inst. Of Management (MCA)

24 Assignment Operators Operator / Operation /Format / Meaning = Assignment a=10 10 assigned to the variable a += Add to the variable a+=5 a=a+5 -= Subtract from variable a-=5 a=a-5 *= Multiply to variable a*=5 a=a*5 /= Divide into a/=5 a=a/5 %= Modulus of a%=5 a=a%5 Mr. Dharmesh M Shah, Asst. Prof, Kalol Inst. Of Management (MCA)

25 Escape Sequences in JAVA Escape Meaning \n Newline \t Tab \b Backspace \r Carriage return \f Form feed \\ Backslash \ Single Code \ Double Code \ddd Octal \xdd Hexadecimal \udddd Unicode Character Mr. Dharmesh M Shah, Asst. Prof, Kalol Inst. Of Management (MCA)

26 Shorthand Notation Shorthand Operation Equivalence Operation sum +=10; sum = sum+ 10; sum -=10; sum = sum-10; sum /=10; sum = sum/ 10; sum *=10; sum = sum* 10; sum %=10; sum = sum% 10; (Similarly a variable within an expression on the right can also be used as :) sum +=total; sum = sum+ total; Mr. Dharmesh M Shah, Asst. Prof, Kalol Inst. Of Management (MCA)

27 Increment & Decrement Operators The increment operator is indicated by ++ and is used to increment the variable by 1. eg. ++marks; increments the value of the variable marks by 1. It can be used in two ways : as a prefix, (++var), meaning that the operator precedes the variable; and as a postfix, (var++), where the operator follows the variable. In prefix the variable gets incremented first where as in postfix the variable gets incremented after the operation of function of its associate operator. Decrement Operators are similar to Increment Operators except the fact for the operation of decrementationby 1. It can also be used both as prefix and postfix forms of its format. eg. --marks; is used to decrement the value of marks by 1 Mr. Dharmesh M Shah, Asst. Prof, Kalol Inst. Of Management (MCA)

28 Ternary Operator of JAVA This is an excellent substitute to the control statement like IF/THEN/ELSE of BASIC language. It is denoted by the combinational characters ?: and follows the usage with the following format/syntax : Value variable = (test expression) ? expression1 : expression2; which indicates that if the test expression is true then the transfer value for storage into the value variable is expression1 and if the test expression is false the transfer value becomes the expression2. for example: grade = (total > 40) ? P: F; In the above example grade refers to the value variable, total>40 is the test expression, Pis the expression1 and Fis the expression2. The ? character follows the true condition and : follows the false condition. Mr. Dharmesh M Shah, Asst. Prof, Kalol Inst. Of Management (MCA)


Download ppt "Basic Of Java Mr. Dharmesh M Shah, (Asst. Prof) Kalol Inst. Of Management (MCA) MCA Semester- III Subject : Fundamentals Of JAVA Programming (630002) Mr."

Similar presentations


Ads by Google