Posts

Showing posts from September, 2022

Day10 : Wrapper Class

Image
 Wrapper Class In java corresponding to 8 primitive datatype their is a set of 8 special classes. These classes have their names resembling with the names of the datatype and the database and collectively all 8 of them are called as wrapper classes. All these wrapper class are available in the package "java.lang" and following are their names. Integer Byte Short Long Float Double Character Boolean What is the use of wrapper class in java? Wrapper classes are use by programmer for two purposes : (1) We use them for converting string representation of the value to its original primitive form. For Example : To convert "25" to 25. We use the parseInt() belonging to wrapper class integer as shown below: int a; a = Integer.parseInt("25"); Likewise we've other parseXXX() method belonging to their respective wrapper classes. (2) Programmer also use wrapper class for converting a variable of primitive datatype into corresponding object. For Example :          

Day9 : Accepting Input

Image
 Accepting Input We can take input by the user by three method :  Using Command line Argument Using Scanner class Using GUI control 1) Using Command Line Argument When we are giving an argument at the time of execution after compiling a program in command prompt then we use command line argument . class Test { public static void main(String[] args) { System.out.println("Hello "+args[0]); System.out.println("Thank You"); } } How to Run: Open the notepad with Run as Administrator. Copy Paste the above code Save in bin file(if path is not specified) Open command prompt with Run as administrator. Enter the file location with cd command like as cd C:\Program Files\Java\jdk-17.0.4.1\bin then press Enter button Then write command javac File_name.java(Example javac Test.java) then press Enter button. Now our program is easily compiled. We're ready to run the above code with this command java Test any_String (Example java Test SCA_Notes) and then press the En

Day8: Using Math Class

Image
 Using Math Class In java we have very special predefined class called as Math available in package java.lang . As the name suggest the class math contains many mathematical constant(called constant as in java as final). and methods to help a programmer for performing mathematical calculation. One of its very popular member is PI. It is public, static, double, final data member declared in math class representing the value of PI up to 15 decimal places. //Write a program to print the value of PI class Circle { public static void main(String [] args) { System.out.println(Math.PI); } } Output : 3.141592653589793 //Write a program by using pow and sqrt function of Math class to find  (i) 21 to the power 2 and  (ii) square root of 36 class Demo {     public static void main(String [] args)          {               System.out.println("21 to the power 2 is "+Math.pow(21,2));               System.out.println("Square root of 36 is "+Math.sqrt(36));          } } Ou

Problem2 : Calculate Circle Area and Circumference

 Problem2 : Calculate Circle Area and Circumference Write a program to calculate and print Area and Circumference of a circle. Assume Radius to be an integer and initialized it with any value of your choice. public class Circle { public static void main ( String [] args ) { int radius = 35 ; double Area = Math . PI * Math . pow (radius, 2 ); System . out . println ( "Area of circle is " +Area); double Circumference = 2 * Math . PI * radius; System . out . println ( "Circumference of circle is " +Circumference); } } Output: Area of circle is 3848.4510006474966 Circumference of circle is 219.9114857512855

Day7: Type of Variable in Java

 Type of Variable in Java In Java we've three type of variable: Local Variable Instance Variable Static Variable 1)Local Variable These are those variable which are declared inside a method and they do not have any default value. so, it is an error to use an uninitialized local variable - class Demo { public static void main(String [ ] args) { int a = 30;                   //Local Variable System.out.println("The value of a is "+a); } } 2)Instance Variable These are those variable which are declare at the class level and they have default values alloted by java which are :               byte, short, int ----> 0               char ----> '\0'               float ----> 0.0f               double ----> 0.0               long ----> 0L               boolean ----> false               referance ---> null class Demo {         int a;            //Instance Variable 'a' public static void main(String [ ] args) { System

Day6 : Code on Assignment Operator

Image
 Code on Assignment Operator class Demo { public static void main(String [ ] args) { int a = 30, b = 10; System.out.println("The Sum of a and b is "+ (a+b)); System.out.println("The Subtraction of a and b is "+ (a-b)); System.out.println("The Multiplication of a and b is "+ (a*b)); System.out.println("The Division of a and b is "+ (a/b)); System.out.println("The Remainder of a and b is "+ (a%b)); } } Output: Shown in figure

Day5 : Operators in java

Image
 Operators Operator is  a symbol that is used to perform an operation. 1) Arithmetic Operator - Addition(+), Subtraction (-), Multiplication(*), Division(/), Modulus(%) 2) Relational Operator - Greater than(>), Less than(<), Greater equal to (>=), Less equal to(<=), equal to(==), not equal to(!=) 3)Logical Operator - AND(&&), OR(||), NOT(!) 4)Increment Operator(Post a++ and pre ++a) and Decrement operator(Post a-- and pre --a) 5)Shorthand Operator : +=, -=, *=, /=, %= 6)Assignment Operator: = 7)Parenthesis: () Question on Operator:   int a; a = 10/4; Output: 2 ................... int a; a = 10/4.0; Error: Possible Lossy Conversion ................ float a; a = 10/4; Output: 2.0 .................. float a; a = 10/4.0; Error: Possible lossy Conversion ........... 3%2 = 1(Output) 10%4 = 2(Output) Post Increment (a++): int a = 10; int b; b = a++; System.out.println(a); System.out.println(b); Pre-Increment(++a) int a = 10; int b; b = ++a; System.out.println(a); System.ou

Problem1: Display the value of variable

Image
Display the value of variable class Demo { public static void main(String [ ] args) { int a = 10; System.out.println("a is "+a); } } Output : 10 Note : Anything is coded with string is yet converted into string.

Day4 : Type Conversion and its type

Image
 Type Conversion Type conversion is a concept which is applied by java compiler whenever we use Assignment operator between variable of different datatypes. Types of Type conversion There are two types of type conversion : Implicit Conversion ((1) Compatible (2) Range of RHS < Range of LHS) (Done by Compiler) Explicit Conversion (In Java) But In C language called as Type Casting. (To be done by the programmer) Rules of Implicit Conversion: 1) Values must be compatible i.e.., there must be some way in java to convert RHS to LHS.     For Example: int x;                                  x = 'A'; The above code will Run because java will convert character constant 'A' to its UNICODE equivalent 65 because character is compatible with integer. But,               int x;               x = true; //The above code will not even compile because the java compiler has no way of converting boolean to int. so the error will incompatible type: can't convert boolean to int. 2) The

Day3 : Datatypes

Image
    Datatypes There are two types of Datatype in Java one is Primitive and Other is non-primitive datatype. The following flowchart shows a subcategory of Datatypes. Datatype Name + Size(In Byte) + Range: Byte - 1 Byte - Range: -128 to +127 Short - 2 Byte - Range: -32,768 to +32,767 Int - 4 Byte - Range: -2,147,433,648 to +2,147,433,647 Long - 8 Byte - Range : -9,223,372,036,854,775,308 to +9,223,372,036,854,775,308 Char - 2 Byte -  Range: 0 to 65535(UNICODE)  Boolean - 1Byte(8 bit) or 1 Bit - Actually It's size is dependent on JVM some JVM takes 8 Bit Or Some takes 1 Bit float - 4 Byte - Range: -3.4 * 10^38 to +3.4 * 10^38 double - 8 Byte - Range: -1.7*30^308 to +1.7*30^308

Day2 : Compiling Java Program with Examples

The First Java Program  class Test {          public static void main(String [] args)               {                    System.out.println("Hello User");               } } Always Write class which you want to make, the first letter in capital letter like Test. Here public is access modifier, static   is   used for memory management mainly ,   void is Return Type, main() is method, String [] args is command line argument, System is predefined method, out is object refinement, Println is predefined method. Compiling Java Program To compile a java program we can command Javac having with following Syntax: Javac Name of the program   For Example : Javac Test.java Whenever we compile a java program the compiler generates byte code files and these byte code files have 3 special properties: The Extension of the byte code file is always class. There main is always same as name of the class defined by programmer. Number of byte code files is always equal to the number of class d

Day1: Introduction to Java and its feature

Image
Introduction to Java Java is one of the most popular programming platform available in the market today and from the last 26 Years it is amongst the top 5 programming language of the world. Symbol of Java Programming Language Following are the most important feature which have made Java so popular in the software world. 1-Platform Independent  Before we can understand the meaning of the platform independent we must first understand the meaning of the world platform. In the software world, the world platform in the environment in which a program runs. In simple words it is the combination of operating System and CPU. So windows + core i7 is one platform while Linux + AMD(Advance Microdevices) Athlon is another platform. Now being platform Independent means that a program compiled on one platform can be executed on any other platform without rewriting OR recompiling and java has this ability with the help of byte code and JVM . Whenever we compile a Java program, the java compiler neve