Introduction of JAVA
Introduction
Founder
- James Gosling - Sun Microsystems
- Co-founder – Vinod Khosla
What is java?
• A general-purpose object oriented language.
• Write Once RunAnywhere(WORA).
• Designed for easy Web/Internet applications.
Execution of JAVA
(Java Virtual Machine) is an abstract machine that enables your computer to run a Java program.
When you run the Java program, Java compiler first compiles your Java code to bytecode. Then, the JVM translates bytecode into native machine code.
Java Runtime Environment
• JRE (Java Runtime Environment) is a software package that provides Java class libraries, Java Virtual Machine (JVM), and other components that are required to run Java applications.
Java Developmulent Kit
•Jdk is a collection of classes, java compiler, and JVM interpreter.
• JDK (Java Development Kit) is a software development kit required to develop applications in Java. When you download JDK, JRE is also downloaded with it. In addition to JRE, JDK also contains a number of development tools (compilers, JavaDoc, Java Debugger, etc).
Characteristics of Java
- Java is platform independent
- Java is portable
- Java is object-oriented
- Java is dynamic
- Java is secure
- Java is robust
- Java is multithread
Comments
Comments in a program are called inline documentation. They should be included to explain the purpose of the program and describe processing steps. They do not affect how a program works Java comments can take three forms:
// this comment runs to the end of the line
/* this comment runs to the terminating symbol, even across line breaks */
/** this is a javadoc comment */
Strings
Java defines the String class to handle strings A String is a collection of characters treated as a single unit.
It is not an array of char variables.
Type Casting
Assigning a value of one type to a variable of another type is known as Type Casting.
Syntax: dataType variableName = (dataType) variableToConvert;
Implicit Casting in Java / Widening
Explicit Casting in Java / Narrowing
- Java language offers many types of operators.
- Arithmetic operators
- Assignment operators
- Relational operators
- Logical operators
- Bitwise operators
- Conditional operators (ternary operators)
- Increment/decrement operators
- Special operators
Public Access: The public access modifier is the direct opposite of the private access modifier. A class, method or variable can be declared as public and it means that it is accessible from any class.
Default:A default class is accessible inside the package but it is not accessible from outside the package i.e. all the classes inside the package in which the default class is defined can access this class.
Private:The private access modifier is specified using the keyword private. The methods or data members declared as private are accessible only within the class in which they are declared. Any other class of the same package will not be able to access these members.
Protected:The protected modifier specifies that the member can only be accessed within its own package (as with package-private) and, in addition, by a subclass of its class in another package.
Methods:
A method is a block of code which only runs when it is called. You can pass data, known as parameters, into a method. Methods are used to perform certain actions, and they are also known as functions.
Constructor:
A constructor in Java is a special method that is used to initialize objects. The constructor is called when an object of a class is created. It can be used to set initial values for object attributes. In Java, a constructor is a block of codes similar to the method.
method vs constructor
•
Array
is a collection of similar type of elements that have contiguous memory
location.
•
Types
of Array in java
•
Single
Dimensional Array
• Multidimensional Array
Comments
Post a Comment
Give your Feedback