- Hands-On Automation Testing with Java for Beginners
- Rahul Shetty
- 251字
- 2021-07-23 16:26:32
Difference between strings and variables
In Chapter 1, First Programming Steps in Java, we printed a string and the variable. If we look closely, when we print a variable we are not using double quotes, but when we print a string, we are using them. This is because the value is already present in the variable, hence we need not use any double quotes. If we use them, Java considers it to be a string and the output will be printed as the letter a in the following example. If we run this and observe the output, the letter a will be printed as shown in the following screenshot:
If we don't use double quotes, Java will check whether there is any variable defined with this letter. If so, it prints the value present in that variable. If there is no variable defined, then it gives an error. If we comment out the variable declaration, what we see is an error. Hovering the mouse over the variable, we will get a prompt saying Create a local variable 'a', or we can use it by adding double quotes:
In short, if we simply use double quotes, the variable will be treated as a string, but if we don't use double quotes, we must declare the variable somewhere. That is the difference between printing out strings and printing out variables.
- 嵌入式軟件系統(tǒng)測試:基于形式化方法的自動化測試解決方案
- Vue.js 3.x從入門到精通(視頻教學版)
- Machine Learning with R Cookbook(Second Edition)
- PostgreSQL 11從入門到精通(視頻教學版)
- 程序是怎樣跑起來的(第3版)
- 軟件測試綜合技術(shù)
- Arduino可穿戴設備開發(fā)
- FFmpeg開發(fā)實戰(zhàn):從零基礎到短視頻上線
- React and React Native
- PhantomJS Cookbook
- 面向?qū)ο蠓治雠c設計(第3版)
- Python程序員面試算法寶典
- Mastering React Test:Driven Development
- Learning Ext JS(Fourth Edition)
- Odoo Development Essentials