Introduction To Java

6,693 Views

This ppt cover basic introduction of Core Java. It cover how to run Java hello word and what is the working internal working of Java compiler to run this program.

Saurabh S / Delhi

4 years of teaching experience

Qualification: MCA

Teaches: Accountancy, Commerce Subjects, Computer Science, IT & Computer Subjects, All Subjects, Mathematics, Economics, Social Studies, BBA Tuition, BCA Tuition, Statistics, .Net, C / C++, Java And J2EE, BCA Subjects, MCA Subjects

  1. Java:An introduction
  2. Objectives Appreciate Java as a language, Write, compile and execute simple java program in command prompt and eclipse
  3. Table of Content Java Language Simple Hello World in Java Environment to compile and execute setup JDK JDK installation directory Compilation & execution: command prompt JRE and bytecode Introducing Eclipse Helios 3.6 IDE Running Different Workspace UI Overview Features of Java Language Portable and platform independent JVM: perspectives Interpreter vs JIT Error handling in java Automatic garbage collection Classpath Commenting source code Some Guidelines for Doc comments javadoc Nesting comments Annotations 3
  4. Java Language Java was created by a team of members called "Green" led by James Arthur Gosling. When Java was created in 199 1, it was originally called Oak. o It is a free and open source software (FOSS) under GNU General Public License(GPL) First version of Java was released in 1995. Java is an Object oriented language, simple, portable, platform independent, robust and secure. We will be focusing on Java 1.6.
  5. Flavors Of Java Java Standard Edition formerly known as J2SE. This forms the core part of Java language. e JEE Java Enterprise Edition formerly known as J2EE. These are the set of packages that are used to develop distributed enterprise-scale applications. These applications are deployed on JEE application servers. e JME These are the set of pacl
  6. Simple Hello World in Java Hello . j ava public class Hello < public static void main (String args[] ) System . out . println ("Hello World! ") Special statement used to display data on consol . 'println' causes the next print statemant to be printed in the next line. main() is a method from where program execution begins. 6
  7. Environment to compile and execute Compile java programs From command prompt Through an IDE (Integrated development environment) Eclipse *Apache NetBeans *Oracle SDN JBuilder -Y Borland Integrated Development Environment -5 IBM What is an IDE? 7
  8. setup JDK o http://java.com/en/download/index.jsp find appropriate linl < in http://www.oracle.com/technetworl
  9. IDI < installation directory Java Runtime Environment java mexe java:. exe j avap.exe j avah.exe cols. jar t. jar java m dll Bin zlient Java virtual machine ext Java Executables Java Predefined Classes like String, Date, Math etc. :cnte 9
  10. Compilation & execution: command prompt Save the file as Hello.java.A public class must be saved in the same name as class name. Compile C : avac Hello. java Byte code Hello.class Hello.java Source code xecute javac compilation execution java C : \MyJava>j ava Hello Platform specific code 10
  11. JRE and bytecode Java Bytecode is produced when Java programs are compiled. To execute Java program,JRE must be installed in the system JRE or Java Runtime environment contains Java Virtual Machine Standard class libraries (APIs) Java Plug-in Java Webstart JRE gets installed automatically when JDK is installed. JRE can be installed independent of JDK as well. This will mean that Java programs can be executed in that system.
  12. Introducing Eclipse Helios 3.6 IDE e IDE is where the Java programs are written, compiled and executed, Eclipse is an open source project Launched in November 200 1 Designed to help developers with specific development tasks GUI and non-GUI application development support Easy integration of tools Supported by multiple operating systems lil
  13. Eclipse as an IDE o Java Development Tooling (JD T) is used for building Java code Provides set of worl
  14. Activity: Installing Eclipse Download Eclipse's Install Zip File from http://www.eclipse.org Clicl < on the Download from the main page on http://www.eclipse.org Choose the best site from which to download Choose the latest build for downloa ave the dowr
  15. Activity: Specifying Worl
  16. W en Eclipse is run, a Welcome page opens Java EE - Eclipse File Edit Navigate Welcome Search Project Run Window Help Eclipse Java EE IDE for Web Developers Overview Get an overview of the features Samples Try out the samples Tutorials Go through tutorials What's New Find out what is new Workbench 2:21 PM 7/24/2012 16
  17. Running Different Workspace o It is possible to run different worl
  18. Closing the Welcome page gets you to the Eclipse workbench user interface Java EE - Eclipse Eile Edit Navigate Seych Eroject Bun Uindow Help project Explorer 0 items selected Markers Properties Servers Data Source Explorer Snippets 0 items Description Resource Path Location Type Outline Task Lis An outline is not available. 2:16 PM 7/26/2012 18
  19. Activity : Create and Execute a Java project Writing a simple HelloWorld program in Java using Eclipse. Step l: Start Eclipse. Step 2: Create a new workspace called sample and 01
  20. Project Eun Step 5: Select "Java" in the categ Java EE - Eclipse Eile Edit Navigate Search ti ct • Select "Java Project" in the project list. Click "Next". Step 7: Enter a project name into the Pro ect name field, for example, "Hello World Project". Clicl < "Finish" Java EE - Eclipse gun Window Help Markers 0 items Descriptio n New Project Select a wizard Create a Java project Wizards: type filter tat cys Eclipse Modeling Framework Java Java project Java Project from Existing Ant Buildfile Java EE JavaScript JPA Plug-in Development Web Examples Sack Properties Servers Data Source Explorer Snippets Resource Path Finish Locatio n Type Cancel O items selected Outline Task Lis An outline is not available. 226 PM 7/26/2012 Lis An mRGne is not .v.il.ble S Nea Create a Java Project Crete project in the workspace or in an eternal location. HeoWodOrojeCt location •n aecution em•imnment 'RE; C) use project spec'ic RE: use pr.ect Use ptoect for sources and cuss files Create separate folders fot class files sets Add projet to working Propetks. O items selected It will ask you if you want the Java perspective to open. Yes. te nee t Yes 20
  21. Step-8: Select New Class option Ste Specify the class name 'Hélld orld" and select "public s atic yoid main(String[] args)" check ox. Click Finish. Java the Cl•ø O • bheted r: Generøe Step 10: In the main method enter the following System.out.println("H 10 World"); Save it pabug •j, Lit pabltc void 21
  22. Step 11:1 I l: Select Run -5 Run. Java - HelloWorldProjectJsrÜHallaWp.E!4ava - Ecli se Eile Edit Source Refactor Navigate Search Eroject Package Explorer 8 HelloWorldProjzct (default package) HelloWorldjava JRE System Library [JavaSE-1.61 resources,jar - C,'IProgram FilesUavakjre6Mib 'tjar - CAProgram FilesUavaIjre611ib Jsse,jar - C:IProgram FilesUavaKjre6\lib jce.jar- CåProgram charsetsjar - CåProgram dnsnsjar - C'IProgram [ocalzdatajar - C'\Program sunjce_provider.jar - C+uProgram sunmscap1Jar - sunpkcsll,jar - C:IProgram Eun Urndow Help public class HelioWarLd k' @parara arg: public statio void main (String I] arga) // TODO Auto—generated methzd stub System. out. printin ("Hella World") Problems @ Javadoc Declaration Console HelloWorld [Java Application) CIProgram (Jul 26, 2012 PM) Hello World Writahle E] Task List Find Java EE Q, All Activate.. Smart Insert Uncategorized (D Connect Mylyn Connect to your task and ALM taols. 02 Outline B HEIloWorld s void 234 PM 7/26/2012 22
  23. a) b) c) Exercise rite a java program to display the following Use print and println statements. The class file of this program should be automatically placed inside "Design" folder while compiling. Display the version used for compiling. ( 15 mins)
  24. Features of Java Language Object oriented language Portable and platform independent Robust Multithreaded Dynamic Linl
  25. Portable and platform independent Java Code can be compiled anywhere O Bytecode can be executed anywhere Can you make any guesses which statement above is for portable and which one for platform independence?
  26. Portable When java code executes, its behavior is exactly same in any java-aware system, There are no platform-specific code in java programs that causes compilation problems in any other OSO This mal
  27. Platform Independent A Java program requires JVM (part of JRE) to execute Java code. When Java application starts to executes, Java Virtual Machine also starts. Bytecode has instructions that Java Virtual Machine can understand and JVM converts the Bytecode to machine specific code. Java Bytecode can be copied on to any machine that has JVM and executed. This is what makes Java Platform Independent. "Write Once, Run any where" Is JVM platform independent?
  28. JVM: perspectives JVM can be lool
  29. Interpreter vs Java Bytecodes were originally designed to be interpreted by JVM meaning bytecode are translated to machine code without it being stored anywhere. Since bytecode verifier (which is part of JVM) performs runtime checks, line by line execution was important. S nce speed became an issue, Just-in-Time Compilation (JIT) came into being. JIT converts chunks of code, stores it temporarily in memory and then executes the converted code. JIT compilers are typically bundled with or are a part of a virtual machine and do the conversion to native code at runtime, on demand. The compiler also does automatic register allocation and some optimization when it produces the bytecodes. Therefore, JIT is hybrid compiler. 20
  30. Error handling in java Compilation error : generated by the compiler, O Examples of situation when it arises: incorrect syntax, bracket mismatch, if keywords are used as variables Using uninitialized variables Unreachable code: while (false) < . >Strong type checking Run-time error : generated by the JVM, O Examples of situation when it arises: Attempt to divide an integral value by 0 or access array index beyond the defined range. Trying to access a class that does not exist at runtime. (What happens if you delete Hello.class and then run Hello. Java has a strong exception handing mechanism that allows programmers to handle such errors and come out of the situation gracefully.
  31. Automatic garbage collection The garbage collector is a tool that attempts to free unreferenced memory (memory occupied by objects that are no longer in use by the program) in programs. Automatic garbage collection is an integral part of Java and its run-time system. Java technology has no pointers. So there is no question of allocation and freeing by programmers. Does that mean Java does not support dynamic memory allocation? No. It means that Java takes care of memory and relieves the programmers from memory-related hassles. java —verbose:gc can be used to get more information about garbage collection process.
  32. Classpath Classpath is an environment variable that java compiler and JVM (system class loader) use to locate the classes in the file system. To set the classpath temporarily in command line SET CLASSPATH=directory; ; Command to set classpath while compiling javac —classpath dirl ; dir2 Someclass . java Example: javac —classpath C : /MyJava Command to specify un-compiled source file to be compiled and included in the classpath sourcepath dir 1 ; dir2 Someclass avac Example: j avac —sourcepath C : /MyJava Providing classpath while executing java —classpath directory 1 ; directory2
  33. public class A < public static void main (String [ ] args) System . getProperty ( "user . dir") ; String curDir System . out . println (curDir) ; This code is in C:\MyJava folder. If this code is executed from C:\MyJava, it prints the curren directory. What command will make sure that this code can be executed from any location? (10 mins)
  34. Commentin source code Question: Why should you comment your code? How much should you comment? 3 types of comment Single line comment : // // this is a single line conunent Multi-line comment: /* */ / * this is multi line comment * / Documentation Comment (Doc comment): /** */ / ** This class is used to represent a stack . * @author Murali * @version 1.0, 08/16/2010
  35. Some Guidelines for Doc comments Who owns and edits the Doc Comments: usually the programmer Doc comments for classes, methods, fields: O Brief description of what it does. In case longer description is required, link to an external document (word, pdf) can be included. For methods, whether they are thread-safe and what runtime exception they throw must be specified. Proper indentation of threads and exception readability. Entities for the less-than () symbols should be written < and >. Likewise, the ampersand (&) should be written &. Visit this after finishing Java or More nformation refer h ttp://dov'.å) load .0 racle.co m/javase/ I .4.2/docs/tooldocs/windows/javadoc.html#documentationcomments
  36. javadoc Tool that is used to produce HTML pages by parsing through the documentation comment in java source code, Produces documentation for public and protected classes/members. Worl
  37. Nesting comments ' Valid Nesting ' Invalid Nesting / * * / and / ** * / nested with itself and nested with each other gives error.
  38. Annotations Annotations are extra text starting with @ symbol that are added in the Java program to provide information about a program. Annotations do not directly affect program semantics. They provide information about the program to tools and libraries, which can in turn affect the semantics of the running program. Annotations can be read from source files, class files, or reflectively at run time.
  39. Uses Annotations for the compiler O Example : @SuppressWarnings : can be used by the compiler to detect errors or suppress warnings Annotations for the application servers and tools Application server tools can process annotation information to generate code etc for services it provides like security etc. javadoc tool uses annotations like @author, @version, @param, @ return Runtime processing — Some annotations are available to be examined at runtime,
  40. Exercise Provide java doc comments for the class created In the previous exercise and generate HTML document files. Use documentation annotation. (10 mins) 40
  41. Summary Java was created by a team of members called "Green" led by James Arthur Gosling in 1991 and it was originally called as Oak. IDE is where the Java programs are written, compiled and executed. Simple, Object oriented language, Portable and platform independent, Robust, Multithreaded, Dynamic Linking, Secure and Performance are some of the features of Java Language Automatic garbage collection is an integral part of Java. Classpath environment variable is used to locate classes in the file system. Javadoc is a tool that is used to produce HTML pages by parsing through the documentation comment in java source code. Annotations are extra text starting with @ symbol that is added in the Java program to provide information about a program.

Need a Tutor or Coaching Class?

Post an enquiry and get instant responses from qualified and experienced tutors.

Related PPTs

Java And J2EE

6,228 Views

Java And J2EE

9,960 Views

C / C++, Data Structures, Java And J2EE

16,203 Views

Java And J2EE

3,350 Views

Java And J2EE

1,423 Views

Computer Science, Data Structures, Java And J2EE

6,405 Views

Java And J2EE

1,888 Views

Java And J2EE

6,320 Views

Java And J2EE, Mechanical

2,863 Views

Java And J2EE

10,517 Views

Upload PPTs

If you have your own PowerPoint Presentations which you think can benefit others, please upload on LearnPick. For each approved PPT you will get 100 Credit Points and 100 Activity Score which will increase your profile visibility.

Tutors by City +

Tutors by Subjects +

Tutors by Categories +

Institutes in India +

Find Tutor Jobs +

Information +

Disclaimer: LearnPick is an online tutoring marketplace and platform connecting students with excellent tutors and instructors. We neither supply nor recommend tutors to those in search of such services, and vice-versa. LearnPick does not verify the identity or authenticity of information posted by tutors or students. For more information on verifying the identity of information posted by other users, please visit our Safety Centre.