Java - Tutorialspoint

Transcription

JavaAbout the TutorialJava is a high-level programming language originally developed by Sun Microsystems andreleased in 1995. Java runs on a variety of platforms, such as Windows, Mac OS, and thevarious versions of UNIX. This tutorial gives a complete understanding of Java.This reference will take you through simple and practical approaches while learning JavaProgramming language.AudienceThis tutorial has been prepared for the beginners to help them understand the basic toadvanced concepts related to Java Programming language.PrerequisitesBefore you start practicing various types of examples given in this reference, we assumethat you are already aware about computer programs and computer programminglanguages.Execute Java OnlineFor most of the examples given in this tutorial, you will find a ‘Try it’ option, which youcan use to execute your Java programs at the spot and enjoy your learning.Try following the example using the ‘Try it’ option available at the top right corner of thefollowing sample code box public class MyFirstJavaProgram {public static void main(String []args) {System.out.println("Hello World");}}i

JavaTable of ContentsAbout the Tutorial . iAudience . iPrerequisites . iExecute Java Online . iTable of Contents . iiJAVA – BASICS . 11.Java – Overview . 2History of Java . 3Tools You Will Need . 3Try It Option . 4What is Next? . 42.Java - Environment Setup . 5Try it Option Online . 5Local Environment Setup . 5Popular Java Editors . 6What is Next? . 63.Java – Basic Syntax . 7First Java Program . 7Basic Syntax . 8Java Identifiers . 9Java Modifiers. 9Java Variables . 9Java Arrays . 9Java Enums . 10Java Keywords . 10Comments in Java . 11Using Blank Lines . 12Inheritance . 12Interfaces . 12What is Next? . 124.Java – Objects & Classes. 13Objects in Java . 13Classes in Java . 14Constructors . 14How to Use Singleton Class? . 15Creating an Object . 17Accessing Instance Variables and Methods. 18Source File Declaration Rules . 20Java Package . 20Import Statements . 21A Simple Case Study . 21What is Next? . 23ii

Java5.Java – Basic Datatypes . 24Primitive Datatypes . 24Reference Datatypes . 26Java Literals . 26What is Next? . 286.Java – Variable Types . 29Local Variables . 29Instance Variables . 31Class/static Variables . 33What is Next? . 347.Java – Modifier Types . 35Java Access Modifiers . 35Java Non-Access Modifiers . 38The Static Modifier . 38The Final Modifier . 39The Abstract Modifier. 41Access Control Modifiers . 43Non-Access Modifiers . 44What is Next? . 448.Java – Basic Operators . 45The Arithmetic Operators . 45The Relational Operators. 47The Bitwise Operators . 49The Logical Operators . 52The Assignment Operators . 53Miscellaneous Operators. 57Precedence of Java Operators . 59What is Next? . 599.Java – Loop Control . 60While Loop in Java . 61for Loop in Java . 62Do While Loop in Java . 65Loop Control Statements . 67Break Statement in Java . 67Continue Statement in Java . 69Enhanced for loop in Java . 70What is Next? . 7110. Java – Decision Making . 72If Statement in Java . 73If-else Statement in Java. 74The if.else if.else Statement . 76Nested if Statement in Java . 77Switch Statement in Java . 78The ? : Operator: . 80What is Next? . 81iii

Java11. Java – Numbers Class . 82Number Methods . 83Java XXXValue Method . 86Java – compareTo() Method . 87Java – equals() Method . 88Java – valueOf() Method . 89Java – toString() Method . 91Java – parseInt() Method . 92Java – abs() Method . 93Java – ceil() Method . 94Java – floor() Method . 95Java – rint() Method . 96Java – round() Method . 97Java – min() Method . 98Java – max() Method . 99Java – exp() Method . 100Java – log() Method . 101Java – pow() Method . 102Java – sqrt() Method. 103Java – sin() Method . 104Java – cos() Method . 105Java – tan() Method . 106Java – asin() Method . 107Java – acos() Method . 108Java – atan() Method . 109Java – atan2() Method . 110Java – toDegrees() Method . 111Java – toRadians() Method . 112Java – random() Method . 113What is Next? . 11412. Java – Character Class . 115Escape Sequences. 115Character Methods .

Java i About the 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