Java Tutorial
Total Page:16
File Type:pdf, Size:1020Kb
Java Tutorial JAVA TUTORIAL Simply Easy Learning by tutorialspoint.com tutorialspoint.com ABOUT THE TUTORIAL Java Tutorial Java is a high-level programming language originally developed by Sun Microsystems and released in 1995. Java runs on a variety of platforms, such as Windows, Mac OS, and the various versions of UNIX. This tutorial gives a complete understanding ofJava. This reference will take you through simple and practical approach while learning Java Programming language. Audience This reference has been prepared for the beginners to help them understand the basic to advanced concepts related to Java Programming language. Prerequisites Before you start doing practice with various types of examples given in this reference, I'm making an assumption that you are already aware about what is a computer program and what is a computer programming language? Copyright & Disclaimer Notice All the content and graphics on this tutorial are the property of tutorialspoint.com. Any content from tutorialspoint.com or this tutorial may not be redistributed or reproduced in any way, shape, or form without the written permission of tutorialspoint.com. Failure to do so is a violation of copyright laws. This tutorial may contain inaccuracies or errors and tutorialspoint provides no guarantee regarding the accuracy of the site or its contents including this tutorial. If you discover that the tutorialspoint.com site or this tutorial content contains some errors, please contact us at [email protected] TUTORIALS POINT Simply Easy Learning Table of Content Java Tutorial ............................................................................ 2 Audience .................................................................................. 2 Prerequisites ............................................................................ 2 Copyright & Disclaimer Notice .................................................. 2 Java Overview ....................................................................... 15 History of Java: ........................................................................................ 16 Tools you will need: ................................................................................. 16 What is Next? .......................................................................................... 16 Java Environment Setup ........................................................ 17 Setting up the path for windows 2000/XP: ............................................... 17 Setting up the path for windows 95/98/ME: ............................................. 17 Setting up the path for Linux, UNIX, Solaris, FreeBSD: ........................... 17 Popular Java Editors: .............................................................................. 18 What is Next? .......................................................................................... 18 Java Basic Syntax .................................................................. 19 First Java Program: ................................................................................. 19 Basic Syntax: ........................................................................................... 20 Java Identifiers: ....................................................................................... 20 Java Modifiers: ........................................................................................ 21 Java Variables: ........................................................................................ 21 Java Arrays:............................................................................................. 21 Java Enums: ............................................................................................ 21 Example: ................................................................................................. 21 Java Keywords: ....................................................................................... 22 Comments in Java ................................................................................... 22 Using Blank Lines: ................................................................................... 22 Inheritance: .............................................................................................. 22 Interfaces: ................................................................................................ 23 What is Next? .......................................................................................... 23 Java Object & Classes ........................................................... 24 Objects in Java: ....................................................................................... 24 Classes in Java: ...................................................................................... 25 Constructors: ........................................................................................... 25 Singleton Classes .................................................................................... 26 Implementing Singletons: ........................................................................ 26 Example 1:............................................................................................... 26 Example 2:............................................................................................... 26 TUTORIALS POINT Simply Easy Learning Creating an Object: .................................................................................. 27 Accessing Instance Variables and Methods: ........................................... 27 Example: ................................................................................................. 28 Source file declaration rules: ................................................................... 28 Java Package: ......................................................................................... 29 Import statements: ................................................................................... 29 A Simple Case Study: .............................................................................. 29 What is Next? .......................................................................................... 31 Java Basic Data Types .......................................................... 32 Primitive Data Types: .............................................................................. 32 byte: ......................................................................................................... 32 short: ....................................................................................................... 32 int: ............................................................................................................ 33 long: ......................................................................................................... 33 float: ......................................................................................................... 33 double: ..................................................................................................... 34 boolean: ................................................................................................... 34 char: ........................................................................................................ 34 Reference Data Types: ............................................................................ 34 Java Literals: ........................................................................................... 35 What is Next? .......................................................................................... 36 Java Variable Types ............................................................... 37 Local variables: ........................................................................................ 37 Example: ................................................................................................. 38 Example: ................................................................................................. 38 Instance variables: ................................................................................... 38 Example: ................................................................................................. 39 Class/static variables: .............................................................................. 40 Example: ................................................................................................. 40 What is Next? .......................................................................................... 41 Java Modifier Types ............................................................... 42 1. Java Access Modifiers ......................................................................... 42 Default Access Modifier - No keyword: .................................................... 42 Example: ................................................................................................. 42 Private Access Modifier - private: ............................................................ 43 Example: ................................................................................................. 43 Public Access Modifier - public: ............................................................... 43 Example: ................................................................................................. 43 Protected Access Modifier - protected: .................................................... 43 TUTORIALS POINT Simply Easy Learning Example: ................................................................................................