Skip to main content

Posts

JAVA: Reading input from Keyboard

How does JAVA accepts input from keyboard? -streams accepts input from keyboard. -stream is a flow of data. Types of stream: input stream : Receives the data. output stream : Writes the data. Note:  System.out is used to print the output to the console. System.in is used to take input from the console. We can take input from the keyboard in two ways: using InputStreamReader class using Scanner class PROGRAM EXAMPLE: 1. Using InputStreamReader class import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class e_inputStream { public static void main(String args[]) throws IOException{ BufferedReader br=new BufferedReader(new InputStreamReader(System.in));               // BufferedReader is used to read the data from the input stream System.out.println("Enter the number:"); int i=Integer.parseInt(br.readLine()); //converting the text to int ...
Recent posts

JAVA: variables

What is a variable ? A variable  is like a container that holds a value. syntax: <data type> <variable name> = <value> eg: int i=10; where i is an integer that holds a value of 10. Scope of variable: Local Variable : its local which means its inside the method Instance Variable : its inside the class but outside the method. Class/Static Variable : its declared as static INSTANCE VARIABLE: declared inside the class but outside the method. visible to all methods. STATIC VARIABLE: declared with the static keyword in a class but outside the method. it is stored in static memory. LOCAL VARIABLE: declared inside the method. are accessible only during the method execution. Confused? let me show you an example with a program. public class scope{ int a=10; //<----instance variable static int c=20; //<----static variable public static void main(String args[]){ int x=30; //<----local var...

JAVA: First program

Lets create a simple program. JAVA PROGRAM: class myfirstprogram{   public static void main(String args[]){   System.out.println("Hello World");   } } OUTPUT: Hello World Explanation: class   keyword  Javaprogram  name of the class {  opening of the class    public   access key   static   used for calling without an object   void  doesn't return a value  main  name of the method   (String args[])   argument to the method {  opening of main    System  class in java.lang package .out  field .println  object ("Hello World");   }   closing of main } closing of class When we compile the program, the compiler compiles and creates a .class file. When we run the program, Java Virtual Machine(JVM) loads the .class file. Here, Java converts all the contents of source file to byte code thats the reason we get a .class file after the compilation of the program. PREVIOUS ...

JAVA: Basic

Java was developed in 1990 as OAK by James Gosling and his friends. Java was mainly famous for automatic memory allocation and garbage collection. Most of you might have heard alot about compiler and interpreter while studying JAVA. Well, compiler compiles the program i.e. it checks if there is any error in the program and interpreter interprets the error i.e. it checks for the error during run time like if the size of memory is less. BASIC STRUCTURE of JAVA PROGRAM: 1. Packages : libraries 2. Import : import the methods required 3. Class : create a class 4. Methods : create you own methods. JAVA TOKENS: 1. Identifier  : names associated with the packages, class , and methods. 2. Keyword : eg: try, catch, if, do, while, for etc. 3. Separator : eg: (), {}, [], ; etc. 4. Operator :  +, -, ++, --, /, % etc. 5. Literal : values 6. Comment : //,  /*..*/ DATA TYPES int 32bits float 32bits character 16bits boolean 8bits byte 8bits short 16bit...

Fantasy Dream Poem

How nice it would be, If we can dance over the rainbow, Sleep over the clouds, Shine with the stars, And bless others with the raindrops. I know it’s a fantasy dream, But nothing is impossible!

I Wish for a WISH

Wish I can wish for a chance A chance to win A chance to be better   A chance to be the best daughter But I don’t want to regret a thing Am happy the way I think The only thing that I wish Let me be me please. I don’t want to hurt anyone I don’t want to lie I just want to see everyone happy The only thing that I wish Let me be me please.                                                                                                          ...

First Love

When I first saw you, I felt my own heart beat, When I first talked to you, I felt the butterflies in me, When I first met  you , I felt like i found ma life, When I feel in love with  you , I saw my future with  you , But all those were mai thoughts, Cause  you  didn't love me at all, I thought  you  loved me, Until I saw  you  wid her, Doing whatever  you  did with me, All my feelings went away, It felt like a glass broke down, It still hurts, I hope tht  you  wud stay happy, I hope that  you would  live , All I want to see is you being happy.                                                       ...