Java Basics

Java – Introduction

Introduction: Java distributions: Java is a platform independent language: Java is an Object-Oriented language: Multithreading:

Java – API Documentation

Java API Documentation: Search “java api” in Google: The Website providing complete information of java library about packages, classes, interface, methods, variables etc.,

Java – Application Structure

Java application structure: How to Compile and Run Java program from command Prompt? Code.java: public class Code{            public static void main(String[] args)            {                        System.out.println(“Hello World!”);            }} Command Prompt as follows:

Java – Naming Rules

Naming conventions: Class: Every word in identity starts with capital letter. Spaces not allowed StringPrintStreamNullPointerExceptionFileNotFoundExceptionArrayIndexOutOfBoundsException Method: First word starts with Lower Case and From Second word, every word starts with capital letters. No spaces allowed. main( )getName( )getAccountHolderNumber( ) Variable: First word starts with Lower Case and From Second word, every word starts with capital …

Java – Naming Rules Read More »

Java – Variables

Variable: Definition1: Variable is an identity given to memory location. Definition2: Variable is a named memory location Syntax:datatype identity = value; Examples:            String name = “Amar”;            int age = 23;            char gender = ‘M’;            boolean married = false;            double salary = 35000.00; Declaration, Assignment, Update and Initialization of Variable: Identifier rules: Rules to create identifier:

Java – Data types

Data type: Syntax:  Example: Data types classified into Primitive and Non-Primitive types. Limits: Integer types: We have 4 integer types among eight available primitive types in java. Type Size(bytes) Limits byte 1 -128(-2^7) to  +127(2^7-1) short 2 -32,768(-2^15) to 32,767(2^15-1) int 4 -2,147,483,648(-2^31) to 2,147,483,647(2^31-1) long 8 -9,223,372,036,854,775,808(-2^63) to 9,223,372,036,854,775,807(2^63-1) Note: Program to print sizes …

Java – Data types Read More »

Java – Programs on Arithmetic Operators

Find the average of two numbers: public class Practice{            public static void main(String[] args)            {                        int num1= 5 , num2 = 3;                        int avg = (num1+num2)/2;                        System.out.println(“Average : ” + avg);            }} Find the Sum of Square and Cube of a Number: public class Practice{                      public static void main(String[] args)            {                        int a = 5;                        …

Java – Programs on Arithmetic Operators Read More »

Java – Type Casting

Type casting: Convert Character to Integer: this conversion happens implicitly when we assign character to integer type. class Code{            public static void main(String[] args) {                        char ch = ‘A’ ;                        int x = ch ;                        System.out.println(“x value : ” + x);            }} Convert Integer to Character: this conversion must be done manually class Code{            public …

Java – Type Casting Read More »

Scroll to Top