Presentation is loading. Please wait.

Presentation is loading. Please wait.

A Short Introduction to JAVA

Similar presentations


Presentation on theme: "A Short Introduction to JAVA"— Presentation transcript:

1 A Short Introduction to JAVA
Kazi Masudul Alam

2 JAVA Object-oriented programming language developed by Sun Microsystems. Currently owned by ORACLE (ORACLE bought Sun Microsystems) Designed to be small, simple, and portable across platforms and operating systems Source, binary work in Windows, Linux, Mac OS Android OS and apps are motivated from JAVA like language. In 1991, James Gosling and Sun Microsystems began designing a language for home appliances (toasters, TVs, etc.). challenging, because home appliances are controlled by many different chips (processors) Programs were translated first into an intermediate language common to all appliance processors. Then the intermediate language was translated into the machine language for a particular appliance’s processor. Appliance manufacturers weren’t impressed. In 1994, Gosling realized that his language would be ideal for a Web browser that could run programs over the Internet. Sun produced the browser known today as HotJava.

3 Different Editions JAVA Standard Edition (J2SE)
Enterprise Edition (J2EE) Micro Edition (J2ME) J2SE is for desktop applications. We will be using this version of JAVA J2ME is for embedded systems ranging from Mobile Phone, Watch, Set top box, Microwave, Fridge etc. J2EE is for enterprise applications with heavily distributed nature. Very important to know the stacks and techniques used. Highly demanded in the job market.

4 JAVA Architecture

5 JAVA Application Development
A compiler translates a program from a high-level language to a low-level language the computer can run. The Java compiler does not translate a Java program into assembly language or machine language for a particular computer. Instead, it translates a Java program into byte-code. Byte-code is the machine language for a hypothetical computer (or interpreter) called the Java Virtual Machine. A byte-code program is easy to translate into machine language for any particular computer. A program called an interpreter translates each byte-code instruction, executing the resulting machine-language instructions on the particular computer before translating the next byte-code instruction. After compiling a Java program into byte-code, that byte-code can be used on any computer with a byte-code interpreter and without a need to recompile. Byte-code can be sent over the Internet and used anywhere in the world.

6 JAVA Editors DrJava Nebeans IDE Eclipse Others
(A light weight IDE) Nebeans IDE Eclipse Others Blue, JCreator, EJE Eclipse is the most used editor. It can work with many other programming language. Also, many other research works develop their plugins to design the systems using Eclipse

7 DrJAVA

8 J2SE Development Java SE Development Kit (8/7/6)
required to develop and compile the code Java SE Runtime Environment (8/7/6) required to execute the program Download here

9 First Java program public class HelloWorld {
public static void main(String[] args) { System.out.println("Hello, world!"); }

10 Saving and Running Save it as HelloWorld.java. Again, make sure that the filename is the same case as the class name. Compile and run it: javac HelloWorld.java Compiling will generate HelloWorld.class file java HelloWorld java HelloWorld.class Your computer should display Hello, world!

11 Errors An error in a program is called a bug.
Eliminating errors is called debugging. three kinds or errors syntax errors runtime errors logic errors Syntax error grammatical mistakes in a program the grammatical rules for writing a program are very strict The compiler catches syntax errors and prints an error message. example: using a period where a program expects a comma Runtime error errors that are detected when your program is running, but not during compilation When the computer detects an error, it terminates the program an prints an error message. example: attempting to divide by 0 Logic error errors that are not detected during compilation or while running, but which cause the program to produce incorrect results

12 Sum of 2 numbers class FirstProgram

13 Samples – Data Type

14 Samples – Control Statement

15 Samples – Loop

16 Variable Types Local variables Instance variables Static variables
Constant

17 Modifier Types Access Modifier
Visible to the package, the default. No modifiers are needed. Visible to the class only (private). Visible to the world (public). Visible to the package and all subclasses (protected).

18 Modifier Types Non-Access Modifier
The static modifier for creating class methods and variables The final modifier for finalizing the implementations of classes, methods, and variables. The abstract modifier for creating abstract classes and methods. The synchronized and volatile modifiers, which are used for threads

19 Arithmetic Operators Output:

20 Relational Operators

21 Logical Operators

22 JAVA Numbers xxxValue()
Converts the value of this Number object to the xxx data type and returned it valueOf() Returns an Integer object holding the value of the specified primitive. toString() Returns a String object representing the value of specified int or Integer. parseInt() This method is used to get the primitive data type of a certain String sqrt() Returns the square root of the argument. random() Returns a random number.

23 JAVA Character and String
isLetter() Determines whether the specified char value is a letter isDigit() Determines whether the specified char value is a digit. isUpperCase() Determines whether the specified char value is uppercase isLowerCase() Determines whether the specified char value is lowercase

24 JAVA Character and String
compareTo(String anotherString) Compares two strings lexicographically. endsWith(String suffix) Tests if this string ends with the specified suffix byte[] getBytes(String charsetName) Encodes this String into a sequence of bytes using the named charset int indexOf(int ch) Returns the index within this string of the first occurrence of the specified character. int length() Returns the length of this string. boolean matches(String regex) Tells whether or not this string matches the given regular expression.

25 JAVA Array dataType[] arrayRefVar =new dataType[arraySize];
double[] myList =new double[10];

26 JAVA Methods Passing parameter by value

27 JAVA Files and I/O

28 Input / Output

29 Exception Handling

30 JAVA Multi Threading

31 Other Features Package Interface Encapsulation Abstraction
Polymorphism Over riding Over loading Inheritance

32 LAB Fill the required logic in the given code so that the output of the program matches. Only use control statements for/while/do-while if/else if/else break/continue Dot not use 2D Array! Write the out patterns in a file. Then read the file and print it in screen.

33 Lab Outputs Desired Output Sample Code

34 References Thanking. Prof. Ivan Stojmenovic


Download ppt "A Short Introduction to JAVA"

Similar presentations


Ads by Google